Simple Vertex Program

Hi,

Can anyone paste or give me an URL to a simple vertex program that does the vertex calculation that OpenGL do per vertex.

Regards, Ninja

Do you want an nvidia (NV_vertex_program), ati (EXT_vertex_shader), or ARB_vertex_program example? I think your best bet would be to look at the ARB_vertex_program extension since both nvidia and ati support it. Here is a simple example:

!!ARBvp1.0
ATTRIB vPos = vertex.position;
ATTRIB vCol = vertex.color;
ATTRIB vTex0 = vertex.texcoord;
PARAM mvp[4] = {state.matrix.mvp};
OUTPUT oPos = result.position;
OUTPUT oCol = result.color;
OUTPUT oTex0 = result.texcoord;

#Transform vertex by modelview-proj
DP4 oPos.x, mvp[0], vPos;
DP4 oPos.y, mvp[1], vPos;
DP4 oPos.z, mvp[2], vPos;
DP4 oPos.w, mvp[3], vPos;

MOV oCol, vCol;
MOV oTex0, vTex0;

END

EDIT: added tex coord move.

-SirKnight

[This message has been edited by SirKnight (edited 11-14-2002).]

Ok, thanks.
But I want the code for the Blinn equation in OpenGL per vertex.

//Ninja

Grab this presentation http://developer.nvidia.com/view.asp?IO=fixed_function_pipeline

It has vertex program equivalents for most of the standard fixed-function transform & lighting pipeline stage.

Should have said that in the first place.

Anyway here is the ARB vertex program code that mimics opengl’s fixed function lighting code.

!!ARBvp1.0
ATTRIB iPos = vertex.position;
ATTRIB iNormal = vertex.normal;
PARAM mvinv[4] = { state.matrix.modelview.invtrans };
PARAM mvp[4] = { state.matrix.mvp };
PARAM lightDir = state.light[0].position;
PARAM halfDir = state.light[0].half;
PARAM specExp = state.material.shininess;
PARAM ambientCol = state.lightprod[0].ambient;
PARAM diffuseCol = state.lightprod[0].diffuse;
PARAM specularCol = state.lightprod[0].specular;
TEMP xfNormal, temp, dots;
OUTPUT oPos = result.position;
OUTPUT oColor = result.color;

    # Transform the vertex to clip coordinates.   
    DP4   oPos.x, mvp[0], iPos;
    DP4   oPos.y, mvp[1], iPos;
    DP4   oPos.z, mvp[2], iPos;
    DP4   oPos.w, mvp[3], iPos;

    # Transform the normal to eye coordinates.
    DP3   xfNormal.x, mvinv[0], iNormal;
    DP3   xfNormal.y, mvinv[1], iNormal;
    DP3   xfNormal.z, mvinv[2], iNormal;
    
    # Compute diffuse and specular dot products and use LIT to compute
    # lighting coefficients.
    DP3   dots.x, xfNormal, lightDir;
    DP3   dots.y, xfNormal, halfDir;
    MOV   dots.w, specExp.x;
    LIT   dots, dots;

    # Accumulate color contributions.
    MAD   temp, dots.y, diffuseCol, ambientCol;
    MAD   oColor.xyz, dots.z, specularCol, temp;
    MOV   oColor.w, difuseCol.w;
    END

-SirKnight

Are you sure this is the right program ? Where is the emissive component ?

…and this is for a single directional light.

I haven’t read the arb_vp spec, but it looks like you can use the opengl light and material parameters in the VP directly - this is very tidy…like it, like it a lot.
How do you tell if a particular opengl light is enabled/disabled in the vertex program? Can you have conditional statements?

knacky, it’s even more cool in an ARB_fragment_program using glLight’s directly there in to… replace the fixed function by… uhm… a bether one