diff options
Diffstat (limited to 'assets/shaders/grid.slang')
| -rw-r--r-- | assets/shaders/grid.slang | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/assets/shaders/grid.slang b/assets/shaders/grid.slang index ea7d263..d90799e 100644 --- a/assets/shaders/grid.slang +++ b/assets/shaders/grid.slang @@ -1,6 +1,13 @@ -uniform float4x4 u_ViewProjection; -uniform float4x4 u_Transform; -uniform float u_GridSize; +struct GridU +{ + float4x4 u_ViewProjection; + float4x4 u_Transform; + float u_GridSize; + float3 u_GridColor; + float u_GridAlpha; + float3 u_CameraPos; +}; +ConstantBuffer<GridU> gu; struct VSInput { float3 position : POSITION; }; struct VSOutput { float4 position : SV_Position; }; @@ -9,23 +16,19 @@ struct VSOutput { float4 position : SV_Position; }; VSOutput vertexMain(VSInput input) { VSOutput output; - float3 scaledPosition = input.position * (u_GridSize / 50.0); - output.position = mul(u_ViewProjection, mul(u_Transform, float4(scaledPosition, 1.0))); + float3 scaledPosition = input.position * (gu.u_GridSize / 50.0); + output.position = mul(gu.u_ViewProjection, mul(gu.u_Transform, float4(scaledPosition, 1.0))); return output; } -uniform float3 u_GridColor; -uniform float u_GridAlpha; -uniform float3 u_CameraPos; - [shader("fragment")] float4 fragmentMain(VSOutput input) : SV_Target { - float dist = length(u_CameraPos); + float dist = length(gu.u_CameraPos); float fadeFactor = 1.0 - clamp(dist / 100.0, 0.0, 0.8); - float3 color = u_GridColor; - float alpha = u_GridAlpha * fadeFactor; + float3 color = gu.u_GridColor; + float alpha = gu.u_GridAlpha * fadeFactor; float gridFade = 1.0 - clamp(dist / 50.0, 0.0, 0.9); alpha *= gridFade; |
