Brian | 2ccd264 | 2007-01-15 17:27:24 -0700 | [diff] [blame] | 1 | // |
| 2 | // Vertex shader for procedural bricks |
| 3 | // |
| 4 | // Authors: Dave Baldwin, Steve Koren, Randi Rost |
| 5 | // based on a shader by Darwyn Peachey |
| 6 | // |
| 7 | // Copyright (c) 2002-2006 3Dlabs Inc. Ltd. |
| 8 | // |
| 9 | // See 3Dlabs-License.txt for license information |
| 10 | // |
| 11 | |
| 12 | uniform vec3 LightPosition; |
| 13 | |
| 14 | const float SpecularContribution = 0.3; |
| 15 | const float DiffuseContribution = 1.0 - SpecularContribution; |
| 16 | |
| 17 | varying float LightIntensity; |
| 18 | varying vec2 MCposition; |
| 19 | |
| 20 | void main() |
| 21 | { |
| 22 | vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex); |
| 23 | vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal); |
| 24 | vec3 lightVec = normalize(LightPosition - ecPosition); |
| 25 | vec3 reflectVec = reflect(-lightVec, tnorm); |
| 26 | vec3 viewVec = normalize(-ecPosition); |
| 27 | float diffuse = max(dot(lightVec, tnorm), 0.0); |
| 28 | float spec = 0.0; |
| 29 | |
| 30 | if (diffuse > 0.0) |
| 31 | { |
| 32 | spec = max(dot(reflectVec, viewVec), 0.0); |
| 33 | spec = pow(spec, 16.0); |
| 34 | } |
| 35 | |
| 36 | LightIntensity = DiffuseContribution * diffuse + |
| 37 | SpecularContribution * spec; |
| 38 | |
| 39 | MCposition = gl_Vertex.xy; |
| 40 | gl_Position = ftransform(); |
| 41 | } |