From 0ee2712029f53175552d459f908b163ad61de197 Mon Sep 17 00:00:00 2001 From: hachem Date: Sun, 23 Aug 2026 16:19:19 +0200 Subject: feat: RHI interface with shared scene and black hole renderers --- assets/shaders/sphere.slang | 48 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'assets/shaders/sphere.slang') diff --git a/assets/shaders/sphere.slang b/assets/shaders/sphere.slang index 0871438..256372d 100644 --- a/assets/shaders/sphere.slang +++ b/assets/shaders/sphere.slang @@ -1,5 +1,17 @@ -uniform float4x4 u_ViewProjection; -uniform float4x4 u_Transform; +struct SphereU +{ + float4x4 u_ViewProjection; + float4x4 u_Transform; + float3 u_Color; + float u_Specular; + float u_Emission; + float3 u_LightPos; + float3 u_CameraPos; + int u_IsSelected; + float3 u_OutlineColor; + float u_OutlineWidth; +}; +ConstantBuffer su; struct VSInput { @@ -18,29 +30,21 @@ struct VSOutput VSOutput vertexMain(VSInput input) { VSOutput output; - output.worldPos = mul(u_Transform, float4(input.position, 1.0)).xyz; - float3x3 normalMatrix = (float3x3)u_Transform; + output.worldPos = mul(su.u_Transform, float4(input.position, 1.0)).xyz; + float3x3 normalMatrix = (float3x3)su.u_Transform; output.normal = mul(normalMatrix, input.normal); - output.position = mul(u_ViewProjection, float4(output.worldPos, 1.0)); + output.position = mul(su.u_ViewProjection, float4(output.worldPos, 1.0)); return output; } -uniform float3 u_Color; -uniform float u_Specular; -uniform float u_Emission; -uniform float3 u_LightPos; -uniform float3 u_CameraPos; -uniform int u_IsSelected; -uniform float3 u_OutlineColor; -uniform float u_OutlineWidth; -SamplerCube u_HDRIEnvironment; +SamplerCube u_HDRIEnvironment; [shader("fragment")] float4 fragmentMain(VSOutput input) : SV_Target { float3 normal = normalize(input.normal); - float3 lightDir = normalize(u_LightPos - input.worldPos); - float3 viewDir = normalize(u_CameraPos - input.worldPos); + float3 lightDir = normalize(su.u_LightPos - input.worldPos); + float3 viewDir = normalize(su.u_CameraPos - input.worldPos); float3 reflectDir = reflect(-lightDir, normal); float3 hdriLight = u_HDRIEnvironment.Sample(normal).rgb; @@ -49,18 +53,18 @@ float4 fragmentMain(VSOutput input) : SV_Target float diff = max(dot(normal, lightDir), 0.0); float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32.0); - float3 diffuse = u_Color * (diff + hdriIntensity * hdriLight); - float3 specular = float3(u_Specular, u_Specular, u_Specular) * spec; - float3 emission = u_Color * u_Emission; + float3 diffuse = su.u_Color * (diff + hdriIntensity * hdriLight); + float3 specular = float3(su.u_Specular, su.u_Specular, su.u_Specular) * spec; + float3 emission = su.u_Color * su.u_Emission; float3 result = diffuse + specular + emission; - if (u_IsSelected > 0) + if (su.u_IsSelected > 0) { float ndotv = max(dot(normal, viewDir), 0.0); float rim = 1.0 - ndotv; - float outlineMask = step(1.0 - u_OutlineWidth, rim); - result = lerp(result, u_OutlineColor, outlineMask); + float outlineMask = step(1.0 - su.u_OutlineWidth, rim); + result = lerp(result, su.u_OutlineColor, outlineMask); } return float4(result, 1.0); -- cgit v1.3