• 13
• 18
• 19
• 27
• 10

# Position invariance in Cg

This topic is 4065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to do a z-cull pass before I draw my scene with vertex and fragment shaders. But I have problem with z-fighting although I use GL_LEQUAL. I have tried my code without using the shaders and then I get no z-fighting. Doing some research here on GameDev I found out that the problem could be due to position invariance, i.e the depth values in the fixed function pipeline compared to the depth values in the shader may not be the same. To fix this I am supposed to use the compiler option -posinv. Here I get real problems. How do I use that option? In a call to cgc? But in my code I use cgCreateProgramFromFile to compile a shader from a source file. Am I supposed to use -posinv when calling cgCreateProgramFromFile? I really do not understand this. What do I have to do meet the following: - Compile the program with a proper compiler option indicating position invariance

##### Share on other sites
Alright...

I found a solution to the problem.

The solution seems to be using the following statement:

mul( glstate.matrix.mvp, position );

instead of using my own calculated modelview matrix like this:

mul(modelViewProj, position);

##### Share on other sites
I haven't used Cg in a while and I never needed position invariance when I did, but it looks like you can pass compiler arguments through the last parameter (args) of cgCreateProgramFromFile. Maybe that will work?

 • Position invariance with respect to the fixed function pipeline is guaranteed if two conditions are met: · The vertex program is compiled using a compiler option indicating position invariance (-posinv, for example). · The vertex program computes position as follows: OUT_POSITION = mul(MVP, IN_POSITION) where OUT_POSITION is a variable (or structure element) of type float4 with an output binding semantic of POSITION or HPOS. IN_POSITION is a variable (or structure element) of type float4 with an input binding semantic of POSITION. MVP is a uniform variable (or structure element) of type float4x4 with an input binding semantic that causes it to track the fixed-function modelview-projection matrix. (The name of this binding semantic is currently profile-specific—for OpenGL profiles, the semantic _GL_MVP is recommended).