OLD | NEW |
(Empty) | |
| 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 |
| 26 attribute vec3 gtf_Normal; |
| 27 attribute vec4 gtf_Vertex; |
| 28 varying float lightIntensity; |
| 29 varying vec3 Position; |
| 30 |
| 31 // Used in the vertex shader. |
| 32 uniform mat3 gtf_NormalMatrix; //< 1 |
| 33 uniform mat4 gtf_ModelViewMatrix; //< 2 |
| 34 uniform mat4 gtf_ModelViewProjectionMatrix; //< 3 |
| 35 uniform float myAttrib1f; //< 4 |
| 36 uniform vec2 myAttrib2f; //< 5 |
| 37 uniform vec3 LightPosition; //< 6 |
| 38 uniform vec4 myAttrib4f; //< 7 |
| 39 uniform int myAttrib1i; //< 8 |
| 40 uniform ivec2 myAttrib2i; //< 9 |
| 41 uniform ivec3 myAttrib3i; //< 10 |
| 42 uniform ivec4 myAttrib4i; //< 11 |
| 43 uniform bool myAttrib1b; //< 12 |
| 44 uniform bvec2 myAttrib2b; //< 13 |
| 45 uniform bvec3 myAttrib3b; //< 14 |
| 46 uniform bvec4 myAttrib4b; //< 15 |
| 47 uniform mat2 myAttrib2m; //< 16 |
| 48 uniform mat3 myAttrib3m; //< 17 |
| 49 uniform mat4 myAttrib4m; //< 18 |
| 50 uniform float myUniformfv[5]; //< 19 |
| 51 // Used in the fragment shader. |
| 52 uniform vec3 brickColor; //< 20 |
| 53 uniform vec3 mortarColor; //< 21 |
| 54 uniform float brickMortarWidth; //< 22 |
| 55 uniform float brickMortarHeight; //< 23 |
| 56 uniform float mwf; //< 24 |
| 57 uniform float mhf; //< 25 |
| 58 |
| 59 |
| 60 const float specularContribution = 0.7; |
| 61 const float diffuseContribution = (1.0 - specularContribution); |
| 62 |
| 63 void 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(myA
ttrib3i[0]) + float(myAttrib4i[0]) |
| 73 + float(myAttrib1b) + float(myAttrib2b[0]) + float(myA
ttrib3b[0]) + float(myAttrib4b[0]) |
| 74 + myAttrib2m[0][0] + myAttrib3m[0][0] + myAttrib4m[0][
0] |
| 75 + myUniformfv[0] + myUniformfv[1] + myUniformfv[2] + m
yUniformfv[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 } |
OLD | NEW |