Sophie

Sophie

distrib > * > cooker > x86_64 > by-pkgid > 0243c8b7bca94179c78b9bd6ac76c033 > files > 643

cg-examples-3.0.0018-0.1.x86_64.rpm

// vertex_texture.cg - simple Cg vertex texturing example

float centerFalloff(float v, float center)
{
  float vv = max(0.0, 1.0-abs(v-center));
  return vv*vv;
}

void displace_mesh(float2 position  : POSITION,

               out float4 oPosition : POSITION,
               out float3 oColor    : COLOR,
                
           uniform float4x4 modelViewProj,
           uniform sampler2D height_field)
{
  const float3 blue = float3(0,0.2,1),
               green = float3(0,1,0),
               white = float3(1,1,1);
  
  float height = tex2D(height_field, position.xy).x;
  float3 displacedPosition = float3(3.5*(2*position-1), height);

  // Compute a color that simulates the coloration of terrain:
  // lowest terrain is blue as if water,
  // middle terrain is green as if folage,
  // highest terrain is white as if snow capped.
  oColor = centerFalloff(height, 0.1) * blue +
           centerFalloff(height, 0.5) * green +
           centerFalloff(height, 0.9) * white;

  oPosition = mul(modelViewProj,
                  float4(displacedPosition, 1));
}