Graphics Reference
In-Depth Information
The fragment shader code for this simulation is given below, and it uses a
number of uniform variables that come from glib sliders. These let you “tune”
the rainbow to match real conditions, since the critical angles from the con-
trasolar point are not available in the plain photograph. These variables have
been tuned to get the computed rainbow to align fairly well with the actual
photograph, as shown, but the tuned values are not included here. See the
exercises for more on tuning.
uniform float uUpDown, uLeftRight, uInOut;
uniform float uALF, uWhere;
uniform sampler2D uImageUnit, uRainbowUnit;
in vec2 vST;
out vec4 fFragColor;
const float PI = 3.14159265;
const float outAngle = 41.
const float inAngle = 39.
const vec4 LIGHTPOS = vec4( 0., 0., 40000., 1. );
void
main( )
{
//simulate directional light
//set up eye and texture coordinates
vec3 irgb = texture( uImageUnit, vST ).rgb;
vec4 irgba = vec4(irgb, 0.5);
vec2 xy = 100. * vST - 50.;
// set initial eyepoint to [-50, 50]
vec3 EyePos = vec3(xy.x + uLeftRight, xy.y + uUpDown, uInOut);
// Compute angles
float num = length( EyePos.xy - LIGHTPOS.xy );
float rAngle = atan( num, uInOut ); // angle in radians
float angle = degrees( rAngle ); // angle in degrees
float myAngle = angle;
//Convert myAngle to rainbow range
if ( angle > outAngle )
{
myAngle = outAngle;
}
if ( angle < inAngle )
{
myAngle = inAngle;
Search WWH ::




Custom Search