- Timestamp:
- 11/16/08 23:57:33 (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
r3128 r3129 60 60 61 61 62 static GLuint noiseTex = 0; 62 static GLuint noiseTex2D = 0; 63 static GLuint noiseTex1D = 0; 63 64 64 65 … … 214 215 215 216 glEnable(GL_TEXTURE_2D); 216 glGenTextures(1, &noiseTex );217 glBindTexture(GL_TEXTURE_2D, noiseTex );217 glGenTextures(1, &noiseTex2D); 218 glBindTexture(GL_TEXTURE_2D, noiseTex2D); 218 219 219 220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); … … 233 234 PrintGLerror("noisetexture"); 234 235 } 236 237 238 static void CreateNoiseTex1D(int w) 239 { 240 float *randomValues = new float[w * 3]; 241 242 static HaltonSequence halton; 243 244 randomValues[0] = randomValues[1] = randomValues[2] = 0; 245 246 for (int i = 3; i < w * 3; i += 3) 247 { 248 // create random samples on a circle 249 randomValues[i + 0] = 20.0f * RandomValue(0, 1) / 512.0f; 250 randomValues[i + 1] = 20.0f * RandomValue(0, 1) / 384.0f; 251 randomValues[i + 2] = 0; 252 } 253 254 glEnable(GL_TEXTURE_2D); 255 glGenTextures(1, &noiseTex1D); 256 glBindTexture(GL_TEXTURE_2D, noiseTex1D); 257 258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 262 263 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, 1, 0, GL_RGB, GL_FLOAT, randomValues); 264 265 glBindTexture(GL_TEXTURE_2D, 0); 266 glDisable(GL_TEXTURE_2D); 267 268 delete [] randomValues; 269 270 cout << "created noise texture 1D" << endl; 271 272 PrintGLerror("noisetexture 1D"); 273 } 274 235 275 236 276 … … 284 324 //CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 285 325 CreateNoiseTex2D(mWidth / 8, mHeight / 8); 326 CreateNoiseTex1D(mWidth / 8); 286 327 287 328 mProjViewMatrix = IdentityMatrix(); … … 302 343 { 303 344 CLEAR_CONTAINER(mFBOs); 304 glDeleteTextures(1, &noiseTex); 345 glDeleteTextures(1, &noiseTex2D); 346 glDeleteTextures(1, &noiseTex1D); 305 347 } 306 348 … … 337 379 "samples", "bl", "br", "tl", "tr", 338 380 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 339 "oldtl", "oldtr", "attribsTex" };340 sCgSsaoProgram->AddParameters(ssaoParams, 0, 1 8);381 "oldtl", "oldtr", "attribsTex", "noiseTex1D"}; 382 sCgSsaoProgram->AddParameters(ssaoParams, 0, 19); 341 383 342 384 string giParams[] = … … 538 580 sCgSsaoProgram->SetTexture(i ++, normalsTex); 539 581 sCgSsaoProgram->SetTexture(i ++, oldTex); 540 sCgSsaoProgram->SetTexture(i ++, noiseTex );582 sCgSsaoProgram->SetTexture(i ++, noiseTex2D); 541 583 542 584 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 543 585 544 //if (mUseTemporalCoherence || mRegenerateSamples)545 if (mRegenerateSamples)586 if (mUseTemporalCoherence || mRegenerateSamples) 587 //if (mRegenerateSamples) 546 588 { 547 589 mRegenerateSamples = false; … … 550 592 // in the first case, the sample patterns look nicer, but the kernel 551 593 // needs longer to converge 552 GenerateSamples(mSamplingMethod); 594 GenerateSamples(mSamplingMethod); 553 595 sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 554 596 } … … 573 615 574 616 sCgSsaoProgram->SetTexture(i ++, attribsTex); 617 618 sCgSsaoProgram->SetTexture(i ++, noiseTex1D); 575 619 576 620 DrawQuad(sCgSsaoProgram); … … 675 719 sCgGiProgram->SetTexture(0, colorsTex); 676 720 sCgGiProgram->SetTexture(1, normalsTex); 677 sCgGiProgram->SetTexture(2, noiseTex );721 sCgGiProgram->SetTexture(2, noiseTex2D); 678 722 sCgGiProgram->SetTexture(3, oldSsaoTex); 679 723 sCgGiProgram->SetTexture(4, oldIllumTex); … … 748 792 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 749 793 GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 794 //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 750 795 751 796 // overwrite old color texture … … 787 832 sCgDeferredShadowProgram->SetTexture(1, normalsTex); 788 833 sCgDeferredShadowProgram->SetTexture(2, shadowTex); 789 sCgDeferredShadowProgram->SetTexture(3, noiseTex );834 sCgDeferredShadowProgram->SetTexture(3, noiseTex2D); 790 835 sCgDeferredShadowProgram->SetMatrix(4, shadowMatrix); 791 836 sCgDeferredShadowProgram->SetValue1f(5, 2.0f / shadowMap->GetSize()); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.h
r2839 r3129 156 156 157 157 // special construtor for pregenerating static halton sequences 158 HaltonSequence(const int dim, const int number); 159 160 HaltonSequence(): index(1) {} 161 162 void Reset() 163 { 164 index = 1; 165 } 166 167 void 168 GetNext(const int dimensions, float *p); 169 170 void GenerateNext() 171 { 172 ++ index; 173 } 158 HaltonSequence(int dim, int number); 159 160 HaltonSequence(): index(1) 161 { 162 float dummy[2]; 163 for (int i = 0; i < 20; ++ i) GetNext(2, dummy); 164 } 165 166 void Reset() { index = 1; } 167 168 void GetNext(int dimensions, float *p); 169 170 void GenerateNext() { ++ index; } 174 171 175 172 double GetNumber(const int dimension) 176 173 { 177 174 int base = FindPrime(dimension); 178 if(base == 1) { 179 base++; //The first dimension uses base 2. 175 if (base == 1) 176 { 177 base++; // The first dimension uses base 2. 180 178 } 181 179 182 180 int _p1 = base; 183 float _ip1 = 1.0f /base;181 float _ip1 = 1.0f / base; 184 182 float p, u=0.0f; 185 183 int kk, a; … … 198 196 @param dimension the dimension 199 197 */ 200 double GetNumberOld( constint dimension)198 double GetNumberOld(int dimension) 201 199 { 202 200 int base = FindPrime(dimension); … … 214 212 if ((base >= 2) && (index >= 1)) 215 213 { 216 while (copyOfIndex > 0)214 while (copyOfIndex > 0) 217 215 { 218 216 N1 = (copyOfIndex / base); … … 226 224 else 227 225 { 228 std::cerr <<"Error generating Halton sequence."<<std::endl;226 std::cerr << "Error generating Halton sequence." << std::endl; 229 227 exit(1); 230 228 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3128 r3129 167 167 168 168 //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 169 depthFactor = max(step(5e- 2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);170 normalFactor = max(step(0. 5f, dot(sampleNorm, norm)), 1e-3f);171 172 w = filterWeights[i] * normalFactor * depthFactor;173 //w = filterWeights[i]* depthFactor;169 depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 170 normalFactor = max(step(0.3f, dot(sampleNorm, norm)), 1e-3f); 171 172 //w = filterWeights[i] * normalFactor * depthFactor; 173 w = normalFactor * depthFactor; 174 174 175 175 average += aoSample.y * w; … … 177 177 } 178 178 179 average *= 1.0f / max(total_w, 1e- 6f);179 average *= 1.0f / max(total_w, 1e-3f); 180 180 181 181 return average; … … 193 193 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 194 194 195 //const static float scaleFactor = 10.0f;195 //const static float scaleFactor = 20.0f; 196 196 const static float scaleFactor = 10.0f; 197 198 197 ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1); 199 198 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3128 r3129 209 209 #endif 210 210 211 const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);212 //const float oldWeight = oldPixel.y;211 //const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 212 const float oldWeight = oldPixel.y; 213 213 214 214 float newWeight; … … 220 220 // if visibility changed in the surrounding area we have to recompute 221 221 //&& (oldNumSamples > 0.8f * newNumSamples) 222 && (notValid < 1.0f)222 //&& (notValid < 1.0f) 223 223 ) 224 224 { 225 225 // increase the weight for convergence 226 226 newWeight = oldWeight + 1.0f; 227 //if (notValid > 1.0f) newWeight = 10.0f;227 if (notValid > 1.0f) newWeight = 10.0f; 228 228 //if (notValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f); 229 229 } … … 236 236 // newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 237 237 //if (newWeight >= 2000) newWeight = 1000; 238 //newWeight -= step(2000.0f, newWeight) * 1000.0f;238 newWeight -= step(512.0f, newWeight) * 256.0f; 239 239 240 240 return float3(oldPixel.x, newWeight, eyeSpaceDepth); … … 257 257 float3 viewDir 258 258 , float2 noiseOffs 259 , sampler2D noiseTex1D 259 260 ) 260 261 { … … 266 267 float numSamples = .0f; 267 268 269 270 //float2 jitter = tex2Dlod(noiseTex1D, float4(IN.texCoord.x * 4.0f + noiseOffs.x, 0.5f, 0, 0)).xy; 271 //float2 jitter = tex2Dlod(noiseTex1D, float4(noiseOffs.x, 0.5f, 0, 0)).xy; 268 272 269 273 for (int i = 0; i < NUM_SAMPLES; ++ i) … … 282 286 #endif 283 287 // weight with projected coordinate to reach similar kernel size for near and far 288 //const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor + jitter; 284 289 const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 285 290 286 291 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 287 288 292 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 289 293 … … 340 344 uniform float3 oldtl, 341 345 uniform float3 oldtr, 342 uniform sampler2D attribsTex 346 uniform sampler2D attribsTex, 347 uniform sampler2D noiseTex1D 343 348 ) 344 349 { … … 378 383 scaleFactor, 379 384 oldbl, oldbr, oldtl, oldtr, 380 diffVec); 385 diffVec 386 ); 381 387 382 388 const float oldSsao = temporalVals.x; 383 const float newWeight = clamp(temporalVals.y, .0f, temporalCoherence); 384 385 //float2 noiseOffs = float2(temporalVals.y / 139.0f, temporalVals.y / 141.0f); 386 float2 noiseOffs = float2(.0f); 389 const float newWeight = clamp(temporalVals.y, 1.0f, temporalCoherence); 390 float2 noiseOffs = float2((temporalVals.y - 1)/ 139.0f, .0f); 391 //float2 noiseOffs = float2(.0f); 387 392 388 393 float2 ao; … … 392 397 { 393 398 ao = ssao(IN, colors, noiseTex, samples, normal, 394 eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), noiseOffs );399 eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), noiseOffs, noiseTex1D); 395 400 } 396 401 else
Note: See TracChangeset
for help on using the changeset viewer.