Graphics Reference
In-Depth Information
float v = 0.;
float w = 1.;
float ang = atan(vMCposition.y - C0.y,
vMCposition.x - C0.x );
float u1 = dot( vec2(u,v), vec2(cos(ang), -sin(ang)) );
float v1 = dot( vec2(u,v), vec2(sin(ang), cos(ang)) );
float w1 = 1.;
// second set of ripples:
float rad1 = length( vMCposition - C1 ); // ripple center 1
float H1 = -uAmp1 * cos( TWOPI*rad1/uPd - TWOPI*uTime );
u = -uAmp1*(TWOPI/uPd)*
sin(TWOPI*rad1/uPd-TWOPI*uTime-uPhaseShift);
v = 0.;
ang = atan( vMCposition.y - C1.y, vMCposition.x - C1.x );
float u2 = dot( vec2(u,v), vec2(cos(ang), -sin(ang)) );
float v2 = dot( vec2(u,v), vec2(sin(ang), cos(ang)) );
float w2 = 1.;
// the sum is the normal:
vec3 normal = normalize( vec3( u1+u2, v1+v2, w1+w2 ) );
float LightIntensity =
abs(dot(normalize(vec3(uLightX,uLightY,uLightZ)-
vECposition),normal));
if( LightIntensity < 0.1 )
LightIntensity = 0.1;
fFragColor = vec4( LightIntensity*uColor.rgb, uColor.a );
}
And, of course, there is the usual comment about the efficiency thing. The
lines
float ang = atan( vMCposition.y - C0.y, vMCposition.x - C0.x );
float up = dot( vec2(u,v), vec2(cos(ang), -sin(ang)) );
float vp = dot( vec2(u,v), vec2(sin(ang), cos(ang)) );
were writen for clarity, but could have been writen more eiciently by just
using x and y components for the trigonometric functions:
vec2 d = vMCposition.xy - C0.xy;
vec2 cossin = normalize( d );
Search WWH ::




Custom Search