Overlapping Textures/Shapes [solved]

Since I am generating my scene at some places I end up with overlapping geometry;

  • simple textures
  • transparent blue plain color

    What you see is that in some spots the blue transparent planes are drawn on top, and in others the arrow textures.

    And then there are a few that are sort of mixed. All dependent on camera angle.

    I realise this is a render ordering issue. Question is, if i always want the transparent planes drawn over the arrow textures, what do I do?

    (drawing the transparent planes closer in space is not really an option).

You will either have to modify the texture or shader or simply not place them exactly on top. You wont be able to solve this issue with rendering order, in a simple example you would see the blue plane on the other side of the box.

Actually many commecial games ave this problem as well, simple solution would be to make the blue sphere minimaly larger.

I hope not to modify shaders for this, but what do you mean with modifying the texture?

What I intend to do here is create a pool of water. Under water the walls (arrow-textures) would get a blue hue, created by the blue transparent material.


I made the boxes slightly smaller but that would leave me with pixel artifacts. Smaller yet and I see the textures cut into eachother again like in the image above.

Making the boxes larger doesnt work either as that would leave the water on the wrong side of the surface.

In update you coudl check for the water tiles if a normal tile is also there, if so, set its cullhint to always so it is not renderd at all.

Try using material.getAdditionalRenderState().setPolyOffset(), what it does is alters the depth value of the pixel so you can kinda move it forward a bit so you don’t have the artifacts.

1 Like
Momoko_Fan said:
Try using material.getAdditionalRenderState().setPolyOffset(), what it does is alters the depth value of the pixel so you can kinda move it forward a bit so you don't have the artifacts.

That did the trick. Exactly what I wanted. No Z-buffer fighting any more, and i can keep my geometries exactly on the grid.
The only drawback is that the water surface is 'on top' viewed from the adjacent solid cube too, but I don't think that will ever be visible any way.

float factor = -1.0f;
float units = -1.0f;
material.getAdditionalRenderState().setPolyOffset(factor, units);

It took quite some googling to find out what the parameters meant and what values to put in. I have tried to patch the much needed comment to the code using the new google edit-file functionality, but after logging in and selecting the RenderState.java file it only showed the top third of the file in the edit window and wouldnt let me scroll down further.

So maybe one of you could put some comment in, Here is the background, method and parameter description.

I suggest
* Offsets the on-screen z-order of the material's polygons, to combat visual artefacts like
* stitching, bleeding and z-fighting for overlapping polygons.
* Factor and units are summed to produce the depth offset. This offset is applied in screen space,
* typically with positive Z pointing into the screen.
* Typical values are (1.0f, 1.0f) or (-1.0f, -1.0f)
* @see http://www.opengl.org/resources/faq/technical/polygonoffset.htm
* @param factor scales the maximum Z slope, with respect to X or Y of the polygon
* @param units scales the minimum resolvable depth buffer value

Thanks :)