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

Distance based fog? #14601

Closed
2 tasks done
greggman opened this issue Jul 31, 2018 · 8 comments
Closed
2 tasks done

Distance based fog? #14601

greggman opened this issue Jul 31, 2018 · 8 comments

Comments

@greggman
Copy link
Contributor

Should fog be distance from camera instead of distance from camera's zplane?

Currently fog is just the z distance from the zplane of the camera. That means if you just turn the camera in place objects that are not really getting closer to the camera come out of the fog. That doesn't seem correct (although maybe it's intentional?)

Here's 6 cubes in a circle around the camera. The camera is spinning in place. you can see the cubes come out of the fog even though they are not actually closer to the camera

http://jsfiddle.net/greggman/Lx3mhvbe/

Changing the fog from this

fogDepth = -mvPosition.z;

to this

fogDepth = length(mvPosition);

Seem like it might work?

Example: https://fog-fix.glitch.me/

Not sure it's correct but the objects are no long coming out of the fog

Three.js version
  • Dev
  • r94
@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 31, 2018

I think this is a good suggestion.

@WestLangley
Copy link
Collaborator

Ditto.

@greggman Do you want to file a PR?

@mrdoob
Copy link
Owner

mrdoob commented Jul 31, 2018

Agreed. I never liked this fog technique.

@mrdoob mrdoob added this to the r96 milestone Jul 31, 2018
@mrdoob mrdoob removed this from the r96 milestone Aug 1, 2018
@mrdoob mrdoob closed this as completed Aug 1, 2018
@WestLangley
Copy link
Collaborator

Actually, this approach only works correctly if the distance is calculated in the fragment shader, not in the vertex shader. So #14602 will have to be reverted for now.

@barnabasbartha
Copy link

Is there any progress about this issue?

@amitukind
Copy link

Is there any progress on this? I have implemented it and I am going to create a PR.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 15, 2021

There is already a PR for this, see #17592.

And this is the leading issue: #17420

@amitukind
Copy link

@Mugen87 I need to change in realtime all object's opacity based on their distance from the camera. The fog technique doesn't work there. Changing manually in animate is consuming a lot of CPU.

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

No branches or pull requests

6 participants