Game Development Reference
In-Depth Information
The final color of the vertex, including colors contributed from spotlights, is sent to the fragment
shader by the Color variable.
varying vec3 Color;
The function IntensityCircle() returns an intensity value from 0 to 1 that is most intense in the
center of the circle and 0 when Radius = MaxRadius. (See Listing 5-34.)
Listing 5-34. The Intensity Circle for the Spotlights
float IntensityCircle(float Radius, float MaxRadius)
{
float retval;
retval = 1.0 - (Radius/MaxRadius);
return retval;
}
Main() Function of Shader
In the main() function of the shader, where the actual shader code starts to execute, we first create a
NewPos vector variable, to hold the incoming vertex locations.
vec3 NewPos;
NewPos = aPosition;
The part of the shader code shown in Listing 5-35 is the main loop that processes all the objects
on the grid and determines the net force acting on the current grid vertex by all the objects on the
grid. It also determines the final color of the vertex, based on the original color and the total of the
spotlight colors from the objects.
The code in Listing 5-35 does the following:
Sets a maximum force through the ForceMax variable
1.
2.
Initializes the cumulative spotlight color from all the objects on the grid to
black (0,0,0)
3.
Initializes the cumulative spotlight color for each of the active objects on the
grid ( Mass > 0 )
4.
Calculates the direction to the object from the vertex
5.
Calculates the distance from the object to the vertex
6.
Calculates the gravitational force attraction, using the formula Force =
(MassValues[i] * (2.0)) / (R * R) , which roughly approximates Newton's
law of gravity, where both objects' masses are the same and the gravitational
constant is 1
Uses the IntensityCircle function to determine the vertex's spotlight color
for that object, if the distance to the object from the vertex is within the
object's spotlight distance
7.
 
Search WWH ::




Custom Search