Transforms in vertex program?

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

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 on other sites
Yes, that's how normals are transformed.

http://www.geocities.com/vmelkon/transformingnormals.html

Note that most of the time, the inverse transpose of the M, is the same as the M.
More specifically, the upper 3x3 matrix is the same.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633700
• Total Posts
3013426
×