root/OpenSceneGraph-Data/tags/OpenSceneGraph-Data-2.6.0/glsl_simple.osg

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

Added shader.vert and fixed path

Line 
1 Group {
2   UniqueID Group_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 "Color1"
13       vec3 0.5 1 1
14     }
15     Uniform {
16       DataVariance DYNAMIC
17       name "Color2"
18       vec3 1 0.5 0
19     }
20     Uniform {
21       DataVariance DYNAMIC
22       name "Sine"
23       float 0.1
24     }
25   }
26   UpdateCallbacks {
27     NodeCallback {
28       DataVariance DYNAMIC
29     }
30   }
31   num_children 2
32   PositionAttitudeTransform {
33     DataVariance DYNAMIC
34     nodeMask 0xffffffff
35     cullingActive TRUE
36     StateSet {
37       DataVariance STATIC
38       rendering_hint DEFAULT_BIN
39       renderBinMode INHERIT
40       Program {
41         UniqueID Program_1
42         DataVariance STATIC
43         num_shaders 2
44         Shader {
45           DataVariance DYNAMIC
46           type VERTEX
47           file shaders/shader.vert
48         }
49         Shader {
50           DataVariance DYNAMIC
51           type FRAGMENT
52           code {
53             "varying vec4 color;void main(void){gl_FragColor = clamp( color, 0.0, 1.0 );}"
54           }
55         }
56       }
57     }
58     referenceFrame RELATIVE
59     position 0 -1 0
60     attitude 0 0 0 1
61     scale 1 1 1
62     pivotPoint 0 0 0
63     num_children 1
64     Geode {
65       UniqueID Geode_2
66       DataVariance DYNAMIC
67       nodeMask 0xffffffff
68       cullingActive TRUE
69       num_drawables 3
70       ShapeDrawable {
71         DataVariance DYNAMIC
72         StateSet {
73           DataVariance STATIC
74           rendering_hint DEFAULT_BIN
75           renderBinMode INHERIT
76           Uniform {
77             DataVariance DYNAMIC
78             name "Color1"
79             vec3 0.2 0.8 1.0
80           }
81         }
82         Sphere {
83           DataVariance DYNAMIC
84           Center 0 0 0
85           Radius 1
86         }
87         useDisplayList TRUE
88         useVertexBufferObjects FALSE
89         color 1 1 1 1
90       }
91       ShapeDrawable {
92         DataVariance DYNAMIC
93         StateSet {
94           DataVariance STATIC
95           rendering_hint DEFAULT_BIN
96           renderBinMode INHERIT
97           Uniform {
98             DataVariance DYNAMIC
99             name "Color1"
100             vec3 0.9 0.2 0.2
101           }
102         }
103         Cone {
104           DataVariance DYNAMIC
105           Center 2.2 0 -0.4
106           Radius 0.9
107           Height 1.8
108           Rotation 0 0 0 1
109         }
110         useDisplayList TRUE
111         useVertexBufferObjects FALSE
112         color 1 1 1 1
113       }
114       ShapeDrawable {
115         DataVariance DYNAMIC
116         StateSet {
117           DataVariance STATIC
118           rendering_hint DEFAULT_BIN
119           renderBinMode INHERIT
120           Uniform {
121             DataVariance DYNAMIC
122             name "Color1"
123             vec3 0.2 0 0.8
124           }
125         }
126         Cylinder {
127           DataVariance DYNAMIC
128           Center 4.4 0 0
129           Radius 1
130           Height 1.4
131           Rotation 0 0 0 1
132         }
133         useDisplayList TRUE
134         useVertexBufferObjects FALSE
135         color 1 1 1 1
136       }
137     }
138   }
139   PositionAttitudeTransform {
140     DataVariance DYNAMIC
141     nodeMask 0xffffffff
142     cullingActive TRUE
143     StateSet {
144       DataVariance STATIC
145       rendering_hint DEFAULT_BIN
146       renderBinMode INHERIT
147       Program {
148         UniqueID Program_3
149         DataVariance STATIC
150         num_shaders 2
151         Shader {
152           DataVariance DYNAMIC
153           type FRAGMENT
154           code {
155             "// blocky.frag - an OGLSL fragment shader with animation"
156             "// Mike Weiblen 2003-09-16 : derived from brick.frag"
157             "// Copyright 2003 3Dlabs Inc."
158             "// see http://www.3dlabs.com/opengl2/ for more OpenGL Shading Language info."
159             ""
160             ""
161             "// the App updates uniforms \"slowly\" (eg once per frame) for animation."
162             "uniform float Sine;"
163             "uniform vec3 Color1;"
164             "uniform vec3 Color2;"
165             ""
166             "// varyings are written by vert shader, interpolated, and read by frag shader."
167             "varying vec2  BlockPosition;"
168             "varying float LightIntensity;"
169             ""
170             "void main(void)"
171             "{"
172             "    vec3 color;"
173             "    float ss, tt, w, h;"
174             "    "
175             "    ss = BlockPosition.x;"
176             "    tt = BlockPosition.y;"
177             ""
178             "    if (fract(tt * 0.5) > 0.5)"
179             "        ss += 0.5;"
180             ""
181             "    ss = fract(ss);"
182             "    tt = fract(tt);"
183             ""
184             "    // animate the proportion of block to mortar"
185             "    float blockFract = (Sine + 1.1) * 0.4;"
186             ""
187             "    w = step(ss, blockFract);"
188             "    h = step(tt, blockFract);"
189             ""
190             "    color = mix(Color2, Color1, w * h) * LightIntensity;"
191             "    gl_FragColor = vec4 (color, 1.0);"
192             "}"
193             ""
194           }
195         }
196         Shader {
197           DataVariance DYNAMIC
198           type VERTEX
199           code {
200             "// blocky.vert - an OGLSL vertex shader with animation"
201             "// Mike Weiblen 2003-09-16 : derived from brick.vert"
202             "// Copyright 2003 3Dlabs Inc."
203             "// see http://www.3dlabs.com/opengl2/ for more OpenGL Shading Language info."
204             ""
205             ""
206             "// the App updates uniforms \"slowly\" (eg once per frame) for animation."
207             "uniform float Sine;"
208             ""
209             "const vec3 LightPosition = vec3(0.0, 0.0, 4.0);"
210             "const float BlockScale = 0.30;"
211             ""
212             "// varyings are written by vert shader, interpolated, and read by frag shader."
213             "varying float LightIntensity;"
214             "varying vec2  BlockPosition;"
215             ""
216             "void main(void)"
217             "{"
218             "    // per-vertex diffuse lighting"
219             "    vec4 ecPosition        = gl_ModelViewMatrix * gl_Vertex;"
220             "    vec3 tnorm             = normalize(gl_NormalMatrix * gl_Normal);"
221             "    vec3 lightVec  = normalize(LightPosition - vec3 (ecPosition));"
222             "    LightIntensity = max(dot(lightVec, tnorm), 0.0); "
223             ""
224             "    // blocks will be determined by fragment's position on the XZ plane."
225             "    BlockPosition = gl_Vertex.xz / BlockScale;"
226             ""
227             "    // scale the geometry based on an animation variable."
228             "    vec4 vertex    = gl_Vertex;"
229             "    vertex.w       = 1.0 + 0.4 * (Sine + 1.0);"
230             ""
231             "    gl_Position    = gl_ModelViewProjectionMatrix * vertex;"
232             "}"
233             ""
234           }
235         }
236       }
237     }
238     referenceFrame RELATIVE
239     position 0 -1 2.2
240     attitude 0 0 0 1
241     scale 1 1 1
242     pivotPoint 0 0 0
243     num_children 1
244     Use Geode_2
245   }
246 }
Note: See TracBrowser for help on using the browser.