Weird lines in textures


I’ve got a scene set up with a height map to create a harbour scene. I want to add a ‘water’ quad now as quick water generation, but when I place a Quad through the scene that is located between the lowest and the next lowest levels in the scene, parts of the water layer scan through.

When I zoom in close enough the lines disappear. They change position with every change in camera position. Any ideas what could be triggering this?


Perhaps Z-fighting

Do you have anything right under the water?

Yes, there's something very close underneath. I believe the bottom is at y=0.0f and the water is at 1.0f. The near and far plane are now at 1 and 1000 respectively. When I tested it with them at 400 and 500  is actually became worse, as now there were thick blue lines running through the green as well.

As the blog article explain, the z buffer is much more accurate near the camera than at a distance.

It could be however, that you're running with a lower resolution z buffer. If you're using SimpleGame you can change the minimum by placing

// eg
depthBits = 16
// or
depthBits = 32

in the constructor of your SimpleGame derived class. Of course if it's higher than what your card supports it won't work.

Also, when you're that far above the terrain, you can set the near value a lot further.. there's no reason to set it at 1 when between 1 and 300 there is nothing, because if you do that by far the largest part of the depth buffer is wasted on an area with no object at all.

I tried setting the depth buffer to both 16 and 32 without noticable improvements. I've pulled the farplane towards the camera, and brought the nearplane out somewhat. I have to be able to zoom up very close so I can increase the nearplane too far.

You can update the camera near and far plane based on the position of the camera. If you're close to the terrain, far does not have to be very far, if you're way up like in the screenshot, near does not have to be so near.

Good advice, thanks. Which ever way I set my near- and farplane or my depthbuffer size, it doesn't solve the problem, just makes it worse.

Well, you said when you get nearer to the terrain the problem goes away. That's because, as explained on the blog, the accuracy is higher near the camera. So if you said the problem gets worse (worse than that screenshot??) when you set a further away near plane, I doubt that's true. You just get a different effect, most likely… either that, or it's something else that's going on here :slight_smile:

As for setting the depthBits, usually it takes the highest value anyway (what you're specifying is the minimum). So that doesn't have to have an effect, it was just to make sure.

I understand what you’re saying in the blog and am going to read that blog a lot more often from now :wink: This is a screenshot from the game, where the nearplane is set to 300 and the farplane is set to 800. The heightmap is a TerrainPage and is 513 deep.

This is a screenshot of what it looks like now.

Hm… nVidia card?

I'd consider raising the land a bit, compared to the water. I think it's closer to the water quad than the land under the water, no?

Or you could lower the land under the water a bit (though with these setting it might not be required), and draw the water first, and then draw the land with a polygon offset. See renderer.setPolygonOffset(float, float). With that you can make the Zbuffer pretend the land is actually a little higher than it actually is. You can also look at ZBufferState.