- Timestamp:
- 11/02/08 17:35:59 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3085 r3087 267 267 mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 268 268 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 269 // downsample buffer for the normal texture 269 270 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 270 271 … … 272 273 273 274 // create noise texture for ssao 274 CreateNoiseTex2D(m DownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight());275 CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 275 276 276 277 mProjViewMatrix = IdentityMatrix(); … … 504 505 505 506 void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo, 506 float tempCohFactor 507 508 ) 507 float tempCohFactor) 509 508 { 510 509 #if 0 … … 516 515 #endif 517 516 517 // flip flop between illumination buffers 518 518 GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 519 519 … … 571 571 sCgSsaoProgram->SetValue3f(16, tl.x, tl.y, tl.z); 572 572 sCgSsaoProgram->SetValue3f(17, tr.x, tr.y, tr.z); 573 574 573 575 574 DrawQuad(sCgSsaoProgram); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3085 r3087 42 42 #define MAX_LOD_LEVEL 10 43 43 44 #define MIN_DEPTH_DIFF 1e- 3f44 #define MIN_DEPTH_DIFF 1e-1f 45 45 #define PRECISION_SCALE 1e-1f 46 46 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3081 r3087 205 205 OUT.color = useShading ? (ambient + diffuse) * color : color; 206 206 207 // store scaled view vector from now on so wie don't have to normalize for e.g., ssao207 // store scaled view vector from now on so wie don't have to normalize later (e.g., for ssao) 208 208 OUT.color.w = color.w / lenView; 209 209 … … 215 215 as well as a boolean that 216 216 */ 217 pixel (fragment IN,218 219 uniform sampler2D normals,217 pixel Reproject(fragment IN, 218 uniform sampler2D colors, 219 uniform sampler2D normals) 220 220 { 221 221 float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3086 r3087 54 54 float3 bl, float3 br, float3 tl, float3 tr) 55 55 { 56 const float eyeSpaceDepth = tex2D (tex, texcoord).w;56 const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 57 57 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 58 58 float3 samplePos = -viewVec * eyeSpaceDepth; … … 62 62 63 63 #pragma position_invariant temporalSmoothing 64 65 66 inline float ComputeDifference(float2 offset, 67 uniform sampler2D oldTex, 68 const uniform float4x4 oldModelViewProj, 69 uniform sampler2D colors, 70 uniform sampler2D noiseTex, 71 uniform float scaleFactor, 72 uniform float3 bl, 73 uniform float3 br, 74 uniform float3 tl, 75 uniform float3 tr, 76 float2 texcoord0, 77 float3 eyePos, 78 float3 oldEyePos, 79 uniform float3 oldbl, 80 uniform float3 oldbr, 81 uniform float3 oldtl, 82 uniform float3 oldtr, 83 float dummy3 84 ) 85 { 86 float2 mynoise = tex2D(noiseTex, texcoord0).xy; 87 88 const float2 offsetTransformed = myreflect(offset, mynoise); 89 const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 90 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos; 91 92 // reproject into old frame and calculate projected depth 93 float4 projPos = mul(oldModelViewProj, float4(samplePos, 1.0f)); 94 projPos /= projPos.w; 95 96 // fit from unit cube into 0 .. 1 97 const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; 98 99 // retrieve the sample from the last frame 100 float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 101 102 float oldEyeSpaceDepth = oldCol.z / dummy3; 103 float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 104 float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 105 106 float dDiff = length(oldSamplePos - samplePos.xyz); 107 108 return dDiff; 109 } 110 64 111 65 112 /** This shader computes the reprojection and stores reprojected color / depth values … … 101 148 // fit from unit cube into 0 .. 1 102 149 const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f; 150 //float2 oldTexCoords = texcoord0; 103 151 104 152 // retrieve the sample from the last frame 105 float4 oldCol = tex2D(oldTex, oldTexCoords); 106 const float oldEyeSpaceDepth = oldCol.z; 153 float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 154 155 //eyeSpaceDepth = 1e6f; 156 157 const float dummy3 = 1e-4f; 158 //const float oldEyeSpaceDepth = 1e5f * dummy3; 159 const float oldEyeSpaceDepth = oldCol.z / dummy3; 160 161 //oldTexCoords.x += 0.5f / 1024.0f; oldTexCoords.y += 0.5f / 768.0f; 107 162 108 163 float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 109 164 //float3 oldSamplePos = -viewVec * eyeSpaceDepth + oldEyePos; 110 float3 oldSamplePos = - viewVec * oldCol.z; 111 oldSamplePos += oldEyePos; 165 float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 112 166 113 167 //const float oldDepth = oldCol.z; 114 168 const float depthDif = length(oldSamplePos - worldPos.xyz); 169 eyeSpaceDepth *= dummy3; 170 171 //const float depthDif = abs(oldEyeSpaceDepth - eyeSpaceDepth);// * 1e4f; 172 //const float depthDif = abs(oldEyeSpaceDepth - dummy2) * 1e3f; 115 173 116 174 //const float oldNumSamples = oldCol.y; … … 118 176 float newWeight; 119 177 120 /*bool isValid = true;178 bool isValid = true; 121 179 122 180 for (int i = 0; i < NUM_SAMPLES; ++ i) 123 181 { 124 const float2 offset = samples[i]; 125 126 float2 mynoise = tex2D(noiseTex, texcoord0).xy; 127 const float2 offsetTransformed = myreflect(offset, mynoise); 128 129 const float2 texCoord = texcoord0;// + offsetTransformed * scaleFactor; 130 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos; 131 132 // reproject into old frame and calculate projected depth 133 float4 projPos = mul(oldModelViewProj, float4(samplePos, 1.0f)); 134 projPos /= projPos.w; 135 136 // the current depth projected into the old frame 137 const float projDepth = projPos.z * PRECISION_SCALE; 138 // fit from unit cube into 0 .. 1 139 // retrieve the sample from the last frame 140 const float4 oldSample = tex2D(oldTex, projPos.xy * 0.5f + 0.5f); 141 const float dDiff = projDepth - oldSample.z; 142 143 if (abs(dDiff) > 1e-5f) isValid = false; 144 }*/ 182 float sampleDif = ComputeDifference(samples[i], 183 oldTex, 184 oldModelViewProj, 185 colors, 186 noiseTex, 187 scaleFactor, 188 bl, br, tl, tr, 189 texcoord0, 190 eyePos, 191 oldEyePos, 192 oldbl, oldbr, oldtl, oldtr, 193 dummy3); 194 195 if (sampleDif > MIN_DEPTH_DIFF) isValid = false; 196 } 145 197 146 198 // the number of valid samples in this frame … … 153 205 // if visibility changed in the surrounding area we have to recompute 154 206 //&& (oldNumSamples > 0.8f * newNumSamples) 155 //&& isValid207 && isValid 156 208 ) 157 209 { … … 166 218 newWeight = .0f; 167 219 } 220 221 //illum_col.x = depthDif; 168 222 169 223 //isValid = 0.0f; … … 171 225 illum_col.y = newWeight; 172 226 illum_col.z = eyeSpaceDepth; 227 //illum_col.z = dummy2; 173 228 174 229 return illum_col; … … 347 402 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 348 403 349 //OUT.illum_col = col * ao.x; 350 OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 404 OUT.illum_col = col * ao.x; 405 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 406 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 351 407 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 352 408 OUT.illum_col.w = col.w;
Note: See TracChangeset
for help on using the changeset viewer.