Horde3D
http://horde3d.org/forums/

z fighting
http://horde3d.org/forums/viewtopic.php?f=2&t=312
Page 1 of 1

Author:  jimbo [ 26.04.2008, 19:45 ]
Post subject:  z fighting

Hi,

I've been able to create decals using the parallax shader, but now they are z fighting,
is there a way to prevent this without offsetting the node?

Author:  AcidFaucet [ 26.04.2008, 20:04 ]
Post subject:  Re: z fighting

Can you post a screenshot and/or give some information about how you're creating the decal (geometry, projected texture, etc)? It'd help a lot.

Author:  jimbo [ 26.04.2008, 21:38 ]
Post subject:  Re: z fighting

I'm creating a mesh node from a simple plane, then align it to the collision normal.

Code:
<Model name="bullethole" geometry="bullethole.geo">
   <Mesh name="bullethole_mesh" material="bullethole.material.xml" batchStart="0" batchCount="6" vertRStart="0" vertREnd="3" />
</Model>

<Material>
   <Shader source="parallax.shader.xml"/>
   <TexUnit unit="0" map="bullethole.tga" />
   <TexUnit unit="1" map="bulletholeBump.tga" allowCompression="false" />
</Material>

Author:  AcidFaucet [ 26.04.2008, 23:42 ]
Post subject:  Re: z fighting

Depth test is probably discarding the fragments then, you'll have to push it slightly above position.

If depth test says its close enough to try then you may be able to offset it in either the vertex or pixel program. I'd try offsetting just in either shader first, as that'd be easier than trying to find the right position.

EDIT: Does the z-fighting only occur where parallax'ed fragments are being pushed back?

Author:  jimbo [ 27.04.2008, 13:05 ]
Post subject:  Re: z fighting

I can fix the problem by adjusting the positioning of the node just a tiny bit off the wall, but I was wondering
if there's another way. Because using a fixed position off the wall will make z-fighting happen again when
multiple bulletholes are over each other. Also I'm having a problem with the transparency using the
parallax shader, please see these images:

Image
standard.shader.xml with small offset

Image
parallax.shader.xml with small offset

Image
z-fighting with no offset

You can see the alpha channel for the diffuse image doesn't seem to work with the parallax shader, do I need to do anything special to the diffuse image of relief image to make it transparent?

Author:  Volker [ 27.04.2008, 14:15 ]
Post subject:  Re: z fighting

Did you already consider setting gl_FragDepth in the shader?

Author:  jimbo [ 27.04.2008, 15:22 ]
Post subject:  Re: z fighting

To what value in which pass? Setting gl_FragDepth = 0.0 in the LIGHTING context fragment shader
does something, but when moving the camera it start fighting again.

Author:  AcidFaucet [ 27.04.2008, 17:17 ]
Post subject:  Re: z fighting

Your shot of z-fighting is what I would expect if they're right on top of each other. In which case it should be close enough that any OGL settings won't chop it, so you could offset inside the vertex shader by pushing slightly along the direction of your normal. Or as volker suggested and I suggested before offset the pixel depth. Have you checked "LightHouse3D" for its GLSL tutorials? They cover a lot of stuff such as this.

Your transparency issue looks to be normal for true/false transparency. To reduce it you'd just have to continue your color texture a bit further into the black space or enable it to work with a range of values. Are you creating transparency with discard?

Author:  Volker [ 28.04.2008, 07:37 ]
Post subject:  Re: z fighting

Untested:
Code:
float offset = 0.0001;
gl_FragDepth = gl_FragCoord.z + offset;

So you have to give the decals a special shader for all contexts and put the lines above in the fragment shader. This way the z-value should
be moved a little bit (maybe the offset has to be negativ, not sure, haven't tested it myself yet).

Author:  jimbo [ 28.04.2008, 07:58 ]
Post subject:  Re: z fighting

Thanks that totally works! Now I need to make that value adjustable for multiple decals over each other.
I also fixed the transparency by adding
Code:
if( albedo.a < 0.5 ) discard;
in the parallax shader.

Author:  jimbo [ 28.04.2008, 21:03 ]
Post subject:  Re: z fighting

Well, I'm still having a problem with that solution, I can set the gl_FragDepth value,
but how can I use the same shader for multiple decals? setting a
uniform value doesn't do it because it will use the same value for
all rendered decals, which will cause them to z-fight with each other.

Author:  AcidFaucet [ 29.04.2008, 00:28 ]
Post subject:  Re: z fighting

You could keep a small collection of material instances for decals. This would let you give them custom offsets. It's pretty much a hack and not a good solution.

Nothing else comes to my mind outside of manually positioning the decals. I recall that FEAR doesn't have overlapping geometric decals.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/