Statistics
| Revision:

root / PyOpenGL-Demo / proesch / shaderProg / brick.vert @ 1

History | View | Annotate | Download (1.7 kB)

1
// Motion of vertices for torus added by
2
// Peter.Roesch@fh-augsburg.de
3
//
4
// Vertex shader for procedural bricks
5
//
6
// Authors: Dave Baldwin, Steve Koren, Randi Rost
7
//          based on a shader by Darwyn Peachey
8
//
9
// Copyright (c) 2002-2004 3Dlabs Inc. Ltd. 
10
//
11
// See 3Dlabs-License.txt for license information
12
//
13

    
14

    
15
uniform float Time;
16
uniform float Amplitude;
17
uniform vec3 LightPosition;
18

    
19
const float SpecularContribution = 0.3;
20
const float DiffuseContribution  = 1.0 - SpecularContribution;
21
const float M_PI=3.14159265358979323846;
22

    
23
varying float LightIntensity;
24
varying vec2  MCposition;
25

    
26
void main(void)
27
{ 
28
	// calculate offset vector in model space
29
	float angle=0.0;
30
	// nvidia linux driver has problems with atan(0) ...
31
	if (abs(gl_Vertex.y) > 1e-7){
32
		angle=atan(gl_Vertex.y/gl_Vertex.x);
33
		if (gl_Vertex.x<0.0)
34
			angle+=M_PI;
35
	}
36
	vec3 offsetVector = gl_Normal*sin(2.0*angle+Time)*Amplitude;
37
	// shift vertex along the normal
38
    vec3 ecPosition = vec3 (gl_ModelViewMatrix * (gl_Vertex+vec4(offsetVector,0)));
39
    vec3 tnorm      = normalize(gl_NormalMatrix * gl_Normal);
40
    vec3 lightVec   = normalize(LightPosition - ecPosition);
41
    vec3 reflectVec = reflect(-lightVec, tnorm);
42
    vec3 viewVec    = normalize(-ecPosition);
43
    float diffuse   = max(dot(lightVec, tnorm), 0.0);
44
    float spec      = 0.0;
45

    
46
    if (diffuse > 0.0)
47
    {
48
        spec = max(dot(reflectVec, viewVec), 0.0);
49
        spec = pow(spec, 16.0);
50
    }
51

    
52
    LightIntensity  = DiffuseContribution * diffuse +
53
                      SpecularContribution * spec;
54

    
55
    MCposition      = gl_Vertex.xy;
56
    // MCposition      = gl_Vertex.xy+offsetVector.xy;
57
    gl_Position     = gl_ProjectionMatrix*vec4(ecPosition,1);
58
}