-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
DataUtils: Clamp param of toHalfFloat(). #22444
Conversation
Hmm..., I'm not sure that is where the test should be. That is where a warning should be. The app should not try to convert a number to half-float that exceeds the maximum-supported value. As implemented, this will cause an RGB hue shift, since each channel is processed separately. |
Before, the method was producing the wrong answer for large values. Now it is still producing the wrong answer: converting back to float will not yield the original value. I think a waring is more appropriate -- and each app should handle large values in a manner appropriate for that app. |
I think that we should auto clamp when using RGBELoader with data type half. RGBE is natively a Float32 format and converting to Half is going to always be possibly problematic - just sometimes RGBE images may not be full dynamic range. Thus I do not think we have to warn here, it is a known problem with RGBE to Half. Maybe a flag on the toHalfFloat that includes a clamp option is best? So you can enable or not enable it depending on use case? So you do not always do it by default. |
We could introduce a second parameter if ( clamp === true ) val = Math.min( val, 65504 ); |
Of course, RGBELoader must be fixed. It could clamp each channel separately or clamp and retain hue.
I disagree. Just clamp without a flag. If you want to clamp silently without warning, that is OK. Why would someone want to set |
Ah, I misunderstood. You want it to figure out if any of RGB is above the threshold and then scale down the value uniformly to keep the hue. |
To be honest, you would want to scale down all colours in the HDR map together. basically you figure out the max value in the RGBE image and then scale it down so that the max fits into the half range -- basically a linear tone mapping operator and maybe also pass back the scaling factor used so you can put that into the intensity value of the envMap. To only scale down the biggest ones would really wreck the local continuity between pixel intensities and cause issues. I think that clamping is fine and probably better than individual pixel scaling - less artifacts. Best case is the overall scaling of the whole image via linear tone mapping into the via half range. |
In theory, yes. But we are talking about only the brightest of the brightest pixels, and for that, I think scaling down just those pixels is fine. Remember, it will be tone mapped, and ACESFilmic, for example, will desaturate the brightest colors anyway. // I still think the problem is not with This PR is not applying the fix in the correct place. |
The problem is that other callers of If necessary, we can mention the clamping in the documentation. Something like:
|
Based on those reasons, I'd post a waring. At least for a while so we can see where the errors are. I do not think clamping is appropriate here. Clamping would be appropriate in |
Thanks! |
Related issue: Fixed #22435.
Description
see #22435 (comment)
This PR ensures that
DataUtils.toHalfFloat()
clamps the parameter to the maximum representable value in float16.I've manually patched
RGBELoader
with this fix in the following live example to demonstrate how it resolves the rendering glitch: https://glitch.com/edit/#!/plastic-copper-hyacinth?path=index.html%3A520%3A22@bhouston Does this change look good to you?