-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
FOG_EXP2: Avoid possible over-/underflow when squaring on mediump #17324
base: dev
Are you sure you want to change the base?
Conversation
Context: 69a8d3b#diff-70001492be345858ece4ba692249de2c Before that commit, there was independent potential for overflow and underflow. Using the/a square function would improve readability and likely not affect performance. Should I modify to Hm, I believe reintroducing |
Why not write it like so? float fogFactor = 1.0 - exp( - pow2( fogDensity * fogDepth ) ); |
@WestLangley Quoting https://community.khronos.org/t/pow-x-2-different-then-x-x/70839 (which refers to the docs)
Would you want to replace all squares with this? log2(x) will fail for non-positive x, and exp and log are more demanding to calculate than simple multiplications, right? pow is made to be general, but for squaring, only multiplication is needed. |
More support for my PR: Here are descriptions (non-official source) of float precisions and a mention of the problem that @WestLangley tackles with #17323 : http://asawicki.info/news_1596_watch_out_for_reduced_precision_normalizelength_in_opengl_es.html Now consider the task of multiplying small,small,big,big in some order. If any part of the calculation fails, the whole calculation fails. But it is not exactly elegant to write out all squares as products where all factors are repeated. This would be more elegant:
And this would be more elegant, and be about as easy for the compiler to optimize:
Apparently, I believe a function is much better than a macro for this, because a macro will expand the argument and evaluate it two times, whereas a function will evaluate the argument and then square only the result. I am beginning to feel that I should include a new |
I answered that above. |
@@ -3,7 +3,7 @@ export default /* glsl */` | |||
|
|||
#ifdef FOG_EXP2 | |||
|
|||
float fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth ); | |||
float fogFactor = 1.0 - exp( - pow2( fogDensity * fogDepth) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
float fogFactor = 1.0 - exp( - pow2( fogDensity * fogDepth ) );
For clarity, can you please fix the formatting and squash the commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed the formatting, but don't know how to squash the commits. I made the edit in the online editor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I failed to squash the commits, but achieved the intended outcome by using the sledgehammer of force-push. 😨 Looks right, although the "Thank you, @WestLangley!" disappeared. Thanks, anyway. 😄
Also correct TS docstring and misspelled name in test file for FogExp2. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete.
Also correct TS docstring and misspelled name in test file for FogExp2. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete.
Also correct TS docstring and misspelled name in test file for FogExp2, and doc for standard Fog. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete.
Also correct TS docstring and misspelled name in test file for FogExp2, and doc for standard Fog. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete.
Abandoning in favor of #17355. EDIT: Or not. |
Also correct TS docstring and misspelled name in test file for FogExp2, and doc for standard Fog. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete.
Also correct TS docstring and misspelled name in test file for FogExp2, and doc for standard Fog. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete.
author Elias Hasle <elias.hasle@gmail.com> 1566822048 +0200 committer Elias Hasle <elias.hasle@gmail.com> 1569597690 +0200 RangeFog(color, near, far) and DensityFog(color, density, squared) Added fog types example. Currently includes some extra examples that show functionality of legacy signatures, and mediump and lowp operation for all fog types. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fix legacy example and mediump example Attempted fixes for editor
Added fog types example. Currently includes some extra examples that show functionality of legacy signatures, and mediump and lowp operation for all fog types. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fix legacy example and mediump example Attempted fixes for editor Formatting + typos
Added fog types example. Currently includes some extra examples that show functionality of legacy signatures, and mediump and lowp operation for all fog types. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fix legacy example and mediump example Attempted fixes for editor Formatting + typos
Added fog types example. Currently includes some extra examples that show functionality of legacy signatures, and mediump and lowp operation for all fog types. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fix legacy example and mediump example Attempted fixes for editor Formatting + typos
Added fog types example. Currently includes some extra examples that show functionality of legacy signatures, and mediump and lowp operation for all fog types. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fix legacy example and mediump example Attempted fixes for editor Formatting + typos Fixed TS declarations (Not sure I am using IFog right)
Added fog types example. Currently includes some extra examples that show functionality of legacy signatures, and mediump and lowp operation for all fog types. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fix legacy example and mediump example Attempted fixes for editor Formatting + typos Fixed TS declarations (Not sure I am using IFog right) Fixed support for scene.fog=null
Added fog types example. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fixed support for scene.fog=null Fixed TS declarations New best guess is `fog: IFog | null`
Added fog types example. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fixed support for scene.fog=null Fixed TS declarations New best guess is `fog: IFog | null`
Added fog types example. Includes the change to distance-based depth, as well as corrections to better support mediump. Makes mrdoob#17316 and mrdoob#17324 obsolete. Force update when squared is changed. Fixed support for scene.fog=null Fixed TS declarations New best guess is `fog: IFog | null`
I would like to reopen this, since it has merit on its own, as described in the discussion above. The large, neglected and currently outdated #17592 should not be holding back a bug fix. I should add that this is now more properly called a Draft PR, since the newest version is completely untested. It theoretically prevents some overflow/underflow situations that may arise with |
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
…erflow on mediump
…5498) * Nodes: Rework ShaderNodeElements and make some other refactorings * Fixes * fix add assign * Fix circular dependency and clean up * Rename addNode -> addNodeElement and LightsNode.setReference -> addLightNode, add addNodeClass and addNodeMaterial --------- Co-authored-by: sunag <sunagbrasil@gmail.com>
No description provided.