- 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/globillum.cg
r2903 r2904 37 37 } 38 38 39 struct GiStruct 40 { 41 float3 illum; 42 float2 ao; 43 }; 44 45 39 46 /** Computes diffuse reflections + ambient occlusion 40 47 */ 41 float4globIllum(fragment IN,48 GiStruct globIllum(fragment IN, 42 49 uniform sampler2D colors, 43 50 uniform sampler2D positions, … … 49 56 ) 50 57 { 58 GiStruct gi; 59 51 60 // the w coordinate from the persp. projection 52 61 float w = centerPosition.w; … … 57 66 58 67 // ao is in stored in the w component 59 float4 total_color = float4(0, 0, 0, 1); 60 68 float3 total_color = float3(0, 0, 0); 69 float total_ao = 0.0f; 70 float numSamples = 0.0f; 61 71 62 72 //////////// … … 78 88 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 79 89 90 if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) 91 ++ numSamples; 92 80 93 // use lower lod level to improve cache coherence 81 94 float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz; … … 100 113 total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 101 114 */ 102 total_ color.w -= cos_angle * distance_intensity;103 total_color .xyz+= cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY;115 total_ao += cos_angle * distance_intensity; 116 total_color += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; 104 117 } 105 118 106 return saturate(total_color); 119 gi.illum = saturate(total_color); 120 gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples); 121 122 //return saturate(total_color); 123 return gi; 107 124 } 108 125 … … 144 161 const float currentDepth = currentCol.w; 145 162 146 float4 new_color = globIllum(IN, colors, positions, noiseTexture, 147 samples, normal, viewDir, centerPosition); 163 GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, centerPosition); 148 164 149 165 … … 168 184 float oldWeight = clamp(oldSsao.z, 0, temporalCoherence); 169 185 float newWeight; 186 187 const float oldNumSamples = oldSsao.y; 170 188 171 189 if ((temporalCoherence > 0.0f) && 172 190 (tex.x >= 0.0f) && (tex.x < 1.0f) && 173 191 (tex.y >= 0.0f) && (tex.y < 1.0f) && 174 (abs(depthDif) < 1e-3f)) 192 (abs(depthDif) < 1e-3f) 193 && (oldNumSamples > gi.ao.y - 1.5f) // check if something happened in the surrounding area 194 ) 175 195 { 176 196 newWeight = oldWeight + 1; 177 197 178 //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 179 OUT.ssao_col.x = (new_color.w + oldSsao.x * oldWeight) / newWeight; 180 OUT.illum_col = (new_color + oldIllum * oldWeight) / newWeight; 181 182 //OUT.ssao_col.x = new_color.w * expFactor + oldSsao.x * (1.0f - expFactor); 183 //OUT.illum_col = new_color * expFactor + oldIllum * (1.0f - expFactor); 198 OUT.ssao_col.xy = (gi.ao + oldSsao.xy * oldWeight) / newWeight; 199 OUT.illum_col.xyz = (gi.illum + oldIllum.xyz * oldWeight) / newWeight; 184 200 } 185 201 else … … 187 203 newWeight = 0; 188 204 189 OUT.ssao_col.x = new_color.w;190 OUT.illum_col = new_color;205 OUT.ssao_col.xy = gi.ao.xy; 206 OUT.illum_col.xyz = gi.illum; 191 207 } 192 208 … … 211 227 212 228 OUT.illum_col = (col + illum) * ao; 229 //OUT.illum_col = ao; 230 213 231 OUT.illum_col.w = col.w; 214 232
Note: See TracChangeset
for help on using the changeset viewer.