Game Development Community

T3D 1.1Beta3 - Black Line Rendering Objects at MaxDistance Through Fog - RESOLVED

by Steve Acaster · in Torque 3D Professional · 01/25/2011 (9:25 am) · 12 replies

Have a feeling that this hasn't been reported ...

T3D 1.1 Beta 3

Win7 32bit (Nvidia GTS 250)

Target:
World Editor, visibleDistance, fog, rendering objects

Issue
When using fog (set to any level but more noticeable when fog is dense) and a low visibleDistance, a black band is visible when an object comes into rendering distance and draws across the object as the camera moves that object into visibleDistance.

img13.imageshack.us/img13/3175/drawthrufogissue.jpg
The real issue is that when using low visibleDistance and high fog to limit rendering of world objects and thus improve performance, the transition from being beyond renderable distance to moving into rendering is ugly as hell. Note: this black line only appears when fog is used and does not happen when only visibleDistance is lowered.

Repeat:
Set VisibleDistance low (eg 100), fog density high(eg 0.1) with no offset, and choose a light fog colour. Have objects in the World. Move camera towards and away from where objects are so that they go through the VisibleDistance range. Notice the black line as new objects/terrain draws. Remove fog and repeat, notice no black line, speculate it's an issue with rendering and fog.

Suggest:
Make rendering of objects entering visibleDistance when fog is used to be seamless and without the currently accompanying black line ... somehow.

#1
01/25/2011 (12:58 pm)
Reproduced this with those fog settings. No idea what's causing it, but I noticed a couple things that could help track it down:
-The black seems to vanish entirely when switching to Basic Lighting.
-You can actually reproduce this with higher visibilities and lower fog densities, it's just not as blatantly obvious.
-By zooming way in I discovered that it's not actually just a black line; the fog is failing to render on the very last few polygons of objects that are being cut off by the visibleDistance. Here's a screenshot at fov 5:
ubermonkey.org/torque/fogLines1.jpg
and a similar screenshot with the fog disabled:
ubermonkey.org/torque/fogLines2.jpg
So you can see that the black bits are actually some sort of rendering glitch that occurs in triangles at/near the visibility cutoff. The issue appears to be that the fog is cutting off a bit before the edge of the models, and those black bits are extremely obvious compared to the often-light fog color.

Also, notice the line of tiny black dots visible in the pic 2? Those seem to define the line where the fog stops in pic 1. Could this be the point where the geometry is supposed to be cut off, making the geometry beyond that point some sort of glitch?

*Edit: I should probably mention... Win7 64-bit, nV GTX 285
#2
01/25/2011 (3:34 pm)
@Steve: Having the same problem as well, though the screenshots are not as bad I had to move the camera for the better effect.

@Henry: Wow, that looks bad...(Though I didnt go looking for it either) Mine are about the same as Steve's (AL only)

i566.photobucket.com/albums/ss101/CS_MP/MPGE/Bugs/screenshot_004-00000.pngi566.photobucket.com/albums/ss101/CS_MP/MPGE/Bugs/screenshot_005-00000.png
Edit: (My Environment)
T3D 1.1 Beta3

Win7 64bit (Nvidia GeForce 9600GT)

#3
03/21/2011 (1:28 pm)
Logged as THREED-1501. It feels familiar, too, but I could not find the duplicate.
#4
03/21/2011 (1:57 pm)
I noticed this. It's very easy to reproduce if you use a ground plane, a small clip distance and colored fog. At some camera positions, a line can be seen where the ground plane is clipped.

The problem seems to be with the g-buffer rendering/packing: the depth buffer has a value of zero in those pixels, causing them to be unfogged.
#5
04/07/2011 (3:59 pm)
Looks better in 1.1P if not 100% if you don't mind me being a miserable git
#6
04/08/2011 (10:39 am)
The issue is we hacked the fog to not hit the sky. So there is a little tolerance there which causes the artifact.

Anyway... its in the tracker now... it will get fixed.
#7
10/11/2011 (11:16 am)
Hmm, another 1.1 fix that fell through cracks and didn't get to me to close out. This should be fixed in 1.1, definitely fixed in 1.2.
#8
10/11/2011 (2:13 pm)
Could the fix be posted for this. It for sure still exists in 1.1F.
#9
10/12/2011 (3:46 am)
Quote:Could the fix be posted for this. It for sure still exists in 1.1F.

That would be nice.
#10
10/13/2011 (3:50 am)
Just noticed that this is also happening with imposters.
#11
11/16/2011 (1:52 pm)
Still an issue in 1.2.
#12
06/17/2012 (12:21 pm)
It seems like the actual "black" bits of terrain were fixed, however bits of terrain that get rendered past the far clip plane (due to z-buffering) don't get fogged out, so they still create a pretty obvious band.

I was playing with the fog shader today and I found where the problem is coming from (though not an actual fix). In the fog shader (shaders/postFX/fogP.hlsl) there's this line:

float depth = prepassUncondition( prepassTex, IN.uv0 ).w;

which gets the scene depth of the pixel (0-1.0 from camera to far clip). The problem is that any pixels farther away than the far clip (and our extra bits of terrain are, they're z-buffer fighting from behind the far clip) end up with extremely low "depth" values resulting in no fogging.

Here's a bit of code you can use to test this theory:
float depth = prepassUncondition( prepassTex, IN.uv0 ).w;
   if (depth < 0.01)
      return hdrEncode( float4( fogColor.rgb, 1.0 - saturate( 0 ) ) );

This will result in full fog out to 1% of the scene depth, but it will also fully fog our extra strips of polygons in the distance.

Unfortunately I've never done shader programming before so I really have very little idea how that line calculates scene depth or how to fix it. I did find that if you went to line 135 of terrCellMaterial.cpp and "lied" about the far clip distance to the shaders:

vEye.normalize( 1.0f / (farPlane + 100.0f) );

Then the fog would catch those extra bits (because it's using 1100 as the far clip distance instead of 1000, or whatever value is set in your levelInfo), but this will break some other shader things (most notably shadows). So what I'm trying to figure out now is how I can essentially do this same thing from inside fogP.hlsl, but no luck so far.

I'm hoping some of this might be helpful to someone who knows enough about shaders to actually solve it.