diff options
author | Brian <[email protected]> | 2007-01-15 17:27:24 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2007-01-15 17:27:24 -0700 |
commit | 2ccd26469541ef042bb1aec8ade3dc4736f694cf (patch) | |
tree | 90132405bcf4384d9bfe76e88e18f363b923b674 /progs/glsl/CH18-mandel.frag.txt | |
parent | f6507157e290b783c036e9459886e0f7ae60ef7b (diff) |
Added new directory of GL shading language demos: glsl
Diffstat (limited to 'progs/glsl/CH18-mandel.frag.txt')
-rw-r--r-- | progs/glsl/CH18-mandel.frag.txt | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/progs/glsl/CH18-mandel.frag.txt b/progs/glsl/CH18-mandel.frag.txt new file mode 100644 index 00000000000..3769cffdc8b --- /dev/null +++ b/progs/glsl/CH18-mandel.frag.txt @@ -0,0 +1,55 @@ +// +// Fragment shader for drawing the Mandelbrot set +// +// Authors: Dave Baldwin, Steve Koren, Randi Rost +// based on a shader by Michael Rivero +// +// Copyright (c) 2002-2005: 3Dlabs, Inc. +// +// See 3Dlabs-License.txt for license information +// + +varying vec3 Position; +varying float LightIntensity; + +uniform float MaxIterations; +uniform float Zoom; +uniform float Xcenter; +uniform float Ycenter; +uniform vec3 InnerColor; +uniform vec3 OuterColor1; +uniform vec3 OuterColor2; + +void main() +{ + float real = Position.x * Zoom + Xcenter; + float imag = Position.y * Zoom + Ycenter; + float Creal = real; // Change this line... + float Cimag = imag; // ...and this one to get a Julia set + + float r2 = 0.0; + float iter; + + for (iter = 0.0; iter < MaxIterations && r2 < 4.0; ++iter) +//nv: for (iter = 0.0; iter < 12 && r2 < 4.0; ++iter) + { + float tempreal = real; + + real = (tempreal * tempreal) - (imag * imag) + Creal; + imag = 2.0 * tempreal * imag + Cimag; + r2 = (real * real) + (imag * imag); + } + + // Base the color on the number of iterations + + vec3 color; + + if (r2 < 4.0) + color = InnerColor; + else + color = mix(OuterColor1, OuterColor2, fract(iter * 0.05)); + + color *= LightIntensity; + + gl_FragColor = vec4(color, 1.0); +} |