next up previous contents index
Next: Fragment Program for Clipped Up: Vertex and Fragment Programs Previous: Vertex and Fragment Programs   Contents   Index


Clipped Tetrahedron Projection Vertex Program

This listing is a vertex program that is part of the tetrahedra projection with adaptive transfer function sampling. Section 1.3 discusses the algorithm in its entirety.

struct rayseg {
  float4 position       : POSITION;  /* Position of front face. */
  float4 distances      : TEXCOORD0; /* Distance of front face to each
                                        face in direction of view
					vector. */
  float3 isovalues      : TEXCOORD1; /* x and y are Color lookups for
                                        scalar values of where tetrahedra
                                        (ray segment) is clipped.  x value
                                        is closer to viewer.  z is the
                                        distance between the two isoplanes
                                        in the view direction. */
  float frontinterp     : TEXCOORD2; /* Interpolates the color of the
                                        front face from the front isovalue
					to the back. */
  float4 backinterp     : TEXCOORD3; /* Interpolates the color of each
                                        face from the back isovalue to the
                                        front. */
};

float4 selectmask[4] = {
  {1, 0, 0, 0},
  {0, 1, 0, 0},
  {0, 0, 1, 0},
  {0, 0, 0, 1}
};
float4 invselectmask[4] = {
  {0, 1, 1, 1},
  {1, 0, 1, 1},
  {1, 1, 0, 1},
  {1, 1, 1, 0}
};

rayseg mainvert(float4 position,        /* Position of the vertex. */
                float distance,         /* Distance from the vertex to the
                                           to opposite face in the view
                                           direction (negative if opposite
                                           face is closer to viewpoint).*/
                float2 isovalues,       /* Texture lookup indices for
                                           clipping isovalues.  The x
					   index is closer to the
					   viewpoint. */
                float2 interpolants,    /* Used to interpolate the actual
                                           colors of the front and back
                                           scalars. */
                float vertNum,
                uniform float4x4 ModelViewProj)
{
  rayseg output;

  output.position = mul(ModelViewProj, position);

  output.distances = selectmask[vertNum]*distance;

  output.frontinterp = interpolants.x;

  /* Note that we invert the interpolation so that the back scalar is
     interpolated from the back isoplane to the front isoplane. */
  output.backinterp = 1 - (  invselectmask[vertNum]*interpolants.x
                           + selectmask[vertNum]*interpolants.y );

  output.isovalues.xy = isovalues;
  /* Compute distance between isoplanes. */
  if (interpolants.x != interpolants.y)
    {
    output.isovalues.z = distance/(interpolants.y-interpolants.x);
    }
  else
    {
    /* Special case when front and back scalars are equal: distance
       between planes does not matter. */
    output.isovalues.z = 1.0e30;
    }

  return output;
}



Kenneth D Moreland 2004-07-16