Jump to content
  • Advertisement
Sign in to follow this  
neatdev

Position invariance in Cg

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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?

EDIT: Missed your second post while I was replying...

According to the Cg Spec, it looks like that is just one of the two conditions needed to guarantee position invariance, the second being the position invariance compiler option so I would still add that in as well to guarantee position invariance. From the Cg Spec...
Quote:
• 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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!