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

Use gamma textures format (WebGl2) #3715

Open
mvaligursky opened this issue Nov 18, 2021 · 2 comments
Open

Use gamma textures format (WebGl2) #3715

mvaligursky opened this issue Nov 18, 2021 · 2 comments
Assignees
Labels
area: graphics Graphics related issue feature request performance Relating to load times or frame rate V2 Work for initial release of V2 engine
Milestone

Comments

@mvaligursky
Copy link
Contributor

Currently, when the engine samples a texture stored in gamma space, it uses gammaCorrectInput function to bring the values to linear space for lighting, costing us a pow instruction per sample, and also bilinear interpolation when sampling takes place in sRGB space, which is slightly incorrect.

On Webgl2 devices, and also on Webgl1 devices with EXT_sRGB (https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB), we could use hardware support for sRGB textures.

See here: (http://www.realtimerendering.com/blog/webgl-2-new-features/)
The sRGB texture will be automatically converted to linear space when being fetched in the shader.

The disadvantage here is that the texture needs to be marked as sRGB when we create a WebGl texture, meaning likely that we would need to expose a texture import setting in the Editor to allow textures to be marked as sRGB (diffuse and similar texture need sRGB, normal map, roughness and others don't as they are in linear space).

@mvaligursky mvaligursky added enhancement performance Relating to load times or frame rate area: graphics Graphics related issue labels Nov 18, 2021
@slimbuck
Copy link
Member

Our gamma space textures also currently have their mipmaps generated in gamma space, which is wrong. Marking texture sRGB will result in linear-space generated mipmaps.

We also need to address compressed textures in the editor. Textures are assumed gamma space (and converted to linear for mipmaps) - so linear-space textures currently have the inverse mipmap problem. (Though I believe normal maps are correctly handled).

@mvaligursky
Copy link
Contributor Author

Note that ideally we'd use sRGB framebuffers as well, which automatically encode linear -> sRGB on write.
https://hackmd.io/@jgilbert/sRGB-WebGL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue feature request performance Relating to load times or frame rate V2 Work for initial release of V2 engine
Projects
Development

No branches or pull requests

5 participants