Skip to main content
GameDev.net gamedev.net
🔒 Locked

Input for a Vertex program?

Started by mlt Nov 7, 2008 at 8:09 AM 4 replies 650+ views
Original Post
mlt
mlt
I am currently trying to use the vertex program from the Cg Toolkit it looks something like this:

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

struct vertex_output
{
  // Homogeneous 'clip-space' coordinates.	
  float4 position : POSITION;
  float4 color    : COLOR;
};

vertex_output main(
                     vertex_input IN
                   , uniform float4x4 ModelViewProj ///< Concatenation of the modelview and projection matrices
                   , uniform float4x4 ModelViewIT   ///< The inverse transpose of the modelview matrix.
                   , uniform float4   light_vector	///< Specification of light location.
             )
{
  vertex_output OUT;
  
  OUT.position = mul(ModelViewIT, IN.position);
  
...
...

In another file its loaded and enabled:

m_vertex_program.load_from_file(vertex_program,demo_path + "vp_lighting.cg");
m_vertex_program.set_modelview_matrix();
m_vertex_program.set_modelview_projection_matrix();
m_vertex_program.set_modelview_inverse_transpose();
m_vertex_program.set_float_param("light_vec",light_vec_x,light_vec_y,light_vec_z);

But I don't understand how the struct "vertex_input" to the vertex program is passed. In the main program in the vertex program the parameter IN should be passed from somewhere right?
V-man
V-man
When you render something, it automatically goes into that struct thing.
Of course, in reality, what happens is that when the program is compiled, a special binary gets generated.
float4 position : POSITION and float4 normal : NORMAL are basically input streams.
mlt
mlt
Ok so there is no way to manually specify arguments to the entry function in a vertex program? They just get passed magically?
swiftcoder
swiftcoder
Quote:
Original post by mlt
Ok so there is no way to manually specify arguments to the entry function in a vertex program? They just get passed magically?
There is nothing magic about it:
struct vertex_input{  float4 position : POSITION;  float4 normal   : NORMAL;};
Here float4 position is bound to the position attribute of each vertex (i.e. the value submitted using glVertex or glVertexPointer), and float4 normal is bound to the normal attribute (glNormal or glNormalPointer).
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
mlt
mlt
Is it possible to give an example of how the vertex program is called, supplying all the parameters (including the vertex_in struct)?
swiftcoder
swiftcoder
Quote:
Original post by mlt
Is it possible to give an example of how the vertex program is called, supplying all the parameters (including the vertex_in struct)?
I think you need to read up on how shaders work. A shader is not 'called', instead it is bound. In psuedo code it would look something like this:
bind_shader( my_shader )glBegin(GL_TRIANGLES);glVertex3f(..)glNormal3f(...)......glEnd();unbind_shader( my_shader )


Now, as long as the shader in bound, it will be executed once for every vertex you specify (using glVertex, glNormal), and each time, the vertex_in struct will be filled out with the current vertex position and normal vector.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.