Graphics Reference
In-Depth Information
uniform float uR1, uR2;
out vec3 vRefractVector;
const float ETA = 0.66; // eta=in/out
void main( )
{
vec3 P = ( uModelViewMatrix * aVertex ).xyz;
vec3 Eye = vec3( 0., 0., 0. ); // just to make it clearer
vec3 FromEyeToPt = normalize( P - Eye ); // vector from eye
to pt
vec3 Center1 = vec3( 0., 0., P.z - uR1 );
vec3 Normal1 = normalize( sign(uR1) * ( P - Center1 ));
vec3 v1 = refract(FromEyeToPt, Normal1, ETA);
v1 = normalize( v1 );
vec3 Center2 = vec3( 0., 0., P.z + uR2 );
vec3 Normal2 = normalize( sign(uR2) * ( Center2 - P ));
vec3 v2 = refract( v1, Normal2, 1./ETA );
vRefractVector = v2;
gl_Position = uModelViewProjectionMatrix * aVertex;
}
The fragment shader, by contrast, is much simpler. It simply computes
the texture from the cube map based on the refraction vector returned by the
vertex shader and blends that with white to get the effect of the lens not pass-
ing along all the light it receives. This also helps to make the lens visible in the
scene.
uniform samplerCube uRefractUnit;
in vec3 vRefractVector;
out vec4 fFragColor;
const vec4 WHITE = vec4( 1.,1.,1.,1. );
void main( ) {
vec4 refractcolor = textureCube( uRefractUnit,
vRefractVector );
fFragColor = mix( refractcolor, WHITE, .3 );
}
Search WWH ::




Custom Search