Graphics Reference
In-Depth Information
produce the polar coordinates ( r , Θ ) of the disk. Thus we have two sets of coor-
dinates and use the uBlend variable to mix between them.
uniform float uBlend;
out vec4 vColor;
out float vLightIntensity;
out vec2 vST;
const float TWOPI = 2.*3.14159265;
const vec3 LIGHTPOS = vec3( 5., 10., 10. );
void main( )
{
// original model coords (sphere):
vec4 vertex0 = aVertex;
vec3 norm0 = aNormal;
// circle coords:
vST = aTexCoord0.st;
float s = aTexCoord0.s;
float t = aTexCoord0.t;
float radius = 1.-t;
float theta = TWOPI*s;
vec4 circle = vec4( radius*cos(theta), radius*sin(theta),
0., 1. );
vec3 circlenorm = vec3( 0., 0., 1. );
// blend:
vec4 theVertex = mix( vertex0, circle, uBlend );
vec3 theNormal = normalize( mix( norm0, circlenorm, uBlend ));
// do the lighting:
vec3 tnorm = normalize( vec3( uNormalMatrix *
theNormal ) );
vec3 ECposition = vec3( uModelViewMatrix * theVertex );
vLightIntensity = abs( dot(normalize(LIGHTPOS -
ECposition),tnorm));
if( vLightIntensity < 0.2 )
vLightIntensity = 0.2;
vColor = aColor;
gl_Position = uModelViewProjectionMatrix * theVertex;
}
Search WWH ::




Custom Search