Changeset 3081 for GTP/trunk/App/Demos
- Timestamp:
- 10/30/08 18:32:56 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3079 r3081 604 604 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 605 605 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 606 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();607 606 608 607 fbo->Bind(); … … 724 723 725 724 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 726 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();727 725 728 726 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); … … 774 772 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 775 773 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 776 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();777 774 778 775 GLuint shadowTex = shadowMap->GetDepthTexture(); … … 948 945 949 946 947 /* 948 void DeferredRenderer::BackProject(FrameBufferObject *fbo) 949 { 950 // back project new frame into old one and check 951 // if pixel still valid. store this property with ssao texture or even 952 // betteer with color / depth texture. This way 953 // we can sample this property together with the color / depth 954 // values and we do not require additional texture lookups 955 fbo->Bind(); 956 957 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 958 //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 959 960 // overwrite old color texture 961 //colorBufferIdx = 3 - colorBufferIdx; 962 //glDrawBuffers(1, mrt + colorBufferIdx); 963 //glDrawBuffers(1, mrt + colorBufferIdx); 964 965 sCgCombineSsaoProgram->SetTexture(0, colorsTex); 966 //sCgCombineSsaoProgram->SetTexture(1, ssaoTex); 967 968 DrawQuad(sCgBackProjectProgram); 969 970 PrintGLerror("combine ssao"); 971 } 972 */ 973 974 975 950 976 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3080 r3081 6 6 //-- ssao + gi parameters 7 7 8 #define NUM_SAMPLES 89 //#define NUM_SAMPLES 168 //#define NUM_SAMPLES 8 9 #define NUM_SAMPLES 16 10 10 11 11 // for quadratic falloff 12 12 //#define SAMPLE_INTENSITY 0.1f 13 #define SAMPLE_INTENSITY 0.07f 13 //#define SAMPLE_INTENSITY 0.07f 14 #define SAMPLE_INTENSITY 0.03f 14 15 15 16 #define SAMPLE_RADIUS 8e-1f … … 18 19 #define DISTANCE_SCALE 5e-2f 19 20 20 #define ILLUM_INTENSITY 8e-2f 21 //#define ILLUM_INTENSITY 8e-2f 22 #define ILLUM_INTENSITY 2e-2f 21 23 22 24 #define VIEW_CORRECTION_SCALE 1.0f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3034 r3081 211 211 } 212 212 213 #if 0 214 /** This shader computes the reprojection and stores reprojected color / depth values 215 as well as a boolean that 216 */ 217 pixel (fragment IN, 218 uniform sampler2D colors, 219 uniform sampler2D normals, 220 { 221 float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)); 222 const float3 normal = normalize(norm.xyz); 223 224 /// reconstruct position from the eye space depth 225 float3 viewDir = IN.view; 226 const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 227 const float3 eyeSpacePos = -viewDir * eyeDepth; 228 const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 229 230 231 //////////////// 232 //-- calculcate the current projected posiion (also used for next frame) 233 234 float4 currentPos = mul(modelViewProj, worldPos); 235 236 const float w = SAMPLE_RADIUS / currentPos.w; 237 currentPos /= currentPos.w; 238 239 const float precisionScale = 1e-3f; 240 const float currentDepth = currentPos.z * precisionScale; 241 242 const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 243 244 245 ///////////////// 246 //-- compute temporally smoothing 247 248 249 // reproject new frame into old one 250 251 // calculate projected depth 252 float4 projPos = mul(oldModelViewProj, worldPos); 253 projPos /= projPos.w; 254 255 // the current depth projected into the old frame 256 const float projDepth = projPos.z * precisionScale; 257 // fit from unit cube into 0 .. 1 258 const float2 tex = projPos.xy * 0.5f + 0.5f; 259 // retrieve the sample from the last frame 260 float4 oldCol = tex2D(oldTex, tex); 261 262 const float oldDepth = oldCol.z; 263 //const float depthDif = 1.0f - projDepth / oldDepth; 264 const float depthDif = projDepth - oldDepth; 265 266 //const float oldNumSamples = oldCol.y; 267 const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 268 269 float newWeight; 270 271 // the number of valid samples in this frame 272 //const float newNumSamples = ao.y; 273 274 if ((temporalCoherence > 0) 275 && (tex.x >= 0.0f) && (tex.x < 1.0f) 276 && (tex.y >= 0.0f) && (tex.y < 1.0f) 277 && (abs(depthDif) < MIN_DEPTH_DIFF) 278 && (abs(oldCol.x - ao.x) < 0.1f) 279 // if visibility changed in the surrounding area we have to recompute 280 //&& (oldNumSamples > 0.8f * newNumSamples) 281 ) 282 { 283 // increase the weight for convergence 284 newWeight = oldWeight + 1.0f; 285 OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 286 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 287 } 288 else 289 { 290 OUT.illum_col.x = ao.x; 291 newWeight = .0f; 292 } 293 294 OUT.illum_col.y = newWeight; 295 OUT.illum_col.z = currentDepth; 296 297 return OUT; 298 } 299 300 #endif -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3080 r3081 20 20 float4 illum_col: COLOR0; 21 21 }; 22 23 24 inline float occlusionPower(float radius, float dist) 25 { 26 return 6.283185307179586476925286766559f * (1.0f - cos(asin(radius / dist))); 27 } 22 28 23 29 … … 106 112 107 113 float3 dirSample = samplePos - centerPosition; 108 const float magSample = length(dirSample);114 const float lengthToSample = length(dirSample); 109 115 // normalize 110 dirSample /= magSample;116 dirSample /= lengthToSample; 111 117 112 118 // angle between current normal and direction to sample controls AO intensity. … … 115 121 // the distance_scale offset is used to avoid singularity that occurs at global illumination when 116 122 // the distance to a sample approaches zero 117 const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + magSample * magSample); 123 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 124 const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample); 118 125 119 126 #if 1 … … 121 128 // => compensate for this (on the other hand, projected sampling area could be larger!) 122 129 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 123 total_ao += cosAngle * intensity* viewCorrection;130 total_ao += cosAngle * aoContrib * viewCorrection; 124 131 #else 125 132 total_ao += cosAngle * intensity; … … 130 137 } 131 138 132 #pragma position_invariant main139 //#pragma position_invariant main 133 140 134 141 /** The mrt shader for screen space ambient occlusion … … 188 195 // the current depth projected into the old frame 189 196 const float projDepth = projPos.z * precisionScale; 190 191 197 // fit from unit cube into 0 .. 1 192 198 const float2 tex = projPos.xy * 0.5f + 0.5f; 193 194 199 // retrieve the sample from the last frame 195 200 float4 oldCol = tex2D(oldTex, tex); … … 199 204 const float depthDif = projDepth - oldDepth; 200 205 201 202 206 //const float oldNumSamples = oldCol.y; 203 207 const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); … … 208 212 //const float newNumSamples = ao.y; 209 213 210 if ((temporalCoherence > 0) && 211 (tex.x >= 0.0f) && (tex.x < 1.0f) && 212 (tex.y >= 0.0f) && (tex.y < 1.0f) && 213 (abs(depthDif) < MIN_DEPTH_DIFF) 214 if ((temporalCoherence > 0) 215 && (tex.x >= 0.0f) && (tex.x < 1.0f) 216 && (tex.y >= 0.0f) && (tex.y < 1.0f) 217 && (abs(depthDif) < MIN_DEPTH_DIFF) 218 && (abs(oldCol.x - ao.x) < 0.1f) 214 219 // if visibility changed in the surrounding area we have to recompute 215 220 //&& (oldNumSamples > 0.8f * newNumSamples) … … 224 229 { 225 230 OUT.illum_col.x = ao.x; 226 newWeight = 0;231 newWeight = .0f; 227 232 } 228 233 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt
r3013 r3081 32 32 33 33 34 35 ssao: 36 37 1) implement bilateral filtering 38 2) check physical properties 39 40 paper of 2007 arikan formula: 41 42 SW(P, C, r) = 2 * pi * (1 - cos(asin (r / |PC|))) 43 44 but not working properly! 45 46 3) normal mapping 47 48 49 problems: 50 51 4) update of converged regions 52 53 something could become visible 54 55 a) from outside 56 b) from previously occluded regions 57 58 a) could use ratio of samples outside current frame / last frame 59 but slows donw code 60 61 5) dynamic objects: 62 63 a) make ao stick on object: this should 64 be possible somehow, as the information is still available!! 65 66 tried to use difference of ao intensity between previous and 67 current frame to find out if pixel ao is not valid anymore. 68 but problems as some flickering was introduced while update of 69 dynamic objects was not fast enough (annoying grey fade effect) 70 71 b) fix the contact shadow on the floor: 72 73 check when pixel not valid anymore: do that by checking for each 74 sample if they were invalidated recently. if so, then invalidate 75 current pixel ao. for each point, theoretically you don't have 76 to compare the depth of the current pixel, but the depth of the 77 samples taken for ao
Note: See TracChangeset
for help on using the changeset viewer.