root/OpenSceneGraph-Data/trunk/shaders/blocky.vert

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

Checked in first cut of new SVN for OpenSceneGraph-Data

Line 
1 // blocky.vert - an OGLSL vertex shader with animation
2 // Mike Weiblen 2003-09-16 : derived from brick.vert
3 // Copyright 2003 3Dlabs Inc.
4 // see http://www.3dlabs.com/opengl2/ for more OpenGL Shading Language info.
5
6
7 // the App updates uniforms "slowly" (eg once per frame) for animation.
8 uniform float Sine;
9
10 const vec3 LightPosition = vec3(0.0, 0.0, 4.0);
11 const float BlockScale = 0.30;
12
13 // varyings are written by vert shader, interpolated, and read by frag shader.
14 varying float LightIntensity;
15 varying vec2  BlockPosition;
16
17 void main(void)
18 {
19     // per-vertex diffuse lighting
20     vec4 ecPosition     = gl_ModelViewMatrix * gl_Vertex;
21     vec3 tnorm          = normalize(gl_NormalMatrix * gl_Normal);
22     vec3 lightVec       = normalize(LightPosition - vec3 (ecPosition));
23     LightIntensity      = max(dot(lightVec, tnorm), 0.0);
24
25     // blocks will be determined by fragment's position on the XZ plane.
26     BlockPosition = gl_Vertex.xz / BlockScale;
27
28     // scale the geometry based on an animation variable.
29     vec4 vertex = gl_Vertex;
30     vertex.w    = 1.0 + 0.4 * (Sine + 1.0);
31
32     gl_Position = gl_ModelViewProjectionMatrix * vertex;
33 }
34
Note: See TracBrowser for help on using the browser.