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

Switch from normal maps to derivative maps #1125

Closed
willeastcott opened this issue Mar 10, 2018 · 0 comments
Closed

Switch from normal maps to derivative maps #1125

willeastcott opened this issue Mar 10, 2018 · 0 comments
Assignees

Comments

@willeastcott
Copy link
Contributor

willeastcott commented Mar 10, 2018

See here:

http://www.rorydriscoll.com/2012/01/15/derivative-maps-vs-normal-maps/
http://www.thetenthplanet.de/archives/1180

Benefits of switching:

  • Faster load times. pc.calculateTangents is very slow. Often well over half of model loading time is actually spent in this function. Furthermore, pc.calculateTangents is always executed if positions, normals and uvs are present, but no tangets. Even if tangents are never actually required by the materials applied to the model. We simply don't know at load time whether tangents might be needed at a future point (if a material is switched dynamically, say).
  • Engine will use less memory. Tangents take up RAM (4-floats per vertex).
  • Less instances of hitting 8 attribute limit. This essentially almost never happens anyway. But tangents use up an attribute so it'd be easier to write shaders that don't hit an 8 attribute limit (which is the minimum for the WebGL spec).
  • Performance. Tangents must be interpolated when passed to the fragment shader and this cost would vanish.

Derivative normal mapping is not without problems too though:

  • Performance. Extra instructions are introduced into the fragment shader to calculate the TBN matrix. Performance needs to be tested on mobile! This would probably outweigh savings from not interpolating precomputed tangents. I suspect that with modern mobile hardware, this performance difference is likely to be small.
  • Cross-platform compatibility. This technique depends upon OES_standard_derivatives. Although this is not guaranteed to be available, 99% of devices support it. For the 1% that don't, in the case precomputed tangents are not available, merely disable normal mapping.

Something to assess:

  • Visual quality. Visual quality may differ. However, I have seen no evidence that it will look perceptibly worse.

NOTE: We should definitely still respect tangents if they are explicitly inserted into a vertex buffer. But we should simply stop generating them if they are not made available.

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

No branches or pull requests

2 participants