Graphics Reference
In-Depth Information
float v12 = 2. * dot( p2-p1, n1+n2 ) / dot( p2-p1, p2-p1 );
float v23 = 2. * dot( p3-p2, n2+n3 ) / dot( p3-p2, p3-p2 );
float v31 = 2. * dot( p1-p3, n3+n1 ) / dot( p1-p3, p1-p3 );
vec3 n200 = n1;
vec3 n020 = n2;
vec3 n002 = n3;
vec3 n110 = normalize( n1 + n2 - v12*(p2-p1) );
vec3 n011 = normalize( n2 + n3 - v23*(p3-p2) );
vec3 n101 = normalize( n3 + n1 - v31*(p1-p3) );
teNormal = n200*w*w + n020*u*u + n002*v*v +
n110*w*u + n011*u*v + n101*w*v;
gl_Position = vec4( xyz, 1. );
}
Following the TES shader is the geometry shader, which takes a triangle
as input and computes the light intensity and position for each vertex of the
output triangle.
#version 400 compatibility
#extension GL_EXT_gpu_shader4: enable
#extension GL_EXT_geometry_shader4: enable
layout( triangles ) in;
layout( triangle_strip, max_vertices=32 ) out;
uniform float uShrink;
in vec3 teNormal[ ];
out float gLightIntensity;
const vec3 LIGHTPOS = vec3( 5., 10., 10. );
vec3 V[3];
vec3 CG;
void
ProduceVertex( int v )
{
gLightIntensity =
abs(dot(normalize(LIGHTPOS - V[v]),
normalize(teNormal[v])));
gl_Position = uProjectionMatrix *
vec4( CG + uShrink * ( V[v] - CG ), 1. );
EmitVertex( );
}
void
main( )
Search WWH ::




Custom Search