The Cg Programming Language
by John Ratcliff

Example 1
(a)
O.HPOS = mul(objviewproj_matrix, I.position);

(b)
dp4 r0.x, c3, v0
dp4 r0.y, c4, v0
dp4 r0.z, c5, v0
dp4 r0.w, c6, v0
mov oPos, r0

Example 2:

float4 shadow    = tex2D(ShadowMap);
float4 spotlight = tex2D(SpotLight);
float4 lighting  = IN.Color0;
OUT.COL = spotlight * shadow * lighting;


Example 3: 
mVertexShader = CreateVertexShader("simple.cg",VBF_FORMAT0,(unsigned int)
m_pd3dDevice );  // create a shader using this vertex format and this 3d device.

mVertexShader->ActivateBindings(this,0,0); // apply all dynamically bound data items.
mVertexShader->Activate(); // activate this shader program on the hardware

ReleaseVertexShader(mVertexShader); // release shader when we are done with it.

Example 4:

bool CMyD3DApplication::ValidateVertexBindingType(VertexBindingType type)
{
  bool ret = false;
  switch ( type )
  {
    case VBT_WORLDVIEWPROJ:
      ret = true;
      break;
  }
  return ret;
}
void * CMyD3DApplication::GetVertexBindingType(VertexBindingType type,
// keyword we need the results for
      void *context1,
// up to 2 contexts for this shader
      void *context2)          
//
{
  void * ret = 0;
  switch ( type )
  {
    case VBT_WORLDVIEWPROJ:
      if ( 1 )
      {
        static D3DXMATRIX mat;
        D3DXMatrixMultiply( &mat, &m_matView, &m_matProj );
        D3DXMatrixTranspose( &mat, &mat );
        ret = &mat;
      }
      break;
  return ret;
}




2


