Graphics Reference
In-Depth Information
Bathroom Glass
We can combine noise with bump-mapping and cube map refractions to simu-
late the effect of “bathroom glass”; that is, glass that has a wobbly enough
surface that you can't exactly discern the detail of what is on the other side
of it. To do this, we are going to use a single quad as our input geometry.
Remember that one of the beauties of bump-mapping is that you can use fairly
coarse geometry but make it look quite detailed because the computations
take place per-pixel.
Here is the fragment shader. Because the input geometry is a single quad
in the XY -plane, each fragment starts out with a normal vector of (0,0,1). That
normal vector is going to be perturbed twice, by rotating it around X and then
around Y . That's the purpose of the RotateNormal( ) function. The angles to
rotate about are generated by calling the noise function twice, using the frag-
ment's model coordinates as an index.
uniform samplerCube uTexUnit;
uniform float uNoiseAmp;
uniform float uNoiseFreq;
uniform sampler3D Noise3;
in vec3 vMCpos;
in vec3 vECpos;
out vec4 fFragColor;
const float ETA = 1.4;// index of refraction
const vec4 WHITE = vec4( 1.,1.,1.,1. );
vec3
RotateNormal( float angx, float angy, vec3 n )
{
float cx = cos( angx );
float sx = sin( angx );
float cy = cos( angy );
float sy = sin( angy );
// rotate about x:
float yp = n.y*cx - n.z*sx; // y'
n.z = n.y*sx + n.z*cx; // z'
n.y = yp;
// rotate about y:
float xp = n.x*cy + n.z*sy; // x'
n.z = -n.x*sy + n.z*cy; // z'
Search WWH ::




Custom Search