1
2/*
3** Copyright (c) 2012 The Khronos Group Inc.
4**
5** Permission is hereby granted, free of charge, to any person obtaining a
6** copy of this software and/or associated documentation files (the
7** "Materials"), to deal in the Materials without restriction, including
8** without limitation the rights to use, copy, modify, merge, publish,
9** distribute, sublicense, and/or sell copies of the Materials, and to
10** permit persons to whom the Materials are furnished to do so, subject to
11** the following conditions:
12**
13** The above copyright notice and this permission notice shall be included
14** in all copies or substantial portions of the Materials.
15**
16** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
23*/
24
25
26attribute vec3 gtf_Normal;
27attribute vec4 gtf_Vertex;
28varying float lightIntensity;
29varying vec3  Position;
30
31                                             // Used in the vertex shader.
32uniform mat3 gtf_NormalMatrix;               //<  1
33uniform mat4 gtf_ModelViewMatrix;            //<  2
34uniform mat4 gtf_ModelViewProjectionMatrix;  //<  3
35uniform float myAttrib1f;                    //<  4
36uniform vec2 myAttrib2f;                     //<  5
37uniform vec3  LightPosition;                 //<  6
38uniform vec4 myAttrib4f;                     //<  7
39uniform int myAttrib1i;                      //<  8
40uniform ivec2 myAttrib2i;                    //<  9
41uniform ivec3 myAttrib3i;                    //< 10
42uniform ivec4 myAttrib4i;                    //< 11
43uniform bool myAttrib1b;                     //< 12
44uniform bvec2 myAttrib2b;                    //< 13
45uniform bvec3 myAttrib3b;                    //< 14
46uniform bvec4 myAttrib4b;                    //< 15
47uniform mat2 myAttrib2m;                     //< 16
48uniform mat3 myAttrib3m;                     //< 17
49uniform mat4 myAttrib4m;                     //< 18
50uniform float myUniformfv[5];                //< 19
51                                             // Used in the fragment shader.
52uniform vec3	brickColor;                  //< 20
53uniform vec3	mortarColor;                 //< 21
54uniform float	brickMortarWidth;            //< 22
55uniform float	brickMortarHeight;           //< 23
56uniform float	mwf;                         //< 24
57uniform float	mhf;                         //< 25
58
59
60const float specularContribution = 0.7;
61const float diffuseContribution  = (1.0 - specularContribution);
62
63void main(void) {
64    vec4 pos        = gtf_ModelViewMatrix * gtf_Vertex;
65    Position        = vec3(gtf_Vertex);
66    vec3 tnorm      = normalize(gtf_NormalMatrix * gtf_Normal);
67    vec3 lightVec   = normalize(LightPosition - vec3(pos));
68    vec3 reflectVec = reflect(lightVec, tnorm);
69    vec3 viewVec    = normalize(vec3(pos));
70
71	float f = myAttrib1f + myAttrib2f[0] + myAttrib4f[0]
72			  + float(myAttrib1i) + float(myAttrib2i[0]) + float(myAttrib3i[0]) + float(myAttrib4i[0])
73			  + float(myAttrib1b) + float(myAttrib2b[0]) + float(myAttrib3b[0]) + float(myAttrib4b[0])
74			  + myAttrib2m[0][0] + myAttrib3m[0][0] + myAttrib4m[0][0]
75			  + myUniformfv[0] + myUniformfv[1] + myUniformfv[2] + myUniformfv[3] + myUniformfv[4];
76
77	//float spec = clamp(dot(reflectVec, viewVec), 0.0, 1.0);
78	float spec = clamp(dot(reflectVec, viewVec), f, 1.0);
79    spec = spec * spec;
80    spec = spec * spec;
81    spec = spec * spec;
82    spec = spec * spec;
83
84    lightIntensity = diffuseContribution * dot(lightVec, tnorm) +
85                     specularContribution * spec;
86
87    gl_Position = gtf_ModelViewProjectionMatrix * gtf_Vertex;
88}
89