- Timestamp:
- 08/25/08 17:34:34 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2863 r2865 30 30 static CGparameter sNoiseMultiplierParam; 31 31 static CGparameter sExpFactorParam; 32 static CGprogram sCgAntiAliasingProgram; 33 34 static CGparameter sColorsTexAntiAliasingParam; 35 static CGparameter sNormalsTexAntiAliasingParam; 36 32 37 33 38 static GLuint noiseTex; … … 133 138 cerr << "ssao program failed to load" << endl; 134 139 140 sCgAntiAliasingProgram = 141 cgCreateProgramFromFile(context, 142 CG_SOURCE, 143 "src/shaders/antialiasing.cg", 144 RenderState::sCgFragmentProfile, 145 "main", 146 NULL); 147 148 if (sCgAntiAliasingProgram != NULL) 149 { 150 cgGLLoadProgram(sCgAntiAliasingProgram); 151 152 sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors"); 153 sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 154 } 155 else 156 cerr << "antialiasing program failed to load" << endl; 157 158 135 159 PrintGLerror("init"); 136 160 } … … 151 175 ComputeSsao(fbo, expFactor); 152 176 // the second pass just renders the combined solution 153 DisplayTexture(); 177 //DisplayTexture(); 178 AntiAliasing(fbo); 154 179 } 155 180 … … 213 238 214 239 215 GenerateSamples();240 //GenerateSamples(); 216 241 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 217 242 … … 259 284 260 285 261 void SsaoShader::DisplayTexture()286 /*void SsaoShader::DisplayTexture() 262 287 { 263 288 glEnable(GL_TEXTURE_2D); … … 300 325 301 326 PrintGLerror("ssao second pass"); 302 } 327 }*/ 303 328 304 329 … … 370 395 371 396 397 398 static void SetVertex(float x, float y, float x_offs, float y_offs) 399 { 400 glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center 401 glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top 402 glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom 403 glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top 404 glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom 405 406 glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right 407 glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom 408 409 glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 410 } 411 412 413 void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 414 { 415 GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 416 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 417 418 glPushAttrib(GL_VIEWPORT_BIT); 419 glViewport(0, 0, mWidth, mHeight); 420 421 glDisable(GL_ALPHA_TEST); 422 glDisable(GL_TEXTURE_2D); 423 glDisable(GL_LIGHTING); 424 425 glMatrixMode(GL_PROJECTION); 426 glPushMatrix(); 427 glLoadIdentity(); 428 429 glMatrixMode(GL_MODELVIEW); 430 glPushMatrix(); 431 glLoadIdentity(); 432 433 const float offs = 0.5f; 434 435 glOrtho(-offs, offs, -offs, offs, 0, 1); 436 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 437 438 cgGLEnableProfile(RenderState::sCgFragmentProfile); 439 440 cgGLBindProgram(sCgAntiAliasingProgram); 441 442 cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex); 443 cgGLEnableTextureParameter(sColorsTexAntiAliasingParam); 444 445 cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 446 cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 447 448 glColor3f(1.0f, 1.0f, 1.0f); 449 450 float offs2 = 0.5f; 451 452 glBegin(GL_QUADS); 453 454 // the neighbouring texels 455 float x_offs = 1.0f / mWidth; 456 float y_offs = 1.0f / mHeight; 457 458 SetVertex(0, 0, x_offs, y_offs); 459 SetVertex(1, 0, x_offs, y_offs); 460 SetVertex(1, 1, x_offs, y_offs); 461 SetVertex(0, 1, x_offs, y_offs); 462 463 glEnd(); 464 465 cgGLDisableTextureParameter(sColorsTexAntiAliasingParam); 466 cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam); 467 468 cgGLDisableProfile(RenderState::sCgFragmentProfile); 469 470 glEnable(GL_LIGHTING); 471 glDisable(GL_TEXTURE_2D); 472 473 glMatrixMode(GL_PROJECTION); 474 glPopMatrix(); 475 476 glMatrixMode(GL_MODELVIEW); 477 glPopMatrix(); 478 479 glPopAttrib(); 480 481 PrintGLerror("deferred shading"); 482 } 483 484 372 485 } // namespace
Note: See TracChangeset
for help on using the changeset viewer.