-
-
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
Fix fog to use view distance #17316
Fix fog to use view distance #17316
Conversation
@greggman did you try this? |
What happened to #14633? |
Oh, now I remember suggesting #14740 (comment). Something similar was subsequently tried, but I have lost track as to why even that did not work... |
It was apparently reverted because @titansoftime showed a screenshot of fog that did not work with the update, but without providing a way to verify that the root cause of the problem was fog. #14786 (comment) Notably, the problem was with medium precision and FogExp2, which may be a bad combination, since FogExp2 squares the depth. ("My" proposed FogExp would perhaps be a better match for medium precision, although it has different characteristics.) |
Eekk! Looks like this has a lot of history. To prevent any issues with lowerp, and at least get it usable where it does work, I've limited using view distance method to highp. So, only highp should see this change, and it looks to be working across the board with the limitation in place. Once @EliasHasle implements the new FogExp method it can be revisited. |
I'd suggest something like #14752 (comment). Until someone can demonstrate that it does not work. Claiming is not demonstrating. |
If y'all bug out fog again, I will be sure to provide a jsfiddle demonstrating the issue in addition to screenshots. |
@WestLangley I entirely agree that's where things should be heading, but I fear history will simply repeat itself. At least if there is somewhere to revert back to, it doesn't mean losing distance fog entirely again. |
@supereggbert Personally, I am not a fan of your proposed implementation which has completely different rendering results based on precision / device. #ifdef HIGHP_PRECISION
float fogDepth = length( fogPosition );
#else
float fogDepth = - fogPosition.z;
#endif I think that will surprise devs. |
@WestLangley I agree it's far from optimal, but the result is far from completely different. Considering the issues are arising from lowerp, mixed with the fact the actually difference is very subtle, it's only really evident with a wide viewing angle on desktop/xr (see screenshots). I'd be willing to bet the precision issues will, more or less, be completely wipe out any difference on lowerp anyway. I'm sure, 99.99% of devs will not notice it's absence on mobile but it can be annoyingly evident on desktop/xr with camera rotation. Plus, it's hopefully only a stopgap/placeholder until a more global solution is found to the length function precision problems, which is probably better suited to it's own PR, as it potentially covers more then just fog. |
I agree with @WestLangley . @titansoftime Is there a chance that your FogExp2 problems on mediump could be caused by the order of multiplication in the shader?
Wouldn't this be safer against mediump overflow, considering that
|
I'm not sure. That PR was reverted a while ago and re-implementing an old version of three.js to test in my app is not something that I want to spend time on. |
In C, multiplication is left-associative: https://stackoverflow.com/a/31630985/4071801 I will have to assume it works the same in GLSL, since they are so similar. For this case, that means the current code will first square the density, then multiply with depth two times. If it were the other way around, I would expect to see overflow on the exponent bits if the precision were low. But I suppose there is equally a potential for "underflow" on the exponent when squaring the density too, so I will submit a PR: #17324 I hope this can pave the way for a new attempt at introducing @bhouston's |
Ya know, I actually did make a fiddle back then =P |
But not in the second report, after the fix, right? I didn't want to be harsh against you, anyway. I understand that stuff like this cannot always be a priority. :-) Pinged you to get your (current) perspective/explanation. |
Incorrect. #14786 No offense taken =] |
FOG_EXP2 could avoid squaring a square root with a few modifications. Something like:
This would replace the need for @supereggbert Will you do this change? ( |
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.
Be aware that this PR, as currently-written, is going to significantly change fog behavior for users who use linear fog with and an I will not be surprised if there are complaints. |
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.
I have incorporated the functionality of this PR as part of the larger PR #17355. It was the most practical way to do it, since I both added
@WestLangley The last time I checked, |
In my experience, It's quite common. @Mugen87 can decide if we want to break this. I am just raising the issue so everyone is aware of it. Modify the scene.fog = new THREE.Fog( 0xcccccc, 100, 1000 );
var h = 120, aspect = window.innerWidth / window.innerHeight;
camera = new THREE.OrthographicCamera( - h * aspect, h * aspect, h, - h, - 1000, 1000 );
camera.position.set( 4, 1, - 4 ); |
Again, that is an undocumented feature (my emphasis):
Presumably positive infinity.
I don't argue that placing @WestLangley How about multiplying in |
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.
@EliasHasle That's fine with me. |
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 see you closed this. #17592 is the up-to-date PR that incorporates the same idea, corrects some numerical issues, improves the OO logic and adds support for truly exponential fog (without squared exponent). It seems to be indefinitely stuck in the fog, though. 😕 |
@EliasHasle do you mind writing a "/bump" comment in that PR so it goes back up on my list? |
#14601 #14602 #14601 #14617 #17274