Graphics Reference
In-Depth Information
n.x = xp;
return normalize( n );
}
void main( )
{
vec3 eye = vec3( 0., 0., 0. );
vec3 eyeToPt = normalize( vECpos - eye );
vec4 nvx = texture( Noise3, uNoiseFreq*vMCpos );
vec4 nvy = texture( Noise3,
uNoiseFreq*vec3(vMCpos.xy,vMCpos.z+0.5) );
float angx = nvx.r + nvx.g + nvx.b + nvx.a; // 1. -> 3.
angx = angx - 2.; // -1. -> 1.
angx *= uNoiseAmp;
float angy = nvy.r + nvy.g + nvy.b + nvy.a; // 1. -> 3.
angy = angy - 2.; // -1. -> 1.
angy *= uNoiseAmp;
vec3 N = vec3( 0., 0., 1. ); // unperturbed normal
N = RotateNormal( angx, angy, N );
N = normalize( uNormalMatrix * N );
// force the normal to point towards us:
if( N.z < 0. )
N = -N;
vec3 reflectVector = reflect( eyeToPt, N );
vec4 reflectColor = textureCube( uTexUnit, reflectVector );
vec3 refractVector = refract( eyeToPt, N, ETA );
vec4 refractColor = textureCube( uTexUnit, refractVector );
refractColor = mix( refractColor, WHITE, .3 );
if( all( equal( refractVector, vec3(0.,0.,0.) ) ))
refractColor = reflectColor;
fFragColor = mix( refractColor, reflectColor, uMix );
}
It is possible that the refract( ) function will fail and will tell us that
it failed by returning the vector (0,0,0). Why could it fail? Like real refraction,
it is possible that the angles will become such that, instead of refraction, you
get internal reflection. You can detect this in Snell's law of refraction by being
forced to take an arcsin of a value greater than 1. or less than −1. You can see
Search WWH ::




Custom Search