- Timestamp:
- 09/04/08 16:46:27 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2903 r2904 35 35 /** The ssao shader returning the an intensity value between 0 and 1 36 36 */ 37 float ssao(fragment IN,37 float2 ssao(fragment IN, 38 38 uniform sampler2D positions, 39 39 uniform sampler2D noiseTexture, 40 40 uniform float2 samples[NUM_SAMPLES], 41 41 uniform float3 currentNormal, 42 uniform float3 currentViewDir,43 42 uniform float4 centerPosition 43 //,uniform float3 currentViewDir 44 44 ) 45 45 { … … 52 52 53 53 float total_ao = 0.0; 54 float numSamples = 0; 54 55 55 56 for (int i = 0; i < NUM_SAMPLES; ++ i) … … 68 69 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 69 70 70 //if ((texcoord.x <= 1.0f) || (texcoord.x >= 0.0f) || (texcoord.y <= 1.0f) || (texcoord.y >= 0.0f)) 71 71 if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) 72 ++ numSamples; 73 72 74 // sample downsampled texture in order to speed up texture accesses 73 75 float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz; … … 92 94 93 95 total_ao += cos_angle * distance_intensity; 96 97 //total_ao /= j; 94 98 } 95 99 96 return max(0.0f, 1.0f - total_ao);100 return float2(max(0.0f, 1.0f - total_ao), numSamples); 97 101 //return saturate(dot(currentViewDir, currentNormal)); 98 102 } … … 124 128 125 129 /// the current view direction 126 float3 viewDir;//= normalize(IN.view);130 //float3 viewDir = normalize(IN.view); 127 131 128 132 // the current world position … … 133 137 const float currentDepth = currentCol.w; 134 138 135 const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, centerPosition);139 const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition);//, viewDir); 136 140 137 141 … … 154 158 155 159 float oldWeight = clamp(oldCol.z, 0, temporalCoherence); 160 float oldNumSamples = oldCol.y; 161 156 162 float newWeight; 157 163 158 if ( (temporalCoherence > 0) &&164 if (//(temporalCoherence > 0) && 159 165 (tex.x >= 0.0f) && (tex.x < 1.0f) && 160 166 (tex.y >= 0.0f) && (tex.y < 1.0f) && 161 (abs(depthDif) < 1e-4f)) 167 (abs(depthDif) < 1e-3f) 168 && (oldNumSamples > ao.y - 1.5f) // check if something happened in the surrounding area 169 ) 162 170 { 163 newWeight = oldWeight + 1; 171 // increase the weight for convergence 172 newWeight = oldWeight + 1.0f; 164 173 165 174 //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 166 OUT.illum_col = (float4)(ao + oldCol.x * oldWeight) / newWeight; 175 OUT.illum_col.xy = (ao.xy + oldCol.xy * oldWeight) / newWeight; 176 177 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 167 178 } 168 179 else 169 180 { 170 OUT.illum_col = (float4)ao;181 OUT.illum_col.xy = ao.xy; 171 182 newWeight = 0; 172 183 } 173 184 174 185 186 //OUT.illum_col.y = ao.y; 175 187 OUT.illum_col.z = newWeight; 176 188 OUT.illum_col.w = currentDepth;
Note: See TracChangeset
for help on using the changeset viewer.