-
Notifications
You must be signed in to change notification settings - Fork 108
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
added gamma correction effect #108
Conversation
@chasedavis i didn't know this effect existed, i remember i asked @vanruesc once and he said pp takes care of gammacorrection automatically but in practice pp is always brighter or causes slight banding. do you know when GammaCorrection should be used? because we know when the canvas is set to autocorrect, so perhaps we can just add it automatically when that's the case? |
The import { HalfFloatType } from "three";
const composer = new EffectComposer(renderer, {
frameBufferType: HalfFloatType
}); I've read somewhere that Unity works around the banding issue by converting colors to sRGB when writing to frame buffers and decoding back to linear when reading from them. It's more work overall but it doesn't require half float buffers. Three currently doesn't support this in hardware because render targets don't support SRGB8 yet. There's also an issue with transparency and blending which I'm currently trying to wrap my head around: mrdoob/three.js#23019 |
You can see in the example that the output encoding is 3001 (SRGBEncoding). Unfortunately the HalfFloatType doesn't fix the lightness that the effect composer is causing. In this particular example, there weren't issues of banding but the rendered image looked too white. Are there other instances of this issue and workarounds you are aware of @vanruesc ? |
In that case, color encoding should be working correctly. I noticed that you set the I modified the hat shader to output So the reason why the hat looks too bright or washed out lies somewhere in your custom shader code. If you want to change the brightness or contrast of the entire scene, consider using the You can find three's color encoding functions over here if you need those for color maps. Custom shaders should also make use of <encodings_fragment> so that they correctly encode their output when rendering to screen (without an effect composer). |
Thanks for diving in here @vanruesc ! It makes sense that you can adjust the shader to achieve a more true color. From the example you shared, it seems that if you delete the effect composer entirely then the backgroundColor (not dictated by the shader?) also changes its perceived brightness.. This is unexpected behavior to me, but I don't doubt that it's caused by the use of the custom shader. I'm not encountering this issue when using normal three/r3f primitives. In the future, I like the idea of including postprocessing curves directly into custom shaders as necessary, rather than fiddle with the GammaCorrection pass. From a dx perspective, up to you @drcmda on if you keep the GammaCorrection component -- it is much easier for novices like me than hopping into shader code, especially if you're not author of the shader as is the case here. With that said, you can also achieve similar with existing Brightness/Contrast and Hue/Saturation effects as mentioned. |
Three doesn't apply gamma correction to the scene background because it actually uses |
@vanruesc, what do you think about this solution? mrdoob/three.js#23019 (comment) |
@iuriiiurevich I appreciate your input and the time you spent on moving the conversation forward! Unfortunately, I've been too busy to deep dive into the matter and can't really comment on your solution yet. I'm actually still not sure which result really is the correct one. Three applies the linear-to-sRGB encoding manually inside the shaders when rendering to the canvas (with |
Per this discussion, adding gamma correction effect as export to react-pp.
I'm still wondering if this is the best solution to the problem encountered, as it seems like some output encoding issue involving render targets, but exporting here does provide a knob for an issue I and @richczhou encountered where color/tonemapping is off in certain custom shader scenes (example).
this is my first contribution so I'm not sure if any other files need adjustments (e.g. postprocessing.d.ts ?)