Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify normal map sample, fix toy box normals. #320

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

ben-clayton
Copy link
Collaborator

@ben-clayton ben-clayton commented Nov 7, 2023

Mirror the toy-box texture to fix the normals.

Simplify the box.ts code.
This was more complicated than it needed to be, and borrowed code from another project.
This code also used vec3 methods with two-element vectors, which might cause issues with future versions of wgpu-matrix

Simplfiy normalMap.wgsl

  • Use const declarations to name the various modes instead of magic literals.
  • Calculate the worldViewProj and worldView matrices on the CPU and pass them in as part of the uniform buffer. Reduces duplicated work in the vertex shader, and reduces the amount of data needed to be passed in.
  • Use vec3f for the light position instead of scalar. Pass in the position in view-space.
  • Reduce the amount of data passed from vertex to fragment.
  • Rename tbn to tangent, bitangent and normal.
  • Remove unused function when_greater
  • Split parallax_uv into two functions.
  • Simplify steep-parallax loop. Pre-calculate the UV derivatives so we can break early from the loop.

Rename diffuse textures to albedo. Technically a diffuse texture already has diffuse lighting applied.

Fixed: #317

Mirror the toy-box texture to fix the normals.

Simplify the `box.ts` code.
This was more complicated than it needed to be, and borrowed code from another project.
This code also used vec3 methods with two-element vectors, which might cause issues with future versions of 'wgpu-matrix'

Simplfiy `normalMap.wgsl`
* Use `const` declarations to name the various modes instead of magic literals.
* Calculate the `worldViewProj` and `worldView` matrices on the CPU and pass them in as part of the uniform buffer. Reduces duplicated work in the vertex shader, and reduces the amount of data needed to be passed in.
* Use `vec3f` for the light position instead of scalar. Pass in the position in view-space.
* Reduce the amount of data passed from vertex to fragment.
* Rename `tbn` to `tangent`, `bitangent` and `normal`.
* Remove unused function `when_greater`
* Split `parallax_uv` into two functions.
* Simplify steep-parallax loop. Pre-calculate the UV derivatives so we can break early from the loop.

Rename 'diffuse' textures to 'albedo'. Technically a diffuse texture already has diffuse lighting applied.

Fixed: webgpu#317
@ben-clayton
Copy link
Collaborator Author

FYI: @cmhhelgeson

@cmhhelgeson
Copy link
Contributor

Hi Ben,

I took a look at the code and everything looks good in terms of clarity and simplicity. Sorry I couldn't be of more help, I've been sick for longer than expected.

@ben-clayton
Copy link
Collaborator Author

Hi Ben,

I took a look at the code and everything looks good in terms of clarity and simplicity. Sorry I couldn't be of more help, I've been sick for longer than expected.

No need to apologise! Thank you for being open to the changes.
I ended up looking through this code because identifying these kinds of bugs are always horribly tricky. My ex-gamedev eyes knew something was off, but it was certainly hard to pin down.
Thank you for submitting the sample. It's great.

@ben-clayton ben-clayton merged commit d67ae2a into webgpu:main Nov 7, 2023
1 check passed
@ben-clayton ben-clayton deleted the fix-normal-map branch November 7, 2023 17:06
@ben-clayton
Copy link
Collaborator Author

Also: Get well soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Normal mapping sample doesn't look quite right
3 participants