Graphics Reference
In-Depth Information
uniform float uUpDown, uLeftRight, uInOut;
uniform float uMix, uRadius;
uniform sampler2D uImageUnit, uGloryUnit;
in vec2 vST;
out vec4 fFragColor;
const float THEANGLE = 160.; // cutoff angle for our
// look-up texture
const vec4 LIGHTPOS = vec4( 0., 0., 40000., 1. );
void main( )
{
//Simulate directional light
//Get texture coordinates of fragment and convert to [-50, 50]
vec3 irgb = texture( uImageUnit, vST ).rgb;
vec2 xy = 100. * vST - 50.;
//Compute angle from the light direction
vec3 EyePos = vec3(xy.x + uLeftRight, xy.y + uUpDown,
uInOut);
float dist = length( LIGHTPOS.xy - EyePos.xy );
float rAngle = atan( dist, uInOut ); // angle to point in
// radians
// the angle is measured from the direction to the sun; this
// is 180 degrees at the contrasolar point and we avoid 180
float angle = 180. - degrees( rAngle );
if( angle < THEANGLE )
angle = THEANGLE;
float v = ( 180. - angle )/( 180. - THEANGLE );
if (v > .99)
v = .99; // avoiding 180
//get the glory texture color
vec2 Gloryst = vec2(v, uRadius);
vec3 Gloryrgb = texture( uGloryUnit, Gloryst ).rgb;
//mix the glory and background colors
vec3 colorOut = uMix * irgb + (1. - uMix) * Gloryrgb;
fFragColor = vec4( colorOut, 1 );
}
Search WWH ::




Custom Search