forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Displacement maps big update (space-wizards#30093)
* split logic into own system * add support for different size displacement maps * some clothes may not use displacement maps * displacement maps spport hand sprites * Update DisplacementMapSystem.cs * rename things * fuck stencilmask * fix bugs * no masks * Update jumpsuits.yml * fix species specific sprites * Update ClothingSystem.cs * shoes + ears displacement, some bugfix * Update DisplacementMapSystem.cs
- Loading branch information
Showing
26 changed files
with
352 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Content.Shared.DisplacementMap; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Shared.Serialization.Manager; | ||
|
||
namespace Content.Client.DisplacementMap; | ||
|
||
public sealed class DisplacementMapSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ISerializationManager _serialization = default!; | ||
|
||
public bool TryAddDisplacement(DisplacementData data, SpriteComponent sprite, int index, string key, HashSet<string> revealedLayers) | ||
{ | ||
if (data.ShaderOverride != null) | ||
sprite.LayerSetShader(index, data.ShaderOverride); | ||
|
||
var displacementKey = $"{key}-displacement"; | ||
if (!revealedLayers.Add(displacementKey)) | ||
{ | ||
Log.Warning($"Duplicate key for DISPLACEMENT: {displacementKey}."); | ||
return false; | ||
} | ||
|
||
//allows you not to write it every time in the YML | ||
foreach (var pair in data.SizeMaps) | ||
{ | ||
pair.Value.CopyToShaderParameters??= new() | ||
{ | ||
LayerKey = "dummy", | ||
ParameterTexture = "displacementMap", | ||
ParameterUV = "displacementUV", | ||
}; | ||
} | ||
|
||
if (!data.SizeMaps.ContainsKey(32)) | ||
{ | ||
Log.Error($"DISPLACEMENT: {displacementKey} don't have 32x32 default displacement map"); | ||
return false; | ||
} | ||
|
||
// We choose a displacement map from the possible ones, matching the size with the original layer size. | ||
// If there is no such a map, we use a standard 32 by 32 one | ||
var displacementDataLayer = data.SizeMaps[EyeManager.PixelsPerMeter]; | ||
var actualRSI = sprite.LayerGetActualRSI(index); | ||
if (actualRSI is not null) | ||
{ | ||
if (actualRSI.Size.X != actualRSI.Size.Y) | ||
Log.Warning($"DISPLACEMENT: {displacementKey} has a resolution that is not 1:1, things can look crooked"); | ||
|
||
var layerSize = actualRSI.Size.X; | ||
if (data.SizeMaps.ContainsKey(layerSize)) | ||
displacementDataLayer = data.SizeMaps[layerSize]; | ||
} | ||
|
||
var displacementLayer = _serialization.CreateCopy(displacementDataLayer, notNullableOverride: true); | ||
displacementLayer.CopyToShaderParameters!.LayerKey = key; | ||
|
||
sprite.AddLayer(displacementLayer, index); | ||
sprite.LayerMapSet(displacementKey, index); | ||
|
||
revealedLayers.Add(displacementKey); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Content.Shared.DisplacementMap; | ||
|
||
[DataDefinition] | ||
public sealed partial class DisplacementData | ||
{ | ||
/// <summary> | ||
/// allows you to attach different maps for layers of different sizes. | ||
/// </summary> | ||
[DataField(required: true)] | ||
public Dictionary<int, PrototypeLayerData> SizeMaps = new(); | ||
|
||
[DataField] | ||
public string? ShaderOverride = "DisplacedStencilDraw"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.