• Advertisement
Sign in to follow this  

cg shader and Inverses matrix

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


  // 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
Sign in to follow this  

  • Advertisement