Jump to content
  • Advertisement
Sign in to follow this  
giugio

cg shader and Inverses matrix

This topic is 3033 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

Hy. I have this vertex shader:

// geometric input (sent by application)

struct appin
{
  float4 Position     : POSITION;
  float3 Normal       : NORMAL;
  float3 TCoords0     : TEXCOORD0;
};

// vertex program output

struct V2FI
{
  float4 HPosition    : POSITION;
  float3 TCoords0     : TEXCOORD0;
  float3 Normal       : TEXCOORD1;
  float3 ViewVector   : TEXCOORD2;
  float3 LightVector  : TEXCOORD3;
};

V2FI main(appin IN,
	  uniform float4x4 Proj   : register(c0), // projection matrix

	  uniform float4x4 View   : register(c4), // modelview  matrix

	  uniform float4x4 ViewI  : register(c8),
	  uniform float4x4 ViewIT : register(c12),
	  uniform float4   LightPos               // light pos in object space

	  )
{
  V2FI OUT;

  // compute view vector

  float4 pos       = mul(View, IN.Position);
  OUT.ViewVector   = -pos.xyz;
  // compute light vector

  float4 lightpos  = mul(View, LightPos);
  OUT.LightVector  = (lightpos-pos).xyz;
  // project point onto screen

  OUT.HPosition    = mul(Proj, pos);
  // transform normal - should use inverse transpose !

  OUT.Normal       = mul(ViewIT, float4(IN.Normal,0.0)).xyz;
  // copy texture coordinates

  OUT.TCoords0     = IN.TCoords0;

  return OUT;
}



why don't use in any mode the world matrix? Thanks.

Share this post


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