[12115] | 1 | #version 150 |
---|
| 2 | /* Copyright Torus Knot Software Ltd 2000-2014 |
---|
| 3 | |
---|
| 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 5 | of this software and associated documentation files (the "Software"), to deal |
---|
| 6 | in the Software without restriction, including without limitation the rights |
---|
| 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 8 | copies of the Software, and to permit persons to whom the Software is |
---|
| 9 | furnished to do so, subject to the following conditions: |
---|
| 10 | |
---|
| 11 | The above copyright notice and this permission notice shall be included in |
---|
| 12 | all copies or substantial portions of the Software. |
---|
| 13 | |
---|
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 20 | THE SOFTWARE. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #define BIAS 0 |
---|
| 24 | |
---|
| 25 | in vec4 position; |
---|
| 26 | in vec3 normal; |
---|
| 27 | in vec4 uv0; |
---|
| 28 | |
---|
| 29 | uniform mat4 worldViewProj; |
---|
| 30 | uniform vec4 lightPosition; |
---|
| 31 | uniform vec3 lightDiffuse; |
---|
| 32 | #if FOG |
---|
| 33 | uniform vec2 fogParams; // x = fog start, y = fog distance |
---|
| 34 | #endif |
---|
| 35 | |
---|
| 36 | #if DEPTH_SHADOWCASTER |
---|
| 37 | uniform vec4 depthRange; // x = min, y = max, z = range, w = 1/range |
---|
| 38 | out float depth; |
---|
| 39 | #endif |
---|
| 40 | |
---|
| 41 | #if DEPTH_SHADOWRECEIVER |
---|
| 42 | uniform vec4 depthRange0; // x = min, y = max, z = range, w = 1/range |
---|
| 43 | uniform vec4 depthRange1; // x = min, y = max, z = range, w = 1/range |
---|
| 44 | uniform vec4 depthRange2; // x = min, y = max, z = range, w = 1/range |
---|
| 45 | uniform mat4 texWorldViewProjMatrix0; |
---|
| 46 | uniform mat4 texWorldViewProjMatrix1; |
---|
| 47 | uniform mat4 texWorldViewProjMatrix2; |
---|
| 48 | out vec4 lightSpacePos0; |
---|
| 49 | out vec4 lightSpacePos1; |
---|
| 50 | out vec4 lightSpacePos2; |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | #if !SHADOWCASTER |
---|
| 54 | out vec3 col; |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | out vec3 diffuseUV; |
---|
| 58 | |
---|
| 59 | void main() |
---|
| 60 | { |
---|
| 61 | // project position to the screen |
---|
| 62 | gl_Position = worldViewProj * position; |
---|
| 63 | |
---|
| 64 | #if !SHADOWCASTER |
---|
| 65 | // Get object space light direction |
---|
| 66 | vec3 lightDir = normalize(lightPosition.xyz - (position.xyz * lightPosition.w).xyz); |
---|
| 67 | col = lightDiffuse.xyz * max(dot(lightDir, normal.xyz), 0.0); |
---|
| 68 | # if FOG |
---|
| 69 | diffuseUV.z = linearFog(gl_Position.z, fogParams.x, fogParams.y); |
---|
| 70 | # endif |
---|
| 71 | |
---|
| 72 | #endif |
---|
| 73 | |
---|
| 74 | // pass through other texcoords exactly as they were received |
---|
| 75 | diffuseUV.xy = uv0.xy; |
---|
| 76 | |
---|
| 77 | #if DEPTH_SHADOWCASTER |
---|
| 78 | depth = (BIAS + gl_Position.z - depthRange.x) * depthRange.w; |
---|
| 79 | #endif |
---|
| 80 | |
---|
| 81 | #if DEPTH_SHADOWRECEIVER |
---|
| 82 | // Calculate the position of vertex in light space |
---|
| 83 | lightSpacePos0 = texWorldViewProjMatrix0 * position; |
---|
| 84 | lightSpacePos1 = texWorldViewProjMatrix1 * position; |
---|
| 85 | lightSpacePos2 = texWorldViewProjMatrix2 * position; |
---|
| 86 | |
---|
| 87 | // make linear |
---|
| 88 | lightSpacePos0.z = (lightSpacePos0.z - depthRange0.x) * depthRange0.w; |
---|
| 89 | lightSpacePos1.z = (lightSpacePos1.z - depthRange1.x) * depthRange1.w; |
---|
| 90 | lightSpacePos2.z = (lightSpacePos2.z - depthRange2.x) * depthRange2.w; |
---|
| 91 | |
---|
| 92 | // pass cam depth |
---|
| 93 | diffuseUV.z = gl_Position.z; |
---|
| 94 | #endif |
---|
| 95 | } |
---|