Changeset 3026
- Timestamp:
- 10/12/08 15:43:22 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3025 r3026 44 44 { 45 45 46 static CGprogram sCgSsaoProgram = NULL; 47 static CGprogram sCgGiProgram = NULL; 48 49 static CGprogram sCgDeferredProgram = NULL; 50 static CGprogram sCgAntiAliasingProgram = NULL; 51 static CGprogram sCgDeferredShadowProgram = NULL; 52 53 static CGparameter sColorsTexCombineParam; 54 static CGparameter sSsaoTexCombineParam; 55 56 static CGparameter sColorsTexDeferredParam; 57 static CGparameter sPositionsTexDeferredParam; 58 static CGparameter sNormalsTexDeferredParam; 59 60 static CGprogram sCgCombinedSsaoProgram = NULL; 61 static CGprogram sCgCombinedIllumProgram = NULL; 62 63 static CGparameter sColorsTexLogLumParam; 64 65 static CGparameter sDownSampleOffsetParam; 66 static CGparameter sFilterOffsetsParam; 67 static CGparameter sFilterWeightsParam; 68 static CGparameter sPCFFilterWeightsParam; 69 70 static CGprogram sCgDownSampleProgram; 71 static CGprogram sCgToneProgram; 72 static CGprogram sCgLogLumProgram; 73 46 static ShaderProgram *sCgSsaoProgram = NULL; 47 static ShaderProgram *sCgGiProgram = NULL; 48 49 static ShaderProgram *sCgDeferredProgram = NULL; 50 static ShaderProgram *sCgAntiAliasingProgram = NULL; 51 static ShaderProgram *sCgDeferredShadowProgram = NULL; 52 53 static ShaderProgram *sCgCombineSsaoProgram = NULL; 54 static ShaderProgram *sCgCombineIllumProgram = NULL; 55 static ShaderProgram *sCgLogLumProgram = NULL; 56 static ShaderProgram *sCgToneProgram = NULL; 57 static ShaderProgram *sCgDownSampleProgram = NULL; 74 58 75 59 ShaderContainer DeferredRenderer::sShaders; 76 60 77 78 ///////////////////////////////////////79 80 81 static CGparameter sColorsTexParam;82 static CGparameter sNormalsTexParam;83 84 static CGparameter sOldModelViewProjMatrixParam;85 static CGparameter sModelViewProjMatrixParam;86 static CGparameter sEyePosParam;87 static CGparameter sEyePosShadowParam;88 static CGparameter sSamplesParam;89 static CGparameter sOldTexParam;90 static CGparameter sNoiseTexParam;91 static CGparameter sTemporalCoherenceParam;92 93 94 ///////////////////////////////////////95 96 97 static CGparameter sColorsTexGiParam;98 static CGparameter sNormalsTexGiParam;99 100 101 static CGparameter sOldModelViewProjMatrixGiParam;102 static CGparameter sModelViewProjMatrixGiParam;103 static CGparameter sSamplesGiParam;104 static CGparameter sOldSsaoTexGiParam;105 static CGparameter sOldIllumTexGiParam;106 static CGparameter sNoiseTexGiParam;107 static CGparameter sTemporalCoherenceGiParam;108 109 110 static CGparameter sColorsTexCombinedIllumParam;111 static CGparameter sSsaoTexCombinedIllumParam;112 static CGparameter sIllumTexCombinedIllumParam;113 114 static CGparameter sColorsTexCombinedSsaoParam;115 static CGparameter sSsaoTexCombinedSsaoParam;116 117 static CGparameter sTLParam;118 static CGparameter sTRParam;119 static CGparameter sBRParam;120 static CGparameter sBLParam;121 122 123 static CGparameter sTLGiParam;124 static CGparameter sTRGiParam;125 static CGparameter sBRGiParam;126 static CGparameter sBLGiParam;127 128 static CGparameter sEyePosGiParam;129 130 131 132 ////////////133 134 static CGparameter sColorsTexAntiAliasingParam;135 static CGparameter sNormalsTexAntiAliasingParam;136 137 138 static CGparameter sShadowMapParam;139 static CGparameter sPositionsTexShadowParam;140 static CGparameter sColorsTexShadowParam;141 static CGparameter sNormalsTexShadowParam;142 143 static CGparameter sShadowMatrixParam;144 static CGparameter sSampleWidthParam;145 146 static CGparameter sNoiseTexShadowParam;147 static CGparameter sSamplesShadowParam;148 149 static CGparameter sLightDirParam;150 static CGparameter sLightDirShadowParam;151 static CGparameter sImageKeyParam;152 static CGparameter sMiddleGreyParam;153 static CGparameter sWhiteLumParam;154 155 156 static CGparameter sColorsTexInitialParam;157 static CGparameter sColorsTexToneParam;158 159 static CGparameter sColorsTexDownSampleParam;160 161 //#define USE_3D_SSAO162 163 164 61 static GLuint noiseTex = 0; 165 62 166 63 // ssao random spherical samples 167 #ifdef USE_3D_SSAO168 static Sample2 samples3[NUM_SAMPLES];169 #else170 64 static Sample2 samples2[NUM_SAMPLES]; 171 #endif172 173 65 // number of pcf tabs 174 66 Sample2 pcfSamples[NUM_PCF_TABS]; 67 175 68 176 69 int DeferredRenderer::colorBufferIdx = 0; … … 230 123 } 231 124 125 126 void DeferredRenderer::DrawQuad(ShaderProgram *p) 127 { 128 Vector3 tl, tr, bl, br; 129 ComputeViewVectors(tl, tr, bl, br); 130 131 p->Bind(); 132 133 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 134 const float offs = 0.5f; 135 136 glBegin(GL_QUADS); 137 138 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 139 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 140 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 141 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 142 143 glEnd(); 144 145 p->Release(); 146 } 147 148 232 149 /** Generate poisson disc distributed sample points on the unit disc 233 150 */ 234 151 static void GenerateSamples(int sampling) 235 152 { 236 #ifdef USE_3D_SSAO237 238 SphericalSampleGenerator sph(NUM_SAMPLES, 1.0f);239 sph.Generate((float *)samples3);240 241 #else242 153 switch (sampling) 243 154 { … … 255 166 break; 256 167 default: // SAMPLING_DEFAULT 257 258 RandomSampleGenerator2 g(NUM_SAMPLES, 1.0f);259 g.Generate((float *)samples2);260 }261 #endif 168 { 169 RandomSampleGenerator2 g(NUM_SAMPLES, 1.0f); 170 g.Generate((float *)samples2); 171 } 172 } 262 173 } 263 174 … … 273 184 for (int i = 0; i < w * h * 3; i += 3) 274 185 { 275 276 #ifdef USE_3D_SSAO277 //halton.GetNext(2, r);278 r[0] = RandomValue(0, 1);279 r[1] = RandomValue(0, 1);280 281 const float theta = 2.0f * acos(sqrt(1.0f - r[0]));282 const float phi = 2.0f * M_PI * r[1];283 284 randomNormals[i + 0] = sin(theta) * cos(phi);285 randomNormals[i + 1] = sin(theta) * sin(phi);286 randomNormals[i + 2] = cos(theta);287 #else288 186 // create random samples on a circle 289 187 r[0] = RandomValue(0, 1); … … 295 193 randomNormals[i + 1] = sin(theta); 296 194 randomNormals[i + 2] = 0; 297 #endif298 195 } 299 196 … … 387 284 388 285 286 bool DeferredRenderer::InitProgram(ShaderProgram **program, 287 CGcontext context, 288 const std::string &filename, 289 const std::string &functionName) 290 { 291 const string fullName = "src/shaders/" + filename + ".cg"; 292 293 cout << "fullname: " << fullName << endl; 294 295 *program = new ShaderProgram(context, fullName, RenderState::sCgFragmentProfile, functionName); 296 297 sShaders.push_back(*program); 298 299 if (!(*program)->IsValid()) 300 { 301 cerr << "Program" << functionName << " in " << fullName << " failed to load" << endl; 302 return false; 303 } 304 305 return true; 306 } 307 308 389 309 void DeferredRenderer::InitCG(CGcontext context) 390 310 { 391 ShaderProgram *pr; 392 393 sCgDeferredProgram = 394 cgCreateProgramFromFile(context, 395 CG_SOURCE, 396 "src/shaders/deferred.cg", 397 RenderState::sCgFragmentProfile, 398 "main", 399 NULL); 400 401 if (sCgDeferredProgram != NULL) 402 { 403 cgGLLoadProgram(sCgDeferredProgram); 404 405 // we need size of texture for scaling 406 sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "positions"); 407 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors"); 408 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 409 410 sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 411 412 pr = new ShaderProgram(sCgDeferredProgram); 413 sShaders.push_back(pr); 414 } 415 else 416 cerr << "deferred program failed to load" << endl; 417 418 419 /////////////// 420 421 sCgSsaoProgram = 422 cgCreateProgramFromFile(context, 423 CG_SOURCE, 424 #ifdef USE_3D_SSAO 425 "src/shaders/ssao3d.cg", 426 #else 427 "src/shaders/ssao.cg", 428 #endif 429 RenderState::sCgFragmentProfile, 430 "main", 431 NULL); 432 433 if (sCgSsaoProgram != NULL) 434 { 435 cgGLLoadProgram(sCgSsaoProgram); 436 437 sColorsTexParam = cgGetNamedParameter(sCgSsaoProgram, "colors"); 438 sEyePosParam = cgGetNamedParameter(sCgSsaoProgram, "eyePos"); 439 sNormalsTexParam = cgGetNamedParameter(sCgSsaoProgram, "normals"); 440 sNoiseTexParam = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture"); 441 442 sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 443 sModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "modelViewProj"); 444 sTemporalCoherenceParam = cgGetNamedParameter(sCgSsaoProgram, "temporalCoherence"); 445 446 sOldTexParam = cgGetNamedParameter(sCgSsaoProgram, "oldTex"); 447 sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples"); 448 449 sTLParam = cgGetNamedParameter(sCgSsaoProgram, "tl"); 450 sTRParam = cgGetNamedParameter(sCgSsaoProgram, "tr"); 451 sBRParam = cgGetNamedParameter(sCgSsaoProgram, "br"); 452 sBLParam = cgGetNamedParameter(sCgSsaoProgram, "bl"); 453 454 pr = new ShaderProgram(sCgSsaoProgram); 455 sShaders.push_back(pr); 456 } 457 else 458 cerr << "ssao program failed to load" << endl; 459 460 sCgGiProgram = 461 cgCreateProgramFromFile(context, 462 CG_SOURCE, 463 "src/shaders/globillum.cg", 464 RenderState::sCgFragmentProfile, 465 "main", 466 NULL); 467 468 if (sCgGiProgram != NULL) 469 { 470 cgGLLoadProgram(sCgGiProgram); 471 472 // we need size of texture for scaling 473 sColorsTexGiParam = cgGetNamedParameter(sCgGiProgram, "colors"); 474 sNormalsTexGiParam = cgGetNamedParameter(sCgGiProgram, "normals"); 475 476 sOldModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj"); 477 sModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "modelViewProj"); 478 sTemporalCoherenceGiParam = cgGetNamedParameter(sCgGiProgram, "temporalCoherence"); 479 480 sNoiseTexGiParam = cgGetNamedParameter(sCgGiProgram, "noiseTexture"); 481 sSamplesGiParam = cgGetNamedParameter(sCgGiProgram, "samples"); 482 483 sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex"); 484 sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex"); 485 486 sTLGiParam = cgGetNamedParameter(sCgGiProgram, "tl"); 487 sTRGiParam = cgGetNamedParameter(sCgGiProgram, "tr"); 488 sBRGiParam = cgGetNamedParameter(sCgGiProgram, "br"); 489 sBLGiParam = cgGetNamedParameter(sCgGiProgram, "bl"); 490 491 sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos"); 492 493 pr = new ShaderProgram(sCgGiProgram); 494 sShaders.push_back(pr); 495 } 496 else 497 cerr << "globillum program failed to load" << endl; 498 499 sCgCombinedIllumProgram = 500 cgCreateProgramFromFile(context, 501 CG_SOURCE, 502 "src/shaders/globillum.cg", 503 RenderState::sCgFragmentProfile, 504 "combine", 505 NULL); 506 507 if (sCgCombinedIllumProgram != NULL) 508 { 509 cgGLLoadProgram(sCgCombinedIllumProgram); 510 511 sColorsTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "colors"); 512 sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex"); 513 sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex"); 514 515 pr = new ShaderProgram(sCgCombinedIllumProgram); 516 sShaders.push_back(pr); 517 } 518 else 519 cerr << "combined illum program failed to load" << endl; 520 521 522 sCgCombinedSsaoProgram = 523 cgCreateProgramFromFile(context, 524 CG_SOURCE, 525 "src/shaders/ssao.cg", 526 RenderState::sCgFragmentProfile, 527 "combine", 528 NULL); 529 530 if (sCgCombinedSsaoProgram != NULL) 531 { 532 cgGLLoadProgram(sCgCombinedSsaoProgram); 533 534 sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors"); 535 sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex"); 536 537 sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs"); 538 sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights"); 539 540 pr = new ShaderProgram(sCgCombinedSsaoProgram); 541 sShaders.push_back(pr); 542 } 543 else 544 cerr << "combied illum program failed to load" << endl; 545 546 547 sCgAntiAliasingProgram = 548 cgCreateProgramFromFile(context, 549 CG_SOURCE, 550 "src/shaders/antialiasing.cg", 551 RenderState::sCgFragmentProfile, 552 "main", 553 NULL); 554 555 if (sCgAntiAliasingProgram != NULL) 556 { 557 cgGLLoadProgram(sCgAntiAliasingProgram); 558 559 sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors"); 560 sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 561 562 pr = new ShaderProgram(sCgAntiAliasingProgram); 563 sShaders.push_back(pr); 564 } 565 else 566 cerr << "antialiasing program failed to load" << endl; 567 568 sCgDeferredShadowProgram = 569 cgCreateProgramFromFile(context, 570 CG_SOURCE, 571 "src/shaders/deferred.cg", 572 RenderState::sCgFragmentProfile, 573 "main_shadow", 574 NULL); 575 576 if (sCgDeferredShadowProgram != NULL) 577 { 578 cgGLLoadProgram(sCgDeferredShadowProgram); 579 580 // we need size of texture for scaling 581 sPositionsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "positions"); 582 sColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "colors"); 583 sNormalsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "normals"); 584 585 sShadowMapParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMap"); 586 sSampleWidthParam = cgGetNamedParameter(sCgDeferredShadowProgram, "sampleWidth"); 587 sShadowMatrixParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMatrix"); 588 589 sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture"); 590 sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 591 sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 592 593 sEyePosShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "eyePos"); 594 595 float filterWeights[NUM_PCF_TABS]; 596 597 sPCFFilterWeightsParam = cgGetNamedParameter(sCgDeferredShadowProgram, "weights"); 598 599 PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f); 600 poisson.Generate((float *)pcfSamples); 601 602 603 for (int i = 0; i < NUM_PCF_TABS; ++ i) 604 { 605 filterWeights[i] = GaussianDistribution(pcfSamples[i].x, pcfSamples[i].y, 1.0f); 606 } 607 608 cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples); 609 cgGLSetParameterArray1f(sPCFFilterWeightsParam, 0, NUM_PCF_TABS, (const float *)filterWeights); 610 611 pr = new ShaderProgram(sCgDeferredShadowProgram); 612 sShaders.push_back(pr); 613 } 614 else 615 cerr << "deferred program failed to load" << endl; 616 617 sCgLogLumProgram = 618 cgCreateProgramFromFile(context, 619 CG_SOURCE, 620 "src/shaders/tonemap.cg", 621 RenderState::sCgFragmentProfile, 622 "CalcAvgLogLum", 623 NULL); 624 625 if (sCgLogLumProgram != NULL) 626 { 627 cgGLLoadProgram(sCgLogLumProgram); 628 sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors"); 629 630 pr = new ShaderProgram(sCgLogLumProgram); 631 sShaders.push_back(pr); 632 } 633 else 634 cerr << "avg loglum program failed to load" << endl; 635 636 637 sCgToneProgram = 638 cgCreateProgramFromFile(context, 639 CG_SOURCE, 640 "src/shaders/tonemap.cg", 641 RenderState::sCgFragmentProfile, 642 "ToneMap", 643 NULL); 644 645 if (sCgToneProgram != NULL) 646 { 647 cgGLLoadProgram(sCgToneProgram); 648 649 sImageKeyParam = cgGetNamedParameter(sCgToneProgram, "imageKey"); 650 sMiddleGreyParam = cgGetNamedParameter(sCgToneProgram, "middleGrey"); 651 sWhiteLumParam = cgGetNamedParameter(sCgToneProgram, "whiteLum"); 652 653 sColorsTexToneParam = cgGetNamedParameter(sCgToneProgram, "colors"); 654 655 pr = new ShaderProgram(sCgToneProgram); 656 sShaders.push_back(pr); 657 } 658 else 659 cerr << "tone program failed to load" << endl; 660 661 662 sCgDownSampleProgram = 663 cgCreateProgramFromFile(context, 664 CG_SOURCE, 665 "src/shaders/tonemap.cg", 666 RenderState::sCgFragmentProfile, 667 "DownSample", 668 NULL); 669 670 if (sCgDownSampleProgram != NULL) 671 { 672 cgGLLoadProgram(sCgDownSampleProgram); 673 674 // we need size of texture for scaling 675 sColorsTexDownSampleParam = cgGetNamedParameter(sCgDownSampleProgram, "colors"); 676 sDownSampleOffsetParam = cgGetNamedParameter(sCgDownSampleProgram, "downSampleOffs"); 677 678 pr = new ShaderProgram(sCgDownSampleProgram); 679 sShaders.push_back(pr); 680 } 681 else 682 cerr << "downsample program failed to load" << endl; 311 InitProgram(&sCgDeferredProgram, context, "deferred", "main"); 312 InitProgram(&sCgDeferredShadowProgram, context, "deferred", "main_shadow"); 313 InitProgram(&sCgSsaoProgram, context, "ssao", "main"); 314 InitProgram(&sCgGiProgram, context, "globillum", "main"); 315 InitProgram(&sCgCombineIllumProgram, context, "globillum", "combine"); 316 InitProgram(&sCgCombineSsaoProgram, context, "ssao", "combine"); 317 InitProgram(&sCgAntiAliasingProgram, context, "antialiasing", "main"); 318 InitProgram(&sCgToneProgram, context, "tonemap", "ToneMap"); 319 InitProgram(&sCgDownSampleProgram, context, "tonemap", "DownSample"); 320 InitProgram(&sCgToneProgram, context, "tonemap", "ToneMap"); 321 InitProgram(&sCgLogLumProgram, context, "tonemap", "CalcAvgLogLum"); 322 323 float filterWeights[NUM_PCF_TABS]; 324 PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f); 325 poisson.Generate((float *)pcfSamples); 326 327 for (int i = 0; i < NUM_PCF_TABS; ++ i) 328 { 329 filterWeights[i] = GaussianDistribution(pcfSamples[i].x, pcfSamples[i].y, 1.0f); 330 } 331 332 sCgDeferredShadowProgram->SetArray2f("samples", (float *)pcfSamples, NUM_PCF_TABS); 333 sCgDeferredShadowProgram->SetArray1f("weights", (float *)filterWeights, NUM_PCF_TABS); 683 334 684 335 PrintGLerror("init"); … … 785 436 ) 786 437 { 787 #ifdef USE_3D_SSAO 788 // bias from [-1, 1] to [0, 1] 789 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 790 0.0f, 0.5f, 0.0f, 0.5f, 791 0.0f, 0.0f, 0.5f, 0.5f, 792 0.0f, 0.0f, 0.0f, 1.0f); 793 794 Matrix4x4 m = projViewMatrix * biasMatrix; 795 cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 796 #else 797 cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)projViewMatrix.x); 798 #endif 799 800 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 438 sCgSsaoProgram->SetMatrix("modelViewProj", projViewMatrix); 439 sCgSsaoProgram->SetMatrix("oldModelViewProj", oldProjViewMatrix); 440 801 441 #if 0 802 442 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); … … 816 456 glDrawBuffers(1, mrt + mIllumFboIndex); 817 457 818 819 cgGLBindProgram(sCgSsaoProgram);820 821 cgGLSetTextureParameter(sColorsTexParam, colorsTex);822 cgGLEnableTextureParameter(sColorsTexParam);823 824 cgGLSetTextureParameter(sNormalsTexParam, normalsTex);825 cgGLEnableTextureParameter(sNormalsTexParam);826 827 cgGLSetTextureParameter(sNoiseTexParam, noiseTex);828 cgGLEnableTextureParameter(sNoiseTexParam);829 830 cgGLSetTextureParameter(sOldTexParam, oldTex);831 cgGLEnableTextureParameter(sOldTexParam);832 833 458 Vector3 pos = mCamera->GetPosition(); 834 cgGLSetParameter3f(sEyePosParam, pos.x, pos.y, pos.z); 835 836 cgGLSetParameter1f(sTemporalCoherenceParam, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 459 460 sCgSsaoProgram->SetValue3f("eyePos", pos.x, pos.y, pos.z); 461 sCgSsaoProgram->SetTexture("colors", colorsTex); 462 sCgSsaoProgram->SetTexture("normals", normalsTex); 463 sCgSsaoProgram->SetTexture("oldTex", colorsTex); 464 sCgSsaoProgram->SetTexture("noise", noiseTex); 465 466 sCgSsaoProgram->SetValue1f("temporalCoherence", (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 467 837 468 838 469 if (mUseTemporalCoherence || mRegenerateSamples) … … 844 475 // needs longer to converge 845 476 GenerateSamples(mSamplingMethod); 846 847 #ifdef USE_3D_SSAO 848 cgGLSetParameterArray3f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples3); 849 #else 850 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples2); 851 #endif 477 sCgSsaoProgram->SetArray2f("samples", (float *)samples2, NUM_SAMPLES); 852 478 } 853 479 … … 855 481 ComputeViewVectors(tl, tr, bl, br); 856 482 857 cgGLSetParameter3f(sBLParam, bl.x, bl.y, bl.z); 858 cgGLSetParameter3f(sBRParam, br.x, br.y, br.z); 859 cgGLSetParameter3f(sTLParam, tl.x, tl.y, tl.z); 860 cgGLSetParameter3f(sTRParam, tr.x, tr.y, tr.z); 861 862 863 glBegin(GL_QUADS); 864 865 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 866 const float offs = 0.5f; 867 868 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 869 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 870 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 871 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 872 873 //cout<<bl << " " << br << endl; 874 875 glEnd(); 876 877 cgGLDisableTextureParameter(sColorsTexParam); 878 cgGLDisableTextureParameter(sNormalsTexParam); 879 cgGLDisableTextureParameter(sNoiseTexParam); 880 cgGLDisableTextureParameter(sOldTexParam); 483 sCgSsaoProgram->SetValue3f("bl", bl.x, bl.y, bl.z); 484 sCgSsaoProgram->SetValue3f("br", br.x, br.y, br.z); 485 sCgSsaoProgram->SetValue3f("tl", tl.x, tl.y, tl.z); 486 sCgSsaoProgram->SetValue3f("tr", tr.x, tr.y, tr.z); 487 488 DrawQuad(sCgSsaoProgram); 881 489 882 490 glPopAttrib(); … … 923 531 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 924 532 925 cgGLBindProgram(sCgAntiAliasingProgram); 926 927 cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex); 928 cgGLEnableTextureParameter(sColorsTexAntiAliasingParam); 929 930 cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 931 cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 932 933 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 533 sCgAntiAliasingProgram->SetTexture("colors", colorsTex); 534 sCgAntiAliasingProgram->SetTexture("normals", normalsTex); 535 536 sCgAntiAliasingProgram->Bind(); 537 934 538 glColor3f(1.0f, 1.0f, 1.0f); 935 539 … … 947 551 glEnd(); 948 552 949 cgGLDisableTextureParameter(sColorsTexAntiAliasingParam); 950 cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam); 553 sCgAntiAliasingProgram->Release(); 951 554 952 555 PrintGLerror("antialiasing"); … … 964 567 colorBufferIdx = 3 - colorBufferIdx; 965 568 glDrawBuffers(1, mrt + colorBufferIdx); 966 967 cgGLBindProgram(sCgDeferredProgram); 968 969 cgGLSetTextureParameter(sColorsTexDeferredParam, colorsTex); 970 cgGLEnableTextureParameter(sColorsTexDeferredParam); 971 972 cgGLSetTextureParameter(sPositionsTexDeferredParam, positionsTex); 973 cgGLEnableTextureParameter(sPositionsTexDeferredParam); 974 975 cgGLSetTextureParameter(sNormalsTexDeferredParam, normalsTex); 976 cgGLEnableTextureParameter(sNormalsTexDeferredParam); 977 978 Vector3 lightDir = -light->GetDirection(); 979 cgGLSetParameter3f(sLightDirParam, lightDir.x, lightDir.y, lightDir.z); 980 981 Vector3 tl, tr, bl, br; 982 ComputeViewVectors(tl, tr, bl, br); 983 984 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 985 const float offs = 0.5f; 986 987 glBegin(GL_QUADS); 988 989 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 990 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 991 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 992 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 993 994 glEnd(); 995 996 cgGLDisableTextureParameter(sColorsTexDeferredParam); 997 cgGLDisableTextureParameter(sPositionsTexDeferredParam); 998 cgGLDisableTextureParameter(sNormalsTexDeferredParam); 569 570 const Vector3 lightDir = -light->GetDirection(); 571 572 sCgDeferredProgram->SetTexture("colors", colorsTex); 573 sCgDeferredProgram->SetTexture("normals", normalsTex); 574 sCgDeferredProgram->SetValue3f("lightDir", lightDir.x, lightDir.y, lightDir.z); 575 576 DrawQuad(sCgDeferredProgram); 999 577 1000 578 PrintGLerror("deferred shading"); 1001 579 } 1002 1003 580 1004 581 … … 1008 585 const Matrix4x4 &oldProjViewMatrix) 1009 586 { 1010 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixGiParam, (const float *)oldProjViewMatrix.x);1011 cgGLSetMatrixParameterfc(sModelViewProjMatrixGiParam, (const float *)projViewMatrix.x);587 sCgGiProgram->SetMatrix("oldModelViewProj", oldProjViewMatrix); 588 sCgGiProgram->SetMatrix("modelViewProj", projViewMatrix); 1012 589 1013 590 #if 0 … … 1030 607 GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 1031 608 1032 cgGLBindProgram(sCgGiProgram); 1033 1034 1035 cgGLSetTextureParameter(sColorsTexGiParam, colorsTex); 1036 cgGLEnableTextureParameter(sColorsTexGiParam); 1037 1038 cgGLSetTextureParameter(sNormalsTexGiParam, normalsTex); 1039 cgGLEnableTextureParameter(sNormalsTexGiParam); 1040 1041 cgGLSetTextureParameter(sNoiseTexGiParam, noiseTex); 1042 cgGLEnableTextureParameter(sNoiseTexGiParam); 1043 1044 cgGLSetTextureParameter(sOldSsaoTexGiParam, oldSsaoTex); 1045 cgGLEnableTextureParameter(sOldSsaoTexGiParam); 1046 1047 cgGLSetTextureParameter(sOldIllumTexGiParam, oldIllumTex); 1048 cgGLEnableTextureParameter(sOldIllumTexGiParam); 1049 1050 1051 cgGLSetParameter1f(sTemporalCoherenceGiParam, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 1052 609 610 sCgGiProgram->SetTexture("colors", colorsTex); 611 sCgGiProgram->SetTexture("normals", normalsTex); 612 sCgGiProgram->SetTexture("noise", noiseTex); 613 sCgGiProgram->SetTexture("oldSsaoTex", oldSsaoTex); 614 sCgGiProgram->SetTexture("oldIllumTex", oldIllumTex); 615 616 sCgGiProgram->SetValue1f("temporalCoherence", 617 (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 1053 618 1054 619 if (mUseTemporalCoherence || mRegenerateSamples) … … 1061 626 GenerateSamples(mSamplingMethod); 1062 627 1063 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples2);628 sCgGiProgram->SetArray2f("samples", (float *)samples2, NUM_SAMPLES); 1064 629 } 1065 630 … … 1069 634 1070 635 const Vector3 pos = mCamera->GetPosition(); 1071 cgGLSetParameter3f(sEyePosGiParam, pos.x, pos.y, pos.z); 1072 1073 cgGLSetParameter3f(sBLGiParam, bl.x, bl.y, bl.z); 1074 cgGLSetParameter3f(sBRGiParam, br.x, br.y, br.z); 1075 cgGLSetParameter3f(sTLGiParam, tl.x, tl.y, tl.z); 1076 cgGLSetParameter3f(sTRGiParam, tr.x, tr.y, tr.z); 1077 1078 1079 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 1080 const float offs = 0.5f; 1081 1082 glBegin(GL_QUADS); 1083 1084 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 1085 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 1086 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 1087 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 1088 1089 glEnd(); 1090 1091 cgGLDisableTextureParameter(sColorsTexGiParam); 1092 cgGLDisableTextureParameter(sNormalsTexGiParam); 1093 cgGLDisableTextureParameter(sNoiseTexGiParam); 1094 cgGLDisableTextureParameter(sOldSsaoTexGiParam); 1095 cgGLDisableTextureParameter(sOldIllumTexGiParam); 636 sCgGiProgram->SetValue3f("eyePos", pos.x, pos.y, pos.z); 637 638 sCgGiProgram->SetValue3f("bl", bl.x, bl.y, bl.z); 639 sCgGiProgram->SetValue3f("br", br.x, br.y, br.z); 640 sCgGiProgram->SetValue3f("tl", tl.x, tl.y, tl.z); 641 sCgGiProgram->SetValue3f("tr", tr.x, tr.y, tr.z); 642 643 DrawQuad(sCgGiProgram); 1096 644 1097 645 glPopAttrib(); … … 1116 664 glDrawBuffers(1, mrt + colorBufferIdx); 1117 665 1118 cgGLBindProgram(sCgCombinedIllumProgram); 1119 1120 1121 cgGLSetTextureParameter(sColorsTexCombinedIllumParam, colorsTex); 1122 cgGLEnableTextureParameter(sColorsTexCombinedIllumParam); 1123 1124 cgGLSetTextureParameter(sSsaoTexCombinedIllumParam, ssaoTex); 1125 cgGLEnableTextureParameter(sSsaoTexCombinedIllumParam); 1126 1127 cgGLSetTextureParameter(sIllumTexCombinedIllumParam, illumTex); 1128 cgGLEnableTextureParameter(sIllumTexCombinedIllumParam); 1129 1130 glColor3f(1.0f, 1.0f, 1.0f); 1131 1132 const float offs = 0.5f; 1133 1134 glBegin(GL_QUADS); 1135 1136 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 1137 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 1138 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 1139 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 1140 1141 glEnd(); 1142 1143 cgGLDisableTextureParameter(sColorsTexCombinedIllumParam); 1144 cgGLDisableTextureParameter(sSsaoTexCombinedIllumParam); 1145 cgGLDisableTextureParameter(sIllumTexCombinedIllumParam); 666 sCgCombineIllumProgram->SetTexture("colors", colorsTex); 667 sCgCombineIllumProgram->SetTexture("ssaoTex", ssaoTex); 668 sCgCombineIllumProgram->SetTexture("illumTex", illumTex); 669 670 DrawQuad(sCgCombineIllumProgram); 1146 671 1147 672 PrintGLerror("combine"); … … 1162 687 glDrawBuffers(1, mrt + colorBufferIdx); 1163 688 1164 cgGLBindProgram(sCgCombinedSsaoProgram);1165 1166 689 float filterOffsets[NUM_DOWNSAMPLES * 2]; 1167 690 float filterWeights[NUM_DOWNSAMPLES]; … … 1185 708 1186 709 //ComputeSampleOffsets(filterOffsets, fbo->GetWidth(), fbo->GetHeight()); 1187 cgGLSetParameterArray2f(sFilterOffsetsParam, 0, NUM_DOWNSAMPLES, (const float *)filterOffsets); 1188 cgGLSetParameterArray1f(sFilterWeightsParam, 0, NUM_DOWNSAMPLES, (const float *)filterWeights); 1189 1190 cgGLSetTextureParameter(sColorsTexCombinedSsaoParam, colorsTex); 1191 cgGLEnableTextureParameter(sColorsTexCombinedSsaoParam); 1192 1193 cgGLSetTextureParameter(sSsaoTexCombinedSsaoParam, ssaoTex); 1194 cgGLEnableTextureParameter(sSsaoTexCombinedSsaoParam); 1195 1196 1197 glColor3f(1.0f, 1.0f, 1.0f); 1198 1199 const float offs = 0.5f; 1200 1201 glBegin(GL_QUADS); 1202 1203 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 1204 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 1205 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 1206 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 1207 1208 glEnd(); 1209 1210 cgGLDisableTextureParameter(sColorsTexCombinedSsaoParam); 1211 cgGLDisableTextureParameter(sSsaoTexCombinedSsaoParam); 710 sCgCombineSsaoProgram->SetArray2f("filterOffs", (float *)filterOffsets, NUM_DOWNSAMPLES); 711 sCgCombineSsaoProgram->SetArray1f("filterWeights", (float *)filterWeights, NUM_DOWNSAMPLES); 712 713 sCgCombineSsaoProgram->SetTexture("colors", colorsTex); 714 sCgCombineSsaoProgram->SetTexture("ssaoTex", ssaoTex); 715 716 DrawQuad(sCgCombineSsaoProgram); 1212 717 1213 718 PrintGLerror("combine ssao"); … … 1233 738 glDrawBuffers(1, mrt + colorBufferIdx); 1234 739 1235 1236 cgGLBindProgram(sCgDeferredShadowProgram); 1237 1238 cgGLSetTextureParameter(sColorsTexShadowParam, colorsTex); 1239 cgGLEnableTextureParameter(sColorsTexShadowParam); 1240 1241 cgGLSetTextureParameter(sPositionsTexShadowParam, positionsTex); 1242 cgGLEnableTextureParameter(sPositionsTexShadowParam); 1243 1244 cgGLSetTextureParameter(sNormalsTexShadowParam, normalsTex); 1245 cgGLEnableTextureParameter(sNormalsTexShadowParam); 1246 1247 cgGLSetTextureParameter(sShadowMapParam, shadowTex); 1248 cgGLEnableTextureParameter(sShadowMapParam); 1249 1250 cgGLSetParameter1f(sSampleWidthParam, 2.0f / shadowMap->GetSize()); 1251 1252 1253 cgGLSetMatrixParameterfc(sShadowMatrixParam, (const float *)shadowMatrix.x); 1254 1255 cgGLSetTextureParameter(sNoiseTexShadowParam, noiseTex); 1256 cgGLEnableTextureParameter(sNoiseTexShadowParam); 1257 1258 Vector3 lightDir = -light->GetDirection(); 1259 cgGLSetParameter3f(sLightDirShadowParam, lightDir.x, lightDir.y, lightDir.z); 1260 1261 Vector3 tl, tr, bl, br; 1262 ComputeViewVectors(tl, tr, bl, br); 1263 740 741 sCgDeferredShadowProgram->SetTexture("colors", colorsTex); 742 sCgDeferredShadowProgram->SetTexture("normals", normalsTex); 743 sCgDeferredShadowProgram->SetTexture("shadowMap", shadowTex); 744 sCgDeferredShadowProgram->SetTexture("noise", noiseTex); 745 sCgDeferredShadowProgram->SetMatrix("shadowMatrix", shadowMatrix); 746 sCgDeferredShadowProgram->SetValue1f("sampleWidth", 2.0f / shadowMap->GetSize()); 747 748 const Vector3 lightDir = -light->GetDirection(); 749 sCgDeferredShadowProgram->SetValue3f("lightDir", lightDir.x, lightDir.y, lightDir.z); 750 1264 751 const Vector3 pos = mCamera->GetPosition(); 1265 cgGLSetParameter3f(sEyePosShadowParam, pos.x, pos.y, pos.z); 1266 1267 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 1268 const float offs = 0.5f; 1269 1270 glBegin(GL_QUADS); 1271 1272 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 1273 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 1274 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 1275 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 1276 1277 glEnd(); 1278 1279 cgGLDisableTextureParameter(sColorsTexShadowParam); 1280 cgGLDisableTextureParameter(sPositionsTexShadowParam); 1281 cgGLDisableTextureParameter(sNormalsTexShadowParam); 1282 cgGLDisableTextureParameter(sShadowMapParam); 1283 cgGLDisableTextureParameter(sNoiseTexShadowParam); 752 sCgDeferredShadowProgram->SetValue3f("eyePos", pos.x, pos.y, pos.z); 753 754 DrawQuad(sCgDeferredShadowProgram); 1284 755 1285 756 PrintGLerror("deferred shading + shadows"); … … 1337 808 glDrawBuffers(1, mrt + colorBufferIdx); 1338 809 1339 cgGLBindProgram(sCgLogLumProgram); 1340 1341 cgGLSetTextureParameter(sColorsTexLogLumParam, colorsTex); 1342 cgGLEnableTextureParameter(sColorsTexLogLumParam); 1343 1344 const float offs = 0.5f; 1345 1346 glBegin(GL_QUADS); 1347 1348 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 1349 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 1350 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 1351 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 1352 1353 glEnd(); 1354 1355 cgGLDisableTextureParameter(sColorsTexLogLumParam); 1356 810 sCgLogLumProgram->SetTexture("colors", colorsTex); 811 DrawQuad(sCgLogLumProgram); 812 1357 813 PrintGLerror("ToneMapParams"); 1358 814 … … 1404 860 glPushAttrib(GL_VIEWPORT_BIT); 1405 861 glViewport(0, 0, downSampleFbo->GetWidth(), downSampleFbo->GetHeight()); 1406 1407 cgGLBindProgram(sCgDownSampleProgram); 1408 1409 cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex); 1410 cgGLEnableTextureParameter(sColorsTexDownSampleParam); 862 863 sCgDownSampleProgram->SetTexture("colors", colorsTex); 1411 864 1412 865 float downSampleOffsets[NUM_DOWNSAMPLES * 2]; 1413 866 ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight()); 1414 867 1415 cgGLSetParameterArray2f(sDownSampleOffsetParam, 0, NUM_DOWNSAMPLES, (const float *)downSampleOffsets);868 sCgDownSampleProgram->SetArray2f("downSampleOffs", (float *)downSampleOffsets, NUM_DOWNSAMPLES); 1416 869 1417 870 mDownSampleFbo->Bind(); 1418 871 glDrawBuffers(1, mrt + downSampleBufferIdx); 1419 872 1420 cgGLBindProgram(sCgDownSampleProgram); 1421 1422 const float offs = 0.5f; 1423 1424 glBegin(GL_QUADS); 1425 1426 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 1427 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 1428 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 1429 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 1430 1431 glEnd(); 1432 1433 cgGLDisableTextureParameter(sColorsTexDownSampleParam); 1434 1435 /*float *data = (float *)mDownSampleFbo->GetColorBuffer(0)->ReadTexture(); 1436 ExportData(data, mWidth / 2, mHeight / 2); 1437 delete [] data;*/ 1438 873 DrawQuad(sCgDownSampleProgram); 874 1439 875 glPopAttrib(); 1440 876 … … 1456 892 glDrawBuffers(1, mrt + colorBufferIdx); 1457 893 1458 cgGLBindProgram(sCgToneProgram); 1459 1460 cgGLSetTextureParameter(sColorsTexToneParam, colorsTex); 1461 cgGLEnableTextureParameter(sColorsTexToneParam); 1462 1463 cgGLSetParameter1f(sImageKeyParam, imageKey); 1464 cgGLSetParameter1f(sWhiteLumParam, whiteLum); 1465 cgGLSetParameter1f(sMiddleGreyParam, middleGrey); 1466 1467 glColor3f(1.0f, 1.0f, 1.0f); 1468 1469 1470 glBegin(GL_QUADS); 1471 1472 const float offs = 0.5f; 1473 1474 1475 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 1476 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 1477 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 1478 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 1479 1480 glEnd(); 1481 1482 cgGLDisableTextureParameter(sColorsTexToneParam); 894 sCgToneProgram->SetTexture("colors", colorsTex); 895 sCgToneProgram->SetValue1f("imageKey", imageKey); 896 sCgToneProgram->SetValue1f("whiteLum", whiteLum); 897 sCgToneProgram->SetValue1f("middleGrey", middleGrey); 898 899 DrawQuad(sCgToneProgram); 1483 900 1484 901 PrintGLerror("ToneMap"); … … 1486 903 1487 904 1488 1489 1490 905 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3021 r3026 107 107 FrameBufferObject *downSampleFbo, int downSampleBufferIdx); 108 108 109 void DrawQuad(ShaderProgram *p); 110 111 static bool InitProgram(ShaderProgram **program, 112 CGcontext context, 113 const std::string &filename, 114 const std::string &functionName); 115 109 116 110 117 //////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3023 r3026 322 322 int main(int argc, char* argv[]) 323 323 { 324 /* 324 325 #ifdef _CRT_SET 325 326 … … 334 335 _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 335 336 #endif 336 337 */ 337 338 cout << "=== reading environment file ===" << endl << endl; 338 339 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r2976 r3026 12 12 }; 13 13 14 // the barrier for detecting a discontinuity 15 uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0); // x = normal, y = depth16 // the weights for normal / depth discontinuity 17 uniform float4 e_weights = float4(0.5f, 0.5f, 1.0f, 1.0f); // x = normal, y = depth18 //uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth14 // the barrier for detecting a discontinuity (x = normal, y = depth) 15 uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0); 16 // the weights for normal / depth discontinuity (x = normal, y = depth) 17 uniform float4 e_weights = float4(0.5f, 0.5f, 1.0f, 1.0f); 18 //uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f); 19 19 uniform float4 e_kernel = float4(0.5f, 1.0f, 1.0f, 1.0f); 20 20 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3025 r3026 61 61 pixel main(fragment IN, 62 62 uniform sampler2D colors, 63 uniform sampler2D positions,64 63 uniform sampler2D normals, 65 64 uniform float3 lightDir … … 151 150 uniform float4x4 shadowMatrix, 152 151 uniform float sampleWidth, 153 uniform sampler2D noise Texture,152 uniform sampler2D noise, 154 153 uniform float2 samples[NUM_PCF_TABS], 155 154 uniform float weights[NUM_PCF_TABS], … … 199 198 lightSpacePos /= lightSpacePos.w; 200 199 201 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noise Texture);202 //float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noise Texture);200 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noise); 201 //float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noise); 203 202 204 203 diffuse *= shadowTerm; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3019 r3026 61 61 uniform float3 currentNormal, 62 62 uniform float3 centerPosition, 63 float w,63 float scaleFactor, 64 64 uniform float3 bl, 65 65 uniform float3 br, … … 96 96 #endif 97 97 // weight with projected coordinate to reach similar kernel size for near and far 98 float2 texcoord = IN.texCoord.xy + offsetTransformed * w;98 float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 99 99 100 100 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; … … 151 151 uniform sampler2D colors, 152 152 uniform sampler2D normals, 153 uniform sampler2D noise Texture,153 uniform sampler2D noise, 154 154 uniform float2 samples[NUM_SAMPLES], 155 155 uniform sampler2D oldSsaoTex, … … 191 191 //-- compute color bleeding + ao 192 192 193 GiStruct gi = globIllum(IN, colors, noise Texture, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view));193 GiStruct gi = globIllum(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view)); 194 194 195 195 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3019 r3026 137 137 uniform sampler2D colors, 138 138 uniform sampler2D normals, 139 uniform sampler2D noise Texture,139 uniform sampler2D noise, 140 140 uniform float2 samples[NUM_SAMPLES], 141 141 uniform sampler2D oldTex, … … 161 161 const float3 centerPosition = eyePos + eyeSpacePos; 162 162 163 float4 realPos = float4(centerPosition, 1.0f);163 const float4 realPos = float4(centerPosition, 1.0f); 164 164 165 165 … … 174 174 const float currentDepth = currentPos.z * 1e-3f; 175 175 176 const float2 ao = ssao(IN, colors, noise Texture, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir));176 const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 177 177 178 178 … … 202 202 203 203 //const float oldNumSamples = oldCol.y; 204 const float oldWeight = clamp(oldCol.y, 0, temporalCoherence);204 const float oldWeight = 50;//clamp(oldCol.y, 0, temporalCoherence); 205 205 206 206 float newWeight; … … 209 209 //const float newNumSamples = ao.y; 210 210 211 if ( //(temporalCoherence > 0) &&211 if ((temporalCoherence > 0) && 212 212 (tex.x >= 0.0f) && (tex.x < 1.0f) && 213 213 (tex.y >= 0.0f) && (tex.y < 1.0f) && … … 228 228 } 229 229 230 //OUT.illum_col.y=depthDif;231 230 OUT.illum_col.y = newWeight; 232 231 OUT.illum_col.z = currentDepth; … … 269 268 float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 270 269 271 if (ao.y < 2000.0f)272 ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);270 //if (ao.y < 2000.0f) 271 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 273 272 274 273 OUT.illum_col = col * ao.x;
Note: See TracChangeset
for help on using the changeset viewer.