Skip to content

Documentation / @ripl/webgpu / FRAGMENT_SHADER

Variable: FRAGMENT_SHADER

const FRAGMENT_SHADER: "\nstruct Uniforms {\n viewProjectionMatrix: mat4x4f,\n lightDirection: vec3f,\n ambient: f32,\n};\n\n@group(0) @binding(0) var<uniform> uniforms: Uniforms;\n\n@fragment\nfn main(\n @location(0) worldNormal: vec3f,\n @location(1) color: vec4f,\n) -> @location(0) vec4f {\n let normal = normalize(worldNormal);\n let light = normalize(-uniforms.lightDirection);\n let diffuse = max(dot(normal, light), 0.0);\n let brightness = uniforms.ambient + (1.0 - uniforms.ambient) * diffuse;\n\n return vec4f(color.rgb * brightness, color.a);\n}\n"

Defined in: webgpu/src/shaders.ts:43

WGSL fragment shader with Lambertian diffuse lighting.