PDA

View Full Version : Fading out the edges of my terrain



Dan M
08-14-2010, 06:29 AM
Hi there,

I have some terrain in a grid. I'd like the edge to fade out so that the isn't a hard join between the void and the viable positions. I followed a method that I knew was going to result in the problem I currently have as I thought that I would have come up with a way to remedy it by now, but haven't.

So, at the moment I:
- Find the intersection between my camera location and the frustum's far centre with the four planes making up my terrain's boundary.
- Take the intersection point which is closest to me further (discounting ones behind me)...
- Calculate the signed distance between the point and the plane.
- Use this distance to setup GL_FOG_LINEAR's START and END values.

The problem is probably obvious. When I'm looking at a plane that's perpendicular to me everything's is fine. When I am near a plane and looking parallel to it towards an adjacent plane I can see the hard edge because the fogged distance is at the adjacent plane. When I'm near a plane and looking at it, but at an acute angle the fog is very close and obscures much of the terrain that should be visible.

So I guess I can't simply use GL's fog and have to come up with something more serious. Any suggestions of new methods or any way to remedy my current situation?

Thanks for any help you can offer,
Dan.

Dark Photon
08-14-2010, 09:04 AM
When I'm looking at a plane that's perpendicular to me everything's is fine. When I am near a plane and looking parallel to it towards an adjacent plane I can see the hard edge because the fogged distance is at the adjacent plane. When I'm near a plane and looking at it, but at an acute angle the fog is very close and obscures much of the terrain that should be visible.

So I guess I can't simply use GL's fog and have to come up with something more serious. Any suggestions of new methods or any way to remedy my current situation?
Sounds like you just need fragment fog. Easy with a shader.

With the old fixed-function pipe, two things that might help your situation. First, seems like there was a FOG_HINT NICEST you could use to encourage certain hardware that could hack it to do fragment fog.

Second, let the GPU compute the fog coordinate, and use EYE_RADIAL rather than EYE_PLANE or EYE_PLANE_ABSOLUTE for highest quality.

And I wouldn't keep messing with START. Set that at some fixed distance out and leave it. I'd actually suggest that with END too. Ideally you've got some basic "range you can see", and you preset your fog parameters based on that. Fog is meant to simulate uniform atmospheric attenuation, and changing it rapidly based on changes in the scene objects just looks wrong.

Dan M
08-14-2010, 11:39 AM
Hi, thanks for the reply.

I will look into shaders, they've been looming on my list for a while now. Thanks for pointing me in the right direction.

However, I would like to understand more of what you meant by:

Second, let the GPU compute the fog coordinate, and use EYE_RADIAL rather than EYE_PLANE or EYE_PLANE_ABSOLUTE for highest quality..

How would I get the coordinate out of the GPU? And I'm afraid I haven't the foggiest (woohoo) idea what EYE_RADIAL, etc are. Indeed, google returns this post as the 2nd most relevant link when searching for it.

And you're right - the current fogging does look wrong, even when moving around an area that was relatively compliant.

Thanks again!

Dark Photon
08-14-2010, 08:28 PM
However, I would like to understand more of what you meant by:

Second, let the GPU compute the fog coordinate, and use EYE_RADIAL rather than EYE_PLANE or EYE_PLANE_ABSOLUTE for highest quality..

How would I get the coordinate out of the GPU? And I'm afraid I haven't the foggiest (woohoo) idea what EYE_RADIAL, etc are.
Well, it wasn't completely obvious from your description what exactly the problem(s) was/were. But beyond dynamically changing the linear fog start/end based on what the scene looked like, it sounded like maybe some of your issue might be attributable to the frequency and method that the GPU is computing fog coordinates (i.e. distances from the eye) to use as input to the fog equation.

For more detail on this, see the "Fog Equations" section at this link (http://glprogramming.com/red/chapter06.html#name3). z is the eye-coordinate distance. There are 3 main methods for computing this. Eye-plane (i.e. eye-space Z value), eye-plane-absolute (absolute value of eye-space Z value), and eye-radial (actual 3D distance from the eye). If everything's pretty far from the eyepoint and your FOV isn't huge, then these are all fairly close together, but if not (obj close to eye or large FOV), the difference can be huge.