Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,34 +202,10 @@ public bool ContainerOccluded
[ViewVariables(VVAccess.ReadWrite)] internal bool _inertUpdateQueued;

/// <summary>
/// Shader instance to use when drawing the final sprite to the world.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public ShaderInstance? PostShader
{
get;
// This will get obsoleted, but I only want to mark it as obsolete when multi-shader support is added, so
// that people can use the appropriate method and don't migrate to an incorrect new method that wont
// be obsoleted.
set;
}

/// <summary>
/// Whether to pass the screen texture to the <see cref="PostShader"/>.
/// </summary>
/// <remarks>
/// Should be false unless you really need it.
/// </remarks>
[DataField]
public bool GetScreenTexture;

/// <summary>
/// If true, this raise a entity system event before rendering this sprite, allowing systems to modify the
/// shader parameters. Usually this can just be done via a frame-update, but some shaders require
/// information about the viewport / eye.
/// Shaders to use when drawing the final sprite to the world.
/// </summary>
[DataField]
public bool RaiseShaderEvent;
public SortedDictionary<SpriteShaderKey, SpriteShaderData> PostShaders = new();

[ViewVariables] internal Dictionary<object, int> LayerMap { get; set; } = new();
[ViewVariables] internal List<Layer> Layers = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Robust.Client.Graphics;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Robust.Client.GameObjects;

[DataDefinition]
public sealed partial class SpriteShaderData(
ProtoId<ShaderPrototype> protoId,
bool raiseShaderEvent = false,
bool getScreenTexture = false,
bool mutable = true,
Color? color = null,
ShaderInstance? instance = null)
{
public SpriteShaderData() : this(default)
{
}

/// <summary>
/// Proto ID of the shader.
/// </summary>
[DataField]
public ProtoId<ShaderPrototype> ProtoId = protoId;

/// <summary>
/// If true, this raise a entity system event before rendering this sprite, allowing systems to modify the
/// shader parameters. Usually this can just be done via a frame-update, but some shaders require
/// information about the viewport / eye.
/// </summary>
[DataField]
public bool RaiseShaderEvent = raiseShaderEvent;

/// <summary>
/// Whether to pass the screen texture to the <see cref="Instance"/>.
/// </summary>
/// <remarks>
/// Should be false unless you really need it.
/// </remarks>
[DataField]
public bool GetScreenTexture = getScreenTexture;

/// <summary>
/// Is the shader mutable
/// </summary>
[DataField]
public bool Mutable = mutable;

/// <summary>
/// Color to apply when rendering shader
/// </summary>
[DataField]
public Color? Color = color;

public ShaderInstance? Instance = instance;

public SpriteShaderData Copy()
{
var shader = Instance is not { Disposed: true } ? Instance?.Mutable is true ? Instance.Duplicate() : Instance : null;
return new SpriteShaderData(ProtoId, RaiseShaderEvent, GetScreenTexture, Mutable, Color, shader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ in target

target.Comp.IsInert = source.Comp.IsInert;
target.Comp.LayerMap = source.Comp.LayerMap.ShallowClone();
target.Comp.PostShader = source.Comp.PostShader is {Mutable: true}
? source.Comp.PostShader.Duplicate()
: source.Comp.PostShader;

target.Comp.RenderOrder = source.Comp.RenderOrder;
target.Comp.GranularLayersRendering = source.Comp.GranularLayersRendering;
Expand Down
18 changes: 7 additions & 11 deletions Robust.Client/GameObjects/EntitySystems/SpriteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,14 @@ public Texture GetFrame(SpriteSpecifier spriteSpec, TimeSpan curTime, bool loop
}
}


/// <summary>
/// This event gets raised before a sprite gets drawn using it's post-shader.
/// </summary>
public sealed class BeforePostShaderRenderEvent : EntityEventArgs
{
public readonly SpriteComponent Sprite;
public readonly IClydeViewport Viewport;

public BeforePostShaderRenderEvent(SpriteComponent sprite, IClydeViewport viewport)
{
Sprite = sprite;
Viewport = viewport;
}
}
[ByRefEvent]
public readonly record struct BeforePostShaderRenderEvent(
ProtoId<ShaderPrototype> Shader,
ShaderInstance Instance,
SpriteComponent Sprite,
IClydeViewport Viewport);
}
4 changes: 3 additions & 1 deletion Robust.Client/Graphics/Clyde/Clyde.Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ private static readonly (string, uint)[] BaseShaderAttribLocations =
private const int UniITexturePixelSize = 2;
private const int UniIMainTexture = 3;
private const int UniILightTexture = 4;
private const int UniCount = 5;
private const int UniIFragCoordOffset = 5;
private const int UniCount = 6;

private const string UniModUV = "modifyUV";
private const string UniModelMatrix = "modelMatrix";
private const string UniTexturePixelSize = "TEXTURE_PIXEL_SIZE";
private const string UniMainTexture = "TEXTURE";
private const string UniLightTexture = "lightMap"; // TODO CLYDE consistent shader variable naming
private const string UniFragCoordOffset = "FragCoordOffset";
private const string UniProjViewMatrices = "projectionViewMatrices";
private const string UniUniformConstants = "uniformConstants";

Expand Down
1 change: 1 addition & 0 deletions Robust.Client/Graphics/Clyde/Clyde.GridRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void _drawGrids(Viewport viewport, Box2 worldAABB, Box2Rotated worldBoun
gridProgram.SetUniformTextureMaybe(UniIMainTexture, TextureUnit.Texture0);
gridProgram.SetUniformTextureMaybe(UniILightTexture, TextureUnit.Texture1);
gridProgram.SetUniform(UniIModUV, new Vector4(0, 0, 1, 1));
gridProgram.SetUniformMaybe(UniIFragCoordOffset, new Vector2(0, 0));
}

gridProgram.SetUniform(UniIModelMatrix, _transformSystem.GetWorldMatrix(mapGrid));
Expand Down
Loading
Loading