- Timestamp:
- 08/26/08 16:27:11 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2867 r2868 19 19 20 20 static CGprogram sCgSsaoProgram = NULL; 21 static CGprogram sCgDeferredProgram2 = NULL; 22 static CGprogram sCgAntiAliasingProgram = NULL; 23 24 static CGparameter sColorsTexDeferredParam; 25 static CGparameter sPositionsTexDeferredParam; 26 static CGparameter sNormalsTexDeferredParam; 21 27 22 28 static CGparameter sColorsTexParam; 23 29 static CGparameter sPositionsTexParam; 24 30 static CGparameter sNormalsTexParam; 31 32 25 33 static CGparameter sOldModelViewProjMatrixParam; 26 34 static CGparameter sMaxDepthParam; … … 30 38 static CGparameter sNoiseMultiplierParam; 31 39 static CGparameter sExpFactorParam; 32 static CGprogram sCgAntiAliasingProgram;33 40 34 41 static CGparameter sColorsTexAntiAliasingParam; … … 81 88 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 82 89 90 mFbo3 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 91 // the diffuse color buffer 92 mFbo3->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 93 83 94 84 95 // create noise texture for ssao … … 101 112 void SsaoShader::Init(CGcontext context) 102 113 { 103 /////////////// 104 105 sCgSsaoProgram = 114 sCgDeferredProgram2 = 106 115 cgCreateProgramFromFile(context, 107 116 CG_SOURCE, 108 117 "src/shaders/deferred.cg", 109 118 RenderState::sCgFragmentProfile, 110 "main_ssao", 119 "main2", 120 NULL); 121 122 if (sCgDeferredProgram2 != NULL) 123 { 124 cgGLLoadProgram(sCgDeferredProgram2); 125 126 // we need size of texture for scaling 127 sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram2, "positions"); 128 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram2, "colors"); 129 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram2, "normals"); 130 } 131 else 132 cerr << "deferred program failed to load" << endl; 133 134 135 /////////////// 136 137 sCgSsaoProgram = 138 cgCreateProgramFromFile(context, 139 CG_SOURCE, 140 "src/shaders/ssao.cg", 141 RenderState::sCgFragmentProfile, 142 "main", 111 143 NULL); 112 144 … … 121 153 sNoiseTexParam = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture"); 122 154 sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier"); 155 123 156 sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 124 157 sMaxDepthParam = cgGetNamedParameter(sCgSsaoProgram, "maxDepth"); … … 162 195 float expFactor) 163 196 { 164 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 165 166 glPushAttrib(GL_VIEWPORT_BIT); 167 glViewport(0, 0, mWidth, mHeight); 168 169 glDrawBuffers(1, mymrt); 170 171 cgGLEnableProfile(RenderState::sCgFragmentProfile); 172 173 glDisable(GL_ALPHA_TEST); 174 glDisable(GL_TEXTURE_2D); 175 glDisable(GL_LIGHTING); 176 177 glMatrixMode(GL_PROJECTION); 178 glPushMatrix(); 179 glLoadIdentity(); 180 181 glMatrixMode(GL_MODELVIEW); 182 glPushMatrix(); 183 glLoadIdentity(); 184 185 const float offs = 0.5f; 186 glOrtho(-offs, offs, -offs, offs, 0, 1); 187 197 188 198 // switch roles of old and new fbo 189 199 // the algorihm uses two input fbos, where the one … … 192 202 swap(mNewFbo, mOldFbo); 193 203 204 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 205 206 glPushAttrib(GL_VIEWPORT_BIT); 207 glViewport(0, 0, mWidth, mHeight); 208 209 FrameBufferObject::Release(); 210 211 glDrawBuffers(1, mymrt); 212 213 cgGLEnableProfile(RenderState::sCgFragmentProfile); 214 215 glDisable(GL_ALPHA_TEST); 216 glDisable(GL_TEXTURE_2D); 217 glDisable(GL_LIGHTING); 218 219 glMatrixMode(GL_PROJECTION); 220 glPushMatrix(); 221 glLoadIdentity(); 222 223 glMatrixMode(GL_MODELVIEW); 224 glPushMatrix(); 225 glLoadIdentity(); 226 227 const float offs = 0.5f; 228 glOrtho(-offs, offs, -offs, offs, 0, 1); 229 230 FirstPass(fbo); 194 231 ComputeSsao(fbo, expFactor); 195 // the second pass just renders the combined solution196 //DisplayTexture();197 232 AntiAliasing(fbo); 198 233 … … 214 249 void SsaoShader::ComputeSsao(FrameBufferObject *fbo, float expFactor) 215 250 { 216 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture();251 GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 217 252 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 218 253 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); … … 228 263 // read the second buffer, write to the first buffer 229 264 mNewFbo->Bind(); 265 glDrawBuffers(1, mymrt); 266 230 267 GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 231 268 232 glDrawBuffers(1, mymrt);233 234 269 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 235 270 271 cgGLEnableProfile(RenderState::sCgFragmentProfile); 236 272 cgGLBindProgram(sCgSsaoProgram); 237 273 … … 385 421 386 422 cgGLEnableProfile(RenderState::sCgFragmentProfile); 387 388 423 cgGLBindProgram(sCgAntiAliasingProgram); 389 424 390 425 cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex); 391 426 cgGLEnableTextureParameter(sColorsTexAntiAliasingParam); … … 393 428 cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 394 429 cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 395 430 396 431 glColor3f(1.0f, 1.0f, 1.0f); 397 432 … … 418 453 419 454 455 void SsaoShader::FirstPass(FrameBufferObject *fbo) 456 { 457 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 458 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 459 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 460 461 mFbo3->Bind(); 462 //mNewFbo->Bind(); 463 464 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 465 466 glDrawBuffers(1, mymrt); 467 468 cgGLEnableProfile(RenderState::sCgFragmentProfile); 469 470 cgGLBindProgram(sCgDeferredProgram2); 471 472 cgGLSetTextureParameter(sColorsTexDeferredParam, colorsTex); 473 cgGLEnableTextureParameter(sColorsTexDeferredParam); 474 475 cgGLSetTextureParameter(sPositionsTexDeferredParam, positionsTex); 476 cgGLEnableTextureParameter(sPositionsTexDeferredParam); 477 478 cgGLSetTextureParameter(sNormalsTexDeferredParam, normalsTex); 479 cgGLEnableTextureParameter(sNormalsTexDeferredParam); 480 481 glColor3f(1.0f, 1.0f, 1.0f); 482 483 const float offs = 0.5f; 484 485 glBegin(GL_QUADS); 486 487 glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 488 glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 489 glTexCoord2f(1, 1); glVertex3f( offs, offs, -0.5f); 490 glTexCoord2f(0, 1); glVertex3f(-offs, offs, -0.5f); 491 492 glEnd(); 493 494 cgGLDisableTextureParameter(sColorsTexDeferredParam); 495 cgGLDisableTextureParameter(sPositionsTexDeferredParam); 496 cgGLDisableTextureParameter(sNormalsTexDeferredParam); 497 498 cgGLDisableProfile(RenderState::sCgFragmentProfile); 499 500 FrameBufferObject::Release(); 501 502 PrintGLerror("deferred shading"); 503 } 504 420 505 } // namespace
Note: See TracChangeset
for help on using the changeset viewer.