- Timestamp:
- 11/25/08 13:28:05 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3162 r3163 1 1 #include "../shaderenv.h" 2 3 4 /******************************************/ 5 /* Filter for combining ssao with image */ 6 /******************************************/ 2 #include "common.h" 3 4 5 /*************************************************/ 6 /* Filter for combining ssao with image */ 7 /*************************************************/ 7 8 8 9 … … 21 22 22 23 /** Filter taking into account depth and normal differences, 23 and convergence of a sample24 and convergence of a sample 24 25 */ 25 26 float DiscontinuityFilter(float2 texCoord, … … 31 32 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 32 33 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 33 float scale) 34 float scale 35 ) 34 36 { 35 37 float average = .0f; … … 84 86 85 87 88 89 /** Filter taking into account depth and normal differences, 90 and convergence of a sample 91 */ 92 float DiscontinuityFilter2(float2 texCoord, 93 float4 ao, 94 float4 color, 95 uniform sampler2D ssaoTex, 96 uniform sampler2D normalsTex, 97 uniform sampler2D colorsTex, 98 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 99 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 100 float scale, 101 float3 bl, 102 float3 br, 103 float3 tl, 104 float3 tr) 105 { 106 float average = .0f; 107 float total_w = .0f; 108 109 const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 110 const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 111 //const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 112 113 float4 aoSample; 114 float3 sampleNorm; 115 float3 samplePos; 116 float w; 117 float4 sampleTexCoord; 118 float spatialFactor; 119 float normalFactor; 120 float convergenceFactor; 121 float sampleDepth; 122 123 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 124 { 125 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 126 127 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 128 sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 129 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 130 131 // check spatial discontinuity 132 samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 133 float len = SqrLen(centerPos - samplePos); 134 135 spatialFactor = 1.0f / max(len, 1e-3f); 136 137 //normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-3f); 138 normalFactor = max(dot(sampleNorm, samplePos), 1e-3f); 139 convergenceFactor = min(100.0f, aoSample.y); 140 //convergenceFactor = aoSample.y; 141 142 // combine the weights 143 w = convergenceFactor * spatialFactor * normalFactor; 144 145 average += aoSample.x * w; 146 total_w += w; 147 } 148 149 average /= max(total_w, 1e-6f); 150 151 return saturate(average); 152 } 153 154 86 155 /** Function combining image and indirect illumination buffer using a 87 156 depth and normal aware discontinuity filter. … … 93 162 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 94 163 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 95 uniform float4x4 modelViewProj 164 uniform float4x4 modelViewProj, 165 uniform float3 bl, 166 uniform float3 br, 167 uniform float3 tl, 168 uniform float3 tr 96 169 ) 97 170 { … … 122 195 //if (col.w < 1e10f) 123 196 { 124 ao.x = DiscontinuityFilter (IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, convergenceScale * distanceScale);197 ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, convergenceScale * distanceScale, bl, br, tl, tr); 125 198 } 126 199
Note: See TracChangeset
for help on using the changeset viewer.