Changeset 2880 for GTP/trunk/App
- Timestamp:
- 08/28/08 22:37:40 (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/SsaoShader.cpp
r2879 r2880 23 23 static CGprogram sCgDeferredProgram = NULL; 24 24 static CGprogram sCgAntiAliasingProgram = NULL; 25 static CGprogram sCgCombineProgram = NULL;26 25 27 26 static CGparameter sColorsTexCombineParam; … … 32 31 static CGparameter sNormalsTexDeferredParam; 33 32 33 34 static CGprogram sCgCombinedSsaoProgram = NULL; 35 static CGprogram sCgCombinedIllumProgram = NULL; 34 36 35 37 ///////////////////////////////////////7 … … 67 69 68 70 71 static CGparameter sColorsTexCombinedIllumParam; 72 static CGparameter sSsaoTexCombinedIllumParam; 73 static CGparameter sIllumTexCombinedIllumParam; 74 75 static CGparameter sColorsTexCombinedSsaoParam; 76 static CGparameter sSsaoTexCombinedSsaoParam; 77 78 69 79 //////////// 70 80 … … 157 167 //-- the flip-flop fbos 158 168 169 w = 256; h = 256; 159 170 mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 171 160 172 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 161 173 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 162 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);163 174 164 175 mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 165 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);176 166 177 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 167 178 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); … … 299 310 cerr << "globillum program failed to load" << endl; 300 311 312 sCgCombinedIllumProgram = 313 cgCreateProgramFromFile(context, 314 CG_SOURCE, 315 "src/shaders/globillum.cg", 316 RenderState::sCgFragmentProfile, 317 "combine", 318 NULL); 319 320 if (sCgCombinedIllumProgram != NULL) 321 { 322 cgGLLoadProgram(sCgCombinedIllumProgram); 323 324 sColorsTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "colors"); 325 sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex"); 326 sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex"); 327 } 328 else 329 cerr << "combined illum program failed to load" << endl; 330 331 332 sCgCombinedSsaoProgram = 333 cgCreateProgramFromFile(context, 334 CG_SOURCE, 335 "src/shaders/ssao.cg", 336 RenderState::sCgFragmentProfile, 337 "combine", 338 NULL); 339 340 if (sCgCombinedSsaoProgram != NULL) 341 { 342 cgGLLoadProgram(sCgCombinedSsaoProgram); 343 344 sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors"); 345 sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex"); 346 } 347 else 348 cerr << "combied illum program failed to load" << endl; 349 350 301 351 sCgAntiAliasingProgram = 302 352 cgCreateProgramFromFile(context, … … 317 367 cerr << "antialiasing program failed to load" << endl; 318 368 319 320 369 PrintGLerror("init"); 321 370 } … … 333 382 swap(mNewFbo, mOldFbo); 334 383 335 336 glPushAttrib(GL_VIEWPORT_BIT);337 glViewport(0, 0, mWidth, mHeight);338 339 384 FrameBufferObject::Release(); 340 385 … … 345 390 glDisable(GL_LIGHTING); 346 391 392 glPushAttrib(GL_VIEWPORT_BIT); 393 glViewport(0, 0, mWidth, mHeight); 394 347 395 glMatrixMode(GL_PROJECTION); 348 396 glPushMatrix(); … … 359 407 360 408 if (!mUseGlobIllum) 409 { 361 410 ComputeSsao(fbo, expFactor, oldProjViewMatrix); 411 CombineSsao(fbo); 412 } 362 413 else 414 { 363 415 ComputeGlobIllum(fbo, expFactor, oldProjViewMatrix); 364 416 CombineIllum(fbo); 417 } 365 418 AntiAliasing(fbo); 366 419 … … 402 455 // read the second buffer, write to the first buffer 403 456 mNewFbo->Bind(); 404 glDrawBuffers(2, mymrt); 457 glDrawBuffers(1, mymrt); 458 459 glPushAttrib(GL_VIEWPORT_BIT); 460 glViewport(0, 0, 256, 256); 461 462 glMatrixMode(GL_PROJECTION); 463 glPushMatrix(); 464 glLoadIdentity(); 465 466 glMatrixMode(GL_MODELVIEW); 467 glPushMatrix(); 468 glLoadIdentity(); 469 470 const float offs = 0.5f; 471 glOrtho(-offs, offs, -offs, offs, 0, 1); 472 405 473 406 474 GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); … … 469 537 cgGLDisableTextureParameter(sOldTexParam); 470 538 539 glMatrixMode(GL_PROJECTION); 540 glPopMatrix(); 541 542 glMatrixMode(GL_MODELVIEW); 543 glPopMatrix(); 544 545 glPopAttrib(); 546 471 547 FrameBufferObject::Release(); 472 548 … … 523 599 void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 524 600 { 525 GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 601 //GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 602 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 526 603 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 527 604 … … 637 714 // read the second buffer, write to the first buffer 638 715 mNewFbo->Bind(); 639 glDrawBuffers( 3, mymrt);716 glDrawBuffers(2, mymrt); 640 717 641 718 GLuint oldSsaoTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 642 GLuint oldIllumTex = mOldFbo->GetColorBuffer( 2)->GetTexture();719 GLuint oldIllumTex = mOldFbo->GetColorBuffer(1)->GetTexture(); 643 720 644 721 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 716 793 717 794 795 void SsaoShader::CombineIllum(FrameBufferObject *fbo) 796 { 797 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 798 GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 799 GLuint illumTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 800 801 // 802 fbo->Bind(); 803 804 // write into old color texture (not needed anymore) 805 glDrawBuffers(1, mymrt); 806 807 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 808 809 cgGLEnableProfile(RenderState::sCgFragmentProfile); 810 811 cgGLBindProgram(sCgCombinedIllumProgram); 812 813 cgGLSetTextureParameter(sColorsTexCombinedIllumParam, colorsTex); 814 cgGLEnableTextureParameter(sColorsTexCombinedIllumParam); 815 816 cgGLSetTextureParameter(sSsaoTexCombinedIllumParam, ssaoTex); 817 cgGLEnableTextureParameter(sSsaoTexCombinedIllumParam); 818 819 cgGLSetTextureParameter(sIllumTexCombinedIllumParam, illumTex); 820 cgGLEnableTextureParameter(sIllumTexCombinedIllumParam); 821 822 glColor3f(1.0f, 1.0f, 1.0f); 823 824 const float offs = 0.5f; 825 826 glBegin(GL_QUADS); 827 828 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 829 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 830 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 831 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 832 833 glEnd(); 834 835 cgGLDisableTextureParameter(sColorsTexCombinedIllumParam); 836 cgGLDisableTextureParameter(sSsaoTexCombinedIllumParam); 837 cgGLDisableTextureParameter(sIllumTexCombinedIllumParam); 838 839 cgGLDisableProfile(RenderState::sCgFragmentProfile); 840 841 FrameBufferObject::Release(); 842 843 PrintGLerror("combine"); 844 } 845 846 847 void SsaoShader::CombineSsao(FrameBufferObject *fbo) 848 { 849 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 850 GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 851 852 // 853 fbo->Bind(); 854 855 // write into old color texture (not needed anymore) 856 glDrawBuffers(1, mymrt); 857 858 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 859 860 cgGLEnableProfile(RenderState::sCgFragmentProfile); 861 862 cgGLBindProgram(sCgCombinedSsaoProgram); 863 864 cgGLSetTextureParameter(sColorsTexCombinedSsaoParam, colorsTex); 865 cgGLEnableTextureParameter(sColorsTexCombinedSsaoParam); 866 867 cgGLSetTextureParameter(sSsaoTexCombinedSsaoParam, ssaoTex); 868 cgGLEnableTextureParameter(sSsaoTexCombinedSsaoParam); 869 870 871 glColor3f(1.0f, 1.0f, 1.0f); 872 873 const float offs = 0.5f; 874 875 glBegin(GL_QUADS); 876 877 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 878 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 879 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 880 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 881 882 glEnd(); 883 884 cgGLDisableTextureParameter(sColorsTexCombinedSsaoParam); 885 cgGLDisableTextureParameter(sSsaoTexCombinedSsaoParam); 886 887 cgGLDisableProfile(RenderState::sCgFragmentProfile); 888 889 FrameBufferObject::Release(); 890 891 PrintGLerror("combine ssao"); 892 } 893 894 895 718 896 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
r2879 r2880 56 56 void FirstPass(FrameBufferObject *fbo); 57 57 58 void CombineSsao(FrameBufferObject *fbo); 59 void CombineIllum(FrameBufferObject *fbo); 60 58 61 void AntiAliasing(FrameBufferObject *fbo); 59 62 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2876 r2880 32 32 { 33 33 float4 ssao_col: COLOR0; 34 float4 combined_col: COLOR1; 35 float4 illum_col: COLOR2; 34 float4 illum_col: COLOR1; 36 35 }; 37 36 … … 185 184 } 186 185 187 OUT.combined_col = (currentCol + OUT.illum_col) * OUT.ssao_col.x;188 //OUT.combined_col = float4(newDepth, oldDepth, 1, 1) ;189 190 186 OUT.ssao_col.w = currentDepth; 191 187 192 188 return OUT; 193 189 } 190 191 192 pixel combine(fragment IN, 193 uniform sampler2D colors, 194 uniform sampler2D ssaoTex, 195 uniform sampler2D illumTex 196 ) 197 { 198 pixel OUT; 199 200 float4 col = tex2D(colors, IN.texCoord.xy); 201 float ao = tex2D(ssaoTex, IN.texCoord.xy).x; 202 float4 illum = tex2D(illumTex, IN.texCoord.xy); 203 204 OUT.illum_col = (col + illum) * ao; 205 206 return OUT; 207 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2876 r2880 29 29 { 30 30 float4 illum_col: COLOR0; 31 float4 combined_col: COLOR1;32 31 }; 33 32 … … 173 172 } 174 173 175 OUT.combined_col = currentCol * OUT.illum_col.x;176 174 OUT.illum_col.w = currentDepth; 177 175 178 176 return OUT; 179 177 } 178 179 180 181 pixel combine(fragment IN, 182 uniform sampler2D colors, 183 uniform sampler2D ssaoTex) 184 { 185 pixel OUT; 186 187 float4 col = tex2D(colors, IN.texCoord.xy); 188 float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 189 190 OUT.illum_col = col * ao.x; 191 192 return OUT; 193 }
Note: See TracChangeset
for help on using the changeset viewer.