I am trying to build an infinite fog shader. This fog is applied on a 3D plane.
For the moment I have a Z-Depth Fog. And I encounter some issues.
As you can see in the screenshot, there are two views.
The green color is my 3D plane. The problem is in the red line. It seems that the this line depends of my camera which is not good because when I rotate my camera the line is affected by my camera position and rotation.
Ok ! That’s why depth is calculated with the camera position.
But I don’t know how to correct it… It seems that there is no way to get the depth from another point. Any idea ?
Any idea ? How can I get the depth buffer from another camera and use it to calculate the depth of the actual camera ? Is it a good process or should I use a matrix effect or anything else ?
I am a bit lost with this… Any help is welcome.
There is an explanation of what I am trying to achieve in the beginning of the thread.
I am trying to apply Z-Depth fog on a surface (a plane) like explained above. It’s very close to the Global fog but it’s “projected” in a plane.
But the depth is calculated from the actual camera so I don’t have always a perpendicular depth (look above for screenshots).
Okay, hmm this is kinda tricky since DepthTexture is in Camera/ScreenSpace coord. and i’m not sure if it’s possible to render depthtexture using multiple camera to achieve different depth buffer since Unity DepthBuffer is shared between camera CMIIW. What renderPath did you used Forward or Deffered?
For the moment, I use deffered but it would be cool to be able on both.
This was a solution in my mind but if there is another solution to obtain a fog like the blue line. I will accept any solution !
Ok, it seems I misunderstood what Annihlator explained. But what can I do when I have the distance between my plane’s vertex and my camera in my vert function ? should I project my matrix ?
Well, then you basically know the amount of air volume, so i’d suggest to use that value for basing your fog transparancy.
For example;
We can expect the value returned to be in the 0-inf. Range, by remapping this with a formula you’ll be able to determine how much fog you should have drawn.
Say in the case of exponential fog;
Float FogFactor = inverselerp(0, 100, dist*dist) should result in something to get you started
I am really sorry but I don’t get it.
I will have the distance between my camera and my plane’s vertex, not between my plane and other objects… How am I supposed to calculate fog with this ? Should I use cameradepth ?