Vertex program : POSITION

Started by
4 comments, last by idinev 15 years, 4 months ago
The input struct to a vertex program often look like this:

struct vertex_input
{
  float4 position : POSITION; 
  float4 normal   : NORMAL; 
};

But I have also stumbled across vertex programs where 'position' is just a float3 vector. If we assume that the data from the application does not change but we only change the position from float4 to float3 then what happens? I am pretty sure that the data from the application only contains 3 elements per vertex so I also wonder why position is sometimes defined as a float4.
Advertisement
Quote:But I have also stumbled across vertex programs where 'position' is just a float3 vector. If we assume that the data from the application does not change but we only change the position from float4 to float3 then what happens?


It depends on what you are doing in the shader.
I'm guessing the vertex gets multiplied by a 4x4 matrix so if you make the vertex into a float3, then multiplying no longer becomes possible.
The Cg compiler would spit out some error message.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
But if position from the application is only a float3 vector what happens if the position in the vertex program is a float4 vector?
afaik, if the VBO's vertex-pos data was specified via glVertexPointer, the .w=1.0f , but if you specify the vertex-pos via glVertexAttribPointer, w=0.
Ok is there anyway to print out the elements in the position vector?
From the shader? If so, then draw into a RGBA32f FBO, then glReadPixels. I usually do MRT (drawing to 4 textures at once) while debugging stuff like that.

This topic is closed to new replies.

Advertisement