[1] | 1 | /****************************************************************************** |
---|
| 2 | Copyright (c) W.J. van der Laan |
---|
| 3 | |
---|
| 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
---|
| 5 | this software and associated documentation files (the "Software"), to deal in |
---|
| 6 | the Software without restriction, including without limitation the rights to use, |
---|
| 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
---|
| 8 | Software, and to permit persons to whom the Software is furnished to do so, subject |
---|
| 9 | to the following conditions: |
---|
| 10 | |
---|
| 11 | The above copyright notice and this permission notice shall be included in all copies |
---|
| 12 | or substantial portions of the Software. |
---|
| 13 | |
---|
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
---|
| 15 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
---|
| 16 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
---|
| 17 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
---|
| 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE |
---|
| 19 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
| 20 | ******************************************************************************/ |
---|
| 21 | /** Deferred shading framework |
---|
| 22 | // W.J. :wumpus: van der Laan 2005 // |
---|
| 23 | |
---|
| 24 | Material shader: Textured normal mapped |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #extension GL_ARB_draw_buffers : enable |
---|
| 28 | |
---|
| 29 | varying vec3 normal; |
---|
| 30 | varying vec3 tangent_; |
---|
| 31 | varying vec3 binormal; |
---|
| 32 | |
---|
| 33 | varying vec2 texCoord0; |
---|
| 34 | varying float depth; |
---|
| 35 | uniform sampler2D tex0; |
---|
| 36 | uniform sampler2D normTex; |
---|
| 37 | |
---|
| 38 | uniform float specularity; |
---|
| 39 | |
---|
| 40 | void main() |
---|
| 41 | { |
---|
| 42 | // Frame for normal mapping |
---|
| 43 | mat3 rotation = mat3(tangent_, binormal, normal); |
---|
| 44 | vec3 texnormal = (vec3(texture2D(normTex, texCoord0))-0.5)*2.0; |
---|
| 45 | |
---|
| 46 | gl_FragData[0].rgb = vec3(texture2D(tex0, texCoord0)); |
---|
| 47 | gl_FragData[0].a = specularity; |
---|
| 48 | // rotation*texnormal is reversed for GL because matrices are stored transposed internally |
---|
| 49 | // compared to HLSL |
---|
| 50 | gl_FragData[1].xyz = normalize(rotation*texnormal); // Do normalisation here, saves an operation per light |
---|
| 51 | gl_FragData[1].w = depth; |
---|
| 52 | } |
---|