Shader pass over fixed pass in Cg.

Started by
3 comments, last by GhostAce 18 years, 6 months ago
Hello. I want to render object in two passes. First one is just a texture pass (without shaders) and second one has vertex and fragment program (lighting pass). My problem is that i see z-fighting artifacts. Is there a way to mix that passes so that there wouldn't be z-fight? I tried cgGLSetStateMatrixParameter and cgGLSetMatrixParameterfc with explicitly calculated ModelViewProj but the result is the same.
Advertisement
I think for the second pass you just need to change your depth function for passing a fragment. Make sure it now includes equality.
But thats the point. I already have equal depth func.
The problem is that fixed pipeline ModelViewProj transformation produces different output vertex position than my vertex program.

I think the reason lies in precision. I didn't see 'double4x4' in cg manual matrix type - so I have to use float4x4. I think opengl internal calculations are done on 'doubles', and that results in z-fighting.

any ideas?


Make sure you are doing everything it mentions in the "Vertex Program Profiles - Position Invariance" section of the Cg spec. That is...
 - Compile the program with a proper compiler option indicating position invariance - Compute the position as OUT_POSITION = mul(MVP, IN_POSITION)
For more info consult the spec. Hope that solves your problem.
I compiled with "-posinv" and now its ok.
thx

This topic is closed to new replies.

Advertisement