diff options
Diffstat (limited to 'assets/shaders/sphere.slang')
| -rw-r--r-- | assets/shaders/sphere.slang | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/assets/shaders/sphere.slang b/assets/shaders/sphere.slang index e37700d..41badde 100644 --- a/assets/shaders/sphere.slang +++ b/assets/shaders/sphere.slang @@ -1,42 +1,32 @@ // Lit sphere (Blinn-Phong + HDRI ambient + selection rim). Uniforms in a // ConstantBuffer (UBO, binding 0) so both backends drive it through the RHI; // the environment cubemap is a separate sampler at binding 1. -struct SphereU +struct Sphere { - 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; + float4x4 u_view_projection; + float4x4 u_transform; + float3 u_color; + float u_specular; + float u_emission; + float3 u_light_pos; + float3 u_camera_pos; + int u_is_selected; + float3 u_outline_color; + float u_outline_width; }; -ConstantBuffer<SphereU> su; +ConstantBuffer<Sphere> su; -struct VSInput -{ - float3 position : POSITION; - float3 normal : NORMAL; -}; - -struct VSOutput -{ - float4 position : SV_Position; - float3 normal : TEXCOORD0; - float3 worldPos : TEXCOORD1; -}; +struct VSInput { float3 position : POSITION; float3 normal : NORMAL; }; +struct VSOutput { float4 position : SV_Position; float3 normal : TEXCOORD0; float3 worldPos : TEXCOORD1; }; [shader("vertex")] VSOutput vertexMain(VSInput input) { VSOutput output; - output.worldPos = mul(su.u_Transform, float4(input.position, 1.0)).xyz; - float3x3 normalMatrix = (float3x3)su.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(su.u_ViewProjection, float4(output.worldPos, 1.0)); + output.position = mul(su.u_view_projection, float4(output.worldPos, 1.0)); return output; } @@ -46,8 +36,8 @@ SamplerCube u_HDRIEnvironment; float4 fragmentMain(VSOutput input) : SV_Target { float3 normal = normalize(input.normal); - float3 lightDir = normalize(su.u_LightPos - input.worldPos); - float3 viewDir = normalize(su.u_CameraPos - input.worldPos); + float3 lightDir = normalize(su.u_light_pos - input.worldPos); + float3 viewDir = normalize(su.u_camera_pos - input.worldPos); float3 reflectDir = reflect(-lightDir, normal); float3 hdriLight = u_HDRIEnvironment.Sample(normal).rgb; @@ -56,18 +46,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 = 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 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 (su.u_IsSelected > 0) + if (su.u_is_selected > 0) { float ndotv = max(dot(normal, viewDir), 0.0); float rim = 1.0 - ndotv; - float outlineMask = step(1.0 - su.u_OutlineWidth, rim); - result = lerp(result, su.u_OutlineColor, outlineMask); + float outlineMask = step(1.0 - su.u_outline_width, rim); + result = lerp(result, su.u_outline_color, outlineMask); } return float4(result, 1.0); |
