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