Jump to content
  • Advertisement
Sign in to follow this  
mlt

Transforms in vertex program?

This topic is 3630 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 currently using the vertex program from the Cg Toolkit:
struct vertex_input
{
  float4 position : POSITION;
  float4 normal   : NORMAL;
};

struct vertex_output
{
  float4 position : POSITION;
  float4 color    : COLOR;
};

vertex_output main(
                     vertex_input IN
                   , uniform float4x4 ModelViewProj 
                   , uniform float4x4 ModelViewIT   
                   , uniform float4   light_vector	
             )
{
  vertex_output OUT;  
 
  // Transform vertex position into homogenous clip-space.
  OUT.position = mul(ModelViewProj, IN.position);  
  
  // Transform normal from model-space to view-space/eye-space
  float3 normalVec = normalize(mul(ModelViewIT, IN.normal).xyz);
  
  // Store normalized light vector.
  float3 lightVec  = normalize(light_vector.xyz);
  
  // Calculate half angle vector.
  float3 eyeVec    = float3(0.0, 0.0, 1.0);  
  //float3 halfVec   = normalize(lightVec);
  float3 halfVec   = normalize(lightVec + eyeVec);
  
  // Calculate diffuse component.
  float diffuse    = dot(normalVec, lightVec);
  
  // Calculate specular component.
  float specular   = dot(normalVec, halfVec);
  
  // Use the lit function to compute lighting vector from
  // diffuse and specular values.
  float4 lighting  = lit(diffuse, specular, 32);
  
  // Blue diffuse material
  float3 diffuseMaterial = float3(0.0, 0.0, 1.0);
  
  // White specular material
  float3 specularMaterial = float3(1.0, 1.0, 1.0);
  
  // Combine diffuse and specular contributions and
  // output final vertex color.
  OUT.color.rgb = lighting.y * diffuseMaterial + lighting.z * specularMaterial;
  OUT.color.a = 1.0;
  return OUT;  
}

In the Cg tutorial the chain of spaces are defined in the following way: Object/modelSpc -> WorldSpc -> Eye/ViewSpc -> ClipSpc -> WindowSpc. But in the second statement in the above vertexprogram the normal is transformed into EyeSpc using the "inverse" modelView matrix ModelViewIT. But does ModelViewIT not transform FROM EyeSpc TO ObjectSpc and not the other way around??

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!