@@ -3,15 +3,14 @@ const uniforms = `
33struct CameraUniforms {
44 uViewMatrix: mat4x4<f32>,
55 uProjectionMatrix: mat4x4<f32>,
6- uCameraRotation : mat3x3<f32>,
6+ uCameraNormalMatrix : mat3x3<f32>,
77}
88
99// Group 2: Model Transform
1010struct ModelUniforms {
1111// @p5 ifdef Vertex getWorldInputs
1212 uModelMatrix: mat4x4<f32>,
1313 uModelNormalMatrix: mat3x3<f32>,
14- uCameraNormalMatrix: mat3x3<f32>,
1514// @p5 endif
1615// @p5 ifndef Vertex getWorldInputs
1716 uModelViewMatrix: mat4x4<f32>,
@@ -115,7 +114,7 @@ fn main(input: VertexInput) -> VertexOutput {
115114// @p5 ifdef Vertex getWorldInputs
116115 // Already multiplied by the model matrix, just apply view
117116 inputs.position = (camera.uViewMatrix * vec4<f32>(inputs.position, 1.0)).xyz;
118- inputs.normal = model .uCameraNormalMatrix * inputs.normal;
117+ inputs.normal = camera .uCameraNormalMatrix * inputs.normal;
119118// @p5 endif
120119// @p5 ifndef Vertex getWorldInputs
121120 // Apply both at once
@@ -222,7 +221,7 @@ fn mapTextureToNormal(v: vec3<f32>) -> vec2<f32> {
222221fn calculateImageDiffuse(vNormal: vec3<f32>, vViewPosition: vec3<f32>, metallic: f32) -> vec3<f32> {
223222 // make 2 seperate builds
224223 let worldCameraPosition = vec3<f32>(0.0, 0.0, 0.0); // hardcoded world camera position
225- let worldNormal = normalize(vNormal * camera.uCameraRotation );
224+ let worldNormal = normalize(vNormal * camera.uCameraNormalMatrix );
226225 let newTexCoord = mapTextureToNormal(worldNormal);
227226 let texture = textureSample(environmentMapDiffused, environmentMapDiffused_sampler, newTexCoord);
228227 // this is to make the darker sections more dark
@@ -234,7 +233,7 @@ fn calculateImageSpecular(vNormal: vec3<f32>, vViewPosition: vec3<f32>, shinines
234233 let worldCameraPosition = vec3<f32>(0.0, 0.0, 0.0);
235234 let worldNormal = normalize(vNormal);
236235 let lightDirection = normalize(vViewPosition - worldCameraPosition);
237- let R = reflect(lightDirection, worldNormal) * camera.uCameraRotation ;
236+ let R = reflect(lightDirection, worldNormal) * camera.uCameraNormalMatrix ;
238237 let newTexCoord = mapTextureToNormal(R);
239238
240239 // In p5js the range of shininess is >= 1,
0 commit comments