[2868] | 1 | |
---|
| 2 | /** Computes the temporally smoothed indirect illumination buffer and combines it |
---|
| 3 | with the color buffer |
---|
| 4 | */ |
---|
| 5 | pixel main(fragment IN, |
---|
| 6 | uniform sampler2D colors, |
---|
| 7 | uniform sampler2D ssao, |
---|
| 8 | uniform sampler2D oldssao, |
---|
| 9 | uniform sampler2D positions |
---|
| 10 | const uniform float4x4 oldModelViewProj, |
---|
| 11 | uniform float maxDepth, |
---|
| 12 | uniform float expFactor |
---|
| 13 | ) |
---|
| 14 | { |
---|
| 15 | pixel OUT; |
---|
| 16 | |
---|
| 17 | float4 centerPosition = tex2D(positions, IN.texCoord.xy); |
---|
| 18 | |
---|
| 19 | float4 col = tex2D(colors, IN.texCoord.xy); |
---|
| 20 | |
---|
| 21 | float ao = tex2D(ssao, IN.texCoord.xy); |
---|
| 22 | float4 attenuated_color = ao * col; |
---|
| 23 | //float4 attenuated_color = ao; |
---|
| 24 | |
---|
| 25 | //float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); |
---|
| 26 | //float4 attenuated_color = ao * col + new_col; |
---|
| 27 | |
---|
| 28 | const float x = expFactor; |
---|
| 29 | |
---|
| 30 | float4 dummy = centerPosition * maxDepth; |
---|
| 31 | dummy.w = 1.0f; |
---|
| 32 | |
---|
| 33 | float4 oldPos = mul(oldModelViewProj, dummy); |
---|
| 34 | |
---|
| 35 | float newDepth = oldPos.z / oldPos.w; |
---|
| 36 | |
---|
| 37 | float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; |
---|
| 38 | float4 col1 = tex2D(oldTex, tex); |
---|
| 39 | |
---|
| 40 | float oldDepth = col1.w; |
---|
| 41 | float depthDif = 1.0f - newDepth / oldDepth; |
---|
| 42 | |
---|
| 43 | if ((tex.x >= 0.0f) && (tex.x < 1.0f) && |
---|
| 44 | (tex.y >= 0.0f) && (tex.y < 1.0f) && |
---|
| 45 | (abs(depthDif) < 1e-4f)) |
---|
| 46 | { |
---|
| 47 | OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor); |
---|
| 48 | } |
---|
| 49 | else |
---|
| 50 | { |
---|
| 51 | OUT.color = attenuated_color; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | //OUT.color.xyz = viewDir; |
---|
| 55 | //OUT.color = attenuated_color; |
---|
| 56 | |
---|
| 57 | //OUT.color.w = tex2D(colors, IN.texCoord.xy).w; |
---|
| 58 | |
---|
| 59 | return OUT; |
---|
| 60 | } |
---|