gallium: add target-helpers/wrap_screen.c to C_SOURCES
[mesa/mesa-lb.git] / progs / glsl / CH11-toyball.frag
blob90ec1c27fc1824b8ad310df232da1e0eeccd44ae
1 //
2 // Fragment shader for procedurally generated toy ball
3 //
4 // Author: Bill Licea-Kane
5 //
6 // Copyright (c) 2002-2003 ATI Research 
7 //
8 // See ATI-License.txt for license information
9 //
11 varying vec4 ECposition;   // surface position in eye coordinates
12 varying vec4 ECballCenter; // ball center in eye coordinates
14 uniform vec4  LightDir;     // light direction, should be normalized
15 uniform vec4  HVector;      // reflection vector for infinite light source
16 uniform vec4  SpecularColor;
17 uniform vec4  Red, Yellow, Blue;
19 uniform vec4  HalfSpace0;   // half-spaces used to define star pattern
20 uniform vec4  HalfSpace1;
21 uniform vec4  HalfSpace2;
22 uniform vec4  HalfSpace3;
23 uniform vec4  HalfSpace4;
25 uniform float InOrOutInit;  // = -3
26 uniform float StripeWidth;  // = 0.3
27 uniform float FWidth;       // = 0.005
29 void main()
31     vec4  normal;              // Analytically computed normal
32     vec4  p;                   // Point in shader space
33     vec4  surfColor;           // Computed color of the surface
34     float intensity;           // Computed light intensity
35     vec4  distance;            // Computed distance values
36     float inorout;             // Counter for computing star pattern
38     p.xyz = normalize(ECposition.xyz - ECballCenter.xyz);    // Calculate p
39     p.w   = 1.0;
41     inorout = InOrOutInit;     // initialize inorout to -3
43     distance[0] = dot(p, HalfSpace0);
44     distance[1] = dot(p, HalfSpace1);
45     distance[2] = dot(p, HalfSpace2);
46     distance[3] = dot(p, HalfSpace3);
48     distance = smoothstep(-FWidth, FWidth, distance);
49     inorout += dot(distance, vec4(1.0));
51     distance.x = dot(p, HalfSpace4);
52     distance.y = StripeWidth - abs(p.z);
53     distance = smoothstep(-FWidth, FWidth, distance);
54     inorout += distance.x;
56     inorout = clamp(inorout, 0.0, 1.0);
58     surfColor = mix(Yellow, Red, inorout);
59     surfColor = mix(surfColor, Blue, distance.y);
61     // normal = point on surface for sphere at (0,0,0)
62     normal = p;
64     // Per fragment diffuse lighting
65     intensity  = 0.2; // ambient
66     intensity += 0.8 * clamp(dot(LightDir, normal), 0.0, 1.0);
67     surfColor *= intensity;
69     // Per fragment specular lighting
70     intensity  = clamp(dot(HVector, normal), 0.0, 1.0);
71     intensity  = pow(intensity, SpecularColor.a);
72     surfColor += SpecularColor * intensity;
74     gl_FragColor = surfColor;