Graphics Reference
In-Depth Information
// Initial input is a complex number (real, imag)
// Set x = real and y = imag
Iterate until we reach a max # of iterations or x*x+y*y >= some
limit
{
float newx = x*x - y*y + r;
float newy = 2.*x*y + c;
x = newx; y = newy;
}
if x*x+y*y < some limit // the process has converged
color the fragment blue
else
color the fragment based on the number of iterations
You see this implemented in the fragment shader code below. In this
code, you see two variables that are set by the vertex shader; one provides the
2D texture coordinates from the graphics primitive's surface, and the other is
the light intensity, so that diffuse lighting can be used. The 2D texture coordi-
nates are used as the real and imaginary parts of the complex number above,
and are adjusted to get the texture centered and sized correctly for effect. In
the vertex shader, the 2D varying variable ST is created by taking the texture
coordinates for the vertices, originally in [0., 1.], and mapping them into the
standard Mandelbrot complex domain [-1., 1.] where they can be interpolated
by the fragment shader. All the uniform variables are set in the GLIB file, and
most are glman slider variables, so you can experiment with the parameters for
the texture.
uniform int uMaxIters;
uniform float uTS; // texture coordinate scaling
uniform float uCS; // color scaling
uniform float uS0; // starting texture value in S
uniform float uT0; // starting texture value in T
uniform float uLimit; // how large before stop iterations
uniform vec3 uConvergeColor;
uniform vec3 uDivergeColor1;
uniform vec3 uDivergeColor2;
in vec2 vST;
in float vLightIntensity;
out vec4 fFragColor;
void main( )
{
Search WWH ::




Custom Search