struct Uniforms { viewProjectionMatrix : mat4x4f } @group(0) @binding(0) var uniforms : Uniforms; @group(1) @binding(0) var modelMatrix : mat4x4f; struct VertexInput { @location(0) position : vec4f, @location(1) normal : vec3f, @location(2) uv : vec2f } struct VertexOutput { @builtin(position) position : vec4f, @location(0) normal: vec3f, @location(1) uv : vec2f, } @vertex fn vertexMain(input: VertexInput) -> VertexOutput { var output : VertexOutput; output.position = uniforms.viewProjectionMatrix * modelMatrix * input.position; output.normal = normalize((modelMatrix * vec4(input.normal, 0)).xyz); output.uv = input.uv; return output; } @group(1) @binding(1) var meshSampler: sampler; @group(1) @binding(2) var meshTexture: texture_2d; // Static directional lighting const lightDir = vec3f(1, 1, 1); const dirColor = vec3(1); const ambientColor = vec3f(0.05); @fragment fn fragmentMain(input: VertexOutput) -> @location(0) vec4f { let textureColor = textureSample(meshTexture, meshSampler, input.uv); // Very simplified lighting algorithm. let lightColor = saturate(ambientColor + max(dot(input.normal, lightDir), 0.0) * dirColor); return vec4f(textureColor.rgb * lightColor, textureColor.a); }