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

GenerateMips on sRGB Textures averaging in gamma space? #142

Open
StephenMLucas opened this issue Dec 2, 2022 · 3 comments
Open

GenerateMips on sRGB Textures averaging in gamma space? #142

StephenMLucas opened this issue Dec 2, 2022 · 3 comments
Assignees
Labels

Comments

@StephenMLucas
Copy link

Hi,

Reviewing the implementation of GenerateMips for sRGB textures it looks like the implementation is doing a reinterpret copy into a linear texture format and then using a bilinear sampler in the ComputeShader to perform the average.

Unless I'm missing something about the math for this case it seems like doing the linear arithmetic on gamma encoded values in the sampler is going to result in color errors in the output mips, as demonstrated by this GLTF test case; https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/TextureLinearInterpolationTest

@StephenMLucas StephenMLucas changed the title GenerateMips on sRGB Textures interpolating in gamma space? GenerateMips on sRGB Textures averaging in gamma space? Dec 2, 2022
@walbourn walbourn added the bug label Dec 2, 2022
@walbourn
Copy link
Member

walbourn commented Dec 2, 2022

Right. I should add a inverse gamma/regamma in this case to the sahder...

@walbourn walbourn self-assigned this Dec 2, 2022
@StephenMLucas
Copy link
Author

Presumably the other option would be to use a regular pixel shader pipeline, like the post processing functions, where the sRGB formats are directly supported as both SRVs and RenderTargets to move the conversion before the filtering in the sampler?

I don't know whether having the compute shader version do 4 point samples, gamma converting, taking the average and regammaing would result in any overall performance difference compared with using the built-in pixel shader functions though.

@walbourn walbourn pinned this issue Dec 11, 2022
@walbourn
Copy link
Member

GenerateMips has always been a bug-farm, and on Direct3D 11 the implementation was very driver-dependent. It does seem like the only "correct" way to solve this is to do as you say and create yet another generatemips codepath using classic texture down-sizing on the GPU.

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

No branches or pull requests

2 participants