Horde3D

Next-Generation Graphics Engine
It is currently 02.05.2025, 15:04

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: z fighting
PostPosted: 26.04.2008, 19:45 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 26.04.2008, 20:04 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 26.04.2008, 21:38 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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>


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 26.04.2008, 23:42 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 27.04.2008, 13:05 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 27.04.2008, 14:15 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Did you already consider setting gl_FragDepth in the shader?


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 27.04.2008, 15:22 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 27.04.2008, 17:17 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 28.04.2008, 07:37 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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).


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 28.04.2008, 07:58 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 28.04.2008, 21:03 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: z fighting
PostPosted: 29.04.2008, 00:28 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group