Merge pull request #205 from hwoodiwiss/fix-tutorial-10

fix: Tutorial 10 Docs Specular Lighting Shader Problems
pull/211/head
sotrh 3 years ago committed by GitHub
commit 0dce068dcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -517,7 +517,7 @@ Remember the normal vectors that were included with our model? We're finally goi
If the dot product of the normal and light vector is 1.0, that means that the current fragment is directly inline with the light source and will receive the lights full intensity. A value of 0.0 or lower means that the surface is perpendicular or facing away from the light, and therefore will be dark.
We're going to need to pull in the normal vector into our `shader.vert`.
We're going to need to pull in the normal vector into our `shader.wgsl`.
```wgsl
struct VertexInput {
@ -847,8 +847,8 @@ let reflect_dir = reflect(-light_dir, in.world_normal);
Then we use the dot product to calculate the `specular_strength` and use that to compute the `specular_color`.
```wgsl
let specular_strength = pow(max(dot(view_dir, reflect_dir), 0.0), 32);
let specular_color = specular_strength * light_color;
let specular_strength = pow(max(dot(view_dir, reflect_dir), 0.0), 32.0);
let specular_color = specular_strength * light.color;
```
Finally we add that to the result.
@ -873,7 +873,7 @@ Up to this point we've actually only implemented the Phong part of Blinn-Phong.
let view_dir = normalize(uniforms.view_pos.xyz - in.world_position);
let half_dir = normalize(view_dir + light_dir);
let specular_strength = pow(max(dot(in.world_normal, half_dir), 0.0), 32);
let specular_strength = pow(max(dot(in.world_normal, half_dir), 0.0), 32.0);
```
It's hard to tell the difference, but here's the results.

Loading…
Cancel
Save