aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/grid.slang
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-23 17:21:37 +0200
committerhachem <im@hachem.wtf>2026-08-23 17:21:37 +0200
commit3fd33ecff7472e4d6fc9e6b3905f56982e497ef2 (patch)
tree66e5812f1a18b926e88a0dd549fe14e7c7327165 /assets/shaders/grid.slang
parente3aa33fc9a99d8b817bda42a567a4c347e18ab32 (diff)
[feat]: complete RHI api
Diffstat (limited to 'assets/shaders/grid.slang')
-rw-r--r--assets/shaders/grid.slang39
1 files changed, 39 insertions, 0 deletions
diff --git a/assets/shaders/grid.slang b/assets/shaders/grid.slang
new file mode 100644
index 0000000..f549cb1
--- /dev/null
+++ b/assets/shaders/grid.slang
@@ -0,0 +1,39 @@
+// Reference grid on the XZ plane. Uniforms live in a ConstantBuffer (UBO) so both
+// backends drive it through the same RHI path (bind a uniform buffer at binding 0).
+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; };
+
+[shader("vertex")]
+VSOutput vertexMain(VSInput input)
+{
+ VSOutput output;
+ 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;
+}
+
+[shader("fragment")]
+float4 fragmentMain(VSOutput input) : SV_Target
+{
+ float dist = length(gu.u_CameraPos);
+ float fadeFactor = 1.0 - clamp(dist / 100.0, 0.0, 0.8);
+
+ 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;
+
+ return float4(color, alpha);
+}