[25] | 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 | Post shader: Light geometry material |
---|
| 25 | */ |
---|
| 26 | struct VS_OUTPUT { |
---|
| 27 | float4 pos: POSITION; |
---|
| 28 | float2 texCoord: TEXCOORD0; |
---|
| 29 | float3 projCoord: TEXCOORD1; |
---|
| 30 | }; |
---|
| 31 | |
---|
| 32 | uniform float vpWidth, vpHeight; |
---|
| 33 | uniform float4x4 worldViewProj; |
---|
| 34 | uniform float4x4 invProj; |
---|
| 35 | |
---|
| 36 | VS_OUTPUT main( |
---|
| 37 | float4 Pos: POSITION |
---|
| 38 | ){ |
---|
| 39 | VS_OUTPUT Out; |
---|
| 40 | |
---|
| 41 | float4 projPos = mul(worldViewProj, Pos); |
---|
| 42 | projPos = projPos/projPos.w; |
---|
| 43 | //projPos[2] = 0; |
---|
| 44 | |
---|
| 45 | // projPos is now in nonhomogeneous 2d space -- this makes sure no perspective interpolation is |
---|
| 46 | // done that could mess with our concept. |
---|
| 47 | Out.pos = projPos; |
---|
| 48 | |
---|
| 49 | //float3 position = mul(invProj, float4(projCoord, 0, 1))*distance; |
---|
| 50 | // Acquire view space position via inverse projection transformation |
---|
| 51 | // Optimisation for perspective, symmetric view frustrums |
---|
| 52 | // These interpolate over the frustrum plane for w=1 |
---|
| 53 | Out.projCoord = float3(projPos[0], projPos[1], 1)*float3( |
---|
| 54 | invProj[0][0], // X vector component from X |
---|
| 55 | invProj[1][1], // Y vector component from Y |
---|
| 56 | invProj[2][3] // Z vector component from W |
---|
| 57 | ); |
---|
| 58 | |
---|
| 59 | // Texture coordinate magic, this compensates for jitter |
---|
| 60 | float2 texCoord = float2(projPos[0]/2+0.5, -projPos[1]/2+0.5); |
---|
| 61 | float2 texSize = float2(vpWidth, vpHeight); |
---|
| 62 | texCoord = floor(texCoord * texSize)/texSize; |
---|
| 63 | Out.texCoord = texCoord; |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | return Out; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | |
---|