Sign in to follow this  

glTranslate and CG

This topic is 4858 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 spend about 3 hours wondering why my shader wasn't working and then i figured out it's because glTranslate doesn't change the vertex position given to the cg shader. Is there anyway to make is affect the vertex position given to the vertex shader or do i just have to make the translate bit on every vertex.

Share this post


Link to post
Share on other sites
The product of the current model-view and projection matrices is passed in to the vertex processor. In the fixed-function pipeline, each vertex is multiplied by these. In the programmable pipeline, your vertex shader is responsible for doing that if you want to.

Share this post


Link to post
Share on other sites
This is my vertex shader

void FragmentLight_V(float4 position : POSITION,
float2 TexCoord0: TEXCOORD0,
float3 normal : NORMAL,

out float4 oPosition : POSITION,
out float2 oTexCoord0: TEXCOORD0,
out float3 objectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2,

uniform float4x4 modelViewProj)
{
oPosition = mul(modelViewProj, position);
objectPos = position.xyz;
oNormal = normal;
oTexCoord0 = TexCoord0;
}

Should i change
objectPos = position.xyz;
to
objectPos = mul(modelView,position).xyz;
and add
uniform float4x4 modelView
to the input parameters?

Share this post


Link to post
Share on other sites
In principle, yes. However, your vertex shader also needs to do the projection, so in general one passes the combined modelview projection matrix (i.e. the product of the two) to the vertex shader and multiplies the position by it. See Lesson 47 (?) for the details, they do it exactly that way (note that the output position is float4 in this lesson and your's is only float3. the 4th coordinate is important when multiplying with the projection matrix).

Share this post


Link to post
Share on other sites

This topic is 4858 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this