Changeset 2904
- Timestamp:
- 09/04/08 16:46:27 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2903 r2904 8 8 // for linear falloff 9 9 //#define SAMPLE_INTENSITY 500.0f 10 //#define SAMPLE_INTENSITY 100.0f10 //#define SAMPLE_INTENSITY 40.0f 11 11 12 12 // for quadradtc falloff -
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 -
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.