root/OpenSceneGraph-Data/tags/OpenSceneGraph-Data-2.0/glsl_mandelbrot.osg

Revision 6871 (checked in by robert, 2 years ago)

Checked in first cut of new SVN for OpenSceneGraph-Data

Line 
1 Geode {
2   UniqueID Geode_0
3   DataVariance DYNAMIC
4   nodeMask 0xffffffff
5   cullingActive TRUE
6   StateSet {
7     DataVariance STATIC
8     rendering_hint DEFAULT_BIN
9     renderBinMode INHERIT
10     Uniform {
11       DataVariance DYNAMIC
12       name "DiffuseContribution"
13       float 0.8
14     }
15     Uniform {
16       DataVariance DYNAMIC
17       name "InnerColor"
18       vec3 0 0 0
19     }
20     Uniform {
21       DataVariance DYNAMIC
22       name "LightPosition"
23       vec3 0 0 1
24     }
25     Uniform {
26       DataVariance DYNAMIC
27       name "MaxIterations"
28       float 100
29     }
30     Uniform {
31       DataVariance DYNAMIC
32       name "OuterColor1"
33       vec3 1 1 0
34     }
35     Uniform {
36       DataVariance DYNAMIC
37       name "OuterColor2"
38       vec3 0 0 1
39     }
40     Uniform {
41       DataVariance DYNAMIC
42       name "Shininess"
43       float 0.3
44     }
45     Uniform {
46       DataVariance DYNAMIC
47       name "SpecularContribution"
48       float 0.2
49     }
50     Uniform {
51       DataVariance DYNAMIC
52       name "Xcenter"
53       float -0.5
54     }
55     Uniform {
56       DataVariance DYNAMIC
57       name "Ycenter"
58       float 0
59     }
60     Uniform {
61       DataVariance DYNAMIC
62       name "Zoom"
63       float 0.6
64     }
65     Program {
66       DataVariance STATIC
67       num_shaders 2
68       Shader {
69         DataVariance DYNAMIC
70         type VERTEX
71         code {
72           "//
73 "
74           "// Vertex shader for drawing the Mandelbrot set
75 "
76           "//
77 "
78           "// Authors: Dave Baldwin, Steve Koren, Randi Rost
79 "
80           "//          based on a shader by Michael Rivero
81 "
82           "//
83 "
84           "// Copyright (c) 2002-2004: 3Dlabs, Inc.
85 "
86           "//
87 "
88           "// See 3Dlabs-License.txt for license information
89 "
90           "//
91 "
92           "
93 "
94           "uniform vec3 LightPosition;
95 "
96           "uniform float SpecularContribution;
97 "
98           "uniform float DiffuseContribution;
99 "
100           "uniform float Shininess;
101 "
102           "
103 "
104           "varying float LightIntensity;
105 "
106           "varying vec3  Position;
107 "
108           "
109 "
110           "void main(void)
111 "
112           "{
113 "
114           "    vec3 ecPosition = vec3 (gl_ModelViewMatrix * gl_Vertex);
115 "
116           "    vec3 tnorm      = normalize(gl_NormalMatrix * gl_Normal);
117 "
118           "    vec3 lightVec   = normalize(LightPosition - ecPosition);
119 "
120           "    vec3 reflectVec = reflect(-lightVec, tnorm);
121 "
122           "    vec3 viewVec    = normalize(-ecPosition);
123 "
124           "    float spec      = max(dot(reflectVec, viewVec), 0.0);
125 "
126           "    spec            = pow(spec, Shininess);
127 "
128           "    LightIntensity  = DiffuseContribution *
129 "
130           "                          max(dot(lightVec, tnorm), 0.0) +
131 "
132           "                          SpecularContribution * spec;
133 "
134           "    Position        = vec3(gl_MultiTexCoord0 - 0.5) * 5.0;
135 "
136           "    gl_Position     = ftransform();
137 "
138           "
139 "
140           "}"
141         }
142       }
143       Shader {
144         DataVariance DYNAMIC
145         type FRAGMENT
146         code {
147           "//
148 "
149           "// Fragment shader for drawing the Mandelbrot set
150 "
151           "//
152 "
153           "// Authors: Dave Baldwin, Steve Koren, Randi Rost
154 "
155           "//          based on a shader by Michael Rivero
156 "
157           "//
158 "
159           "// Copyright (c) 2002-2004: 3Dlabs, Inc.
160 "
161           "//
162 "
163           "// See 3Dlabs-License.txt for license information
164 "
165           "//
166 "
167           "
168 "
169           "varying vec3  Position;
170 "
171           "varying float LightIntensity;
172 "
173           "
174 "
175           "uniform float MaxIterations;
176 "
177           "uniform float Zoom;
178 "
179           "uniform float Xcenter;
180 "
181           "uniform float Ycenter;
182 "
183           "uniform vec3  InnerColor;
184 "
185           "uniform vec3  OuterColor1;
186 "
187           "uniform vec3  OuterColor2;
188 "
189           "
190 "
191           "void main(void)
192 "
193           "{
194 "
195           "    float   real  = Position.x * Zoom + Xcenter;
196 "
197           "    float   imag  = Position.y * Zoom + Ycenter;
198 "
199           "    float   Creal = real;   // Change this line...
200 "
201           "    float   Cimag = imag;   // ...and this one to get a Julia set
202 "
203           "
204 "
205           "    float r2 = 0.0;
206 "
207           "    float iter;
208 "
209           "
210 "
211           "    for (iter = 0.0; iter < MaxIterations && r2 < 4.0; ++iter)
212 "
213           "    {
214 "
215           "        float tempreal = real;
216 "
217           "
218 "
219           "        real = (tempreal * tempreal) - (imag * imag) + Creal;
220 "
221           "        imag = 2.0 * tempreal * imag + Cimag;
222 "
223           "        r2   = (real * real) + (imag * imag);
224 "
225           "    }
226 "
227           "
228 "
229           "    // Base the color on the number of iterations
230 "
231           "
232 "
233           "    vec3 color;
234 "
235           "
236 "
237           "    if (r2 < 4.0)
238 "
239           "        color = InnerColor;
240 "
241           "    else
242 "
243           "        color = mix(OuterColor1, OuterColor2, fract(iter * 0.05));
244 "
245           "
246 "
247           "    color *= LightIntensity;
248 "
249           "
250 "
251           "    gl_FragColor = vec4 (color, 1.0);
252 "
253           "}"
254         }
255       }
256     }
257   }
258   num_drawables 1
259   Geometry {
260     DataVariance DYNAMIC
261     useDisplayList TRUE
262     useVertexBufferObjects FALSE
263     PrimitiveSets 1
264     {
265       DrawArrays QUADS 0 4
266     }
267     VertexArray Vec3Array 4
268     {
269       0 0 1
270       0 0 0
271       1 0 0
272       1 0 1
273     }
274     NormalBinding OVERALL
275     NormalArray Vec3Array 1
276     {
277       0 -1 0
278     }
279     ColorBinding OVERALL
280     ColorArray Vec4Array 1
281     {
282       1 1 1 1
283     }
284     TexCoordArray 0 Vec2Array 4
285     {
286       0 1
287       0 0
288       1 0
289       1 1
290     }
291   }
292 }
Note: See TracBrowser for help on using the browser.