- Timestamp:
- 08/28/08 21:17:15 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2875 r2879 9 9 using namespace std; 10 10 11 static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT };11 static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT}; 12 12 13 13 namespace CHCDemoEngine … … 72 72 static CGparameter sNormalsTexAntiAliasingParam; 73 73 74 75 static GLuint noiseTex; 74 static GLuint noiseTex = 0; 76 75 77 76 // ssao random spherical samples … … 98 97 static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 99 98 poisson.Generate((Sample2 *)samples); 99 } 100 101 102 static void CreateNoiseTex2D(int w, int h) 103 { 104 // hack: should be able to recalc noise texture 105 //if (noiseTex > 0) return; 106 107 //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 108 float *randomNormals = new float[w * h * 3]; 109 110 for (int i = 0; i < w * h * 3; i += 3) 111 { 112 // create random samples on a circle 113 const float rx = RandomValue(0, 1); 114 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 115 116 //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 117 //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 118 randomNormals[i + 0] = cos(theta); 119 randomNormals[i + 1] = sin(theta); 120 randomNormals[i + 2] = 0; 121 } 122 123 glEnable(GL_TEXTURE_2D); 124 glGenTextures(1, &noiseTex); 125 glBindTexture(GL_TEXTURE_2D, noiseTex); 126 127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 131 132 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 133 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGB, GL_FLOAT, randomNormals); 134 135 glBindTexture(GL_TEXTURE_2D, 0); 136 glDisable(GL_TEXTURE_2D); 137 138 delete [] randomNormals; 139 140 cout << "created noise texture" << endl; 141 142 PrintGLerror("noisetexture"); 100 143 } 101 144 … … 108 151 mUseGlobIllum(false) 109 152 { 153 // create noise texture for ssao 154 CreateNoiseTex2D(w, h); 155 110 156 /////////// 111 157 //-- the flip-flop fbos 112 158 113 159 mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 114 // the diffuse color buffer115 160 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 116 161 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); … … 118 163 119 164 mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 120 // the diffuse color buffer121 165 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 122 166 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 123 167 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 124 168 125 mFbo3 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 126 // the diffuse color buffer 127 mFbo3->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 128 129 130 // create noise texture for ssao 131 CreateNoiseTex2D(); 169 //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 170 //mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);*/ 132 171 } 133 172 134 173 135 174 SsaoShader::~SsaoShader() 136 { 137 if (sCgSsaoProgram) 138 cgDestroyProgram(sCgSsaoProgram); 175 176 { 177 if (sCgSsaoProgram) cgDestroyProgram(sCgSsaoProgram); 178 if (sCgDeferredProgram) cgDestroyProgram(sCgDeferredProgram); 179 if (sCgSsaoProgram) cgDestroyProgram(sCgSsaoProgram); 180 if (sCgGiProgram) cgDestroyProgram(sCgGiProgram); 181 if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram); 139 182 140 183 DEL_PTR(mNewFbo); 141 184 DEL_PTR(mOldFbo); 185 //DEL_PTR(mFbo); 142 186 143 187 glDeleteTextures(1, &noiseTex); … … 295 339 FrameBufferObject::Release(); 296 340 297 glDrawBuffers(1, mymrt);298 299 341 cgGLEnableProfile(RenderState::sCgFragmentProfile); 300 342 … … 345 387 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 346 388 347 GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 389 // GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture(); 390 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 348 391 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 349 392 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); … … 462 505 463 506 464 void SsaoShader::CreateNoiseTex2D()465 {466 //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3];467 float *randomNormals = new float[mWidth * mHeight * 3];468 469 for (int i = 0; i < mWidth * mHeight * 3; i += 3)470 {471 // create random samples on a circle472 const float rx = RandomValue(0, 1);473 const float theta = 2.0f * acos(sqrt(1.0f - rx));474 475 //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f);476 //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f);477 randomNormals[i + 0] = cos(theta);478 randomNormals[i + 1] = sin(theta);479 randomNormals[i + 2] = 0;480 }481 482 glEnable(GL_TEXTURE_2D);483 glGenTextures(1, &noiseTex);484 glBindTexture(GL_TEXTURE_2D, noiseTex);485 486 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);490 491 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals);492 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, mWidth, mHeight, 0, GL_RGB, GL_FLOAT, randomNormals);493 494 glBindTexture(GL_TEXTURE_2D, 0);495 glDisable(GL_TEXTURE_2D);496 497 delete [] randomNormals;498 499 cout << "created noise texture" << endl;500 501 PrintGLerror("noisetexture");502 }503 504 505 507 506 508 static void SetVertex(float x, float y, float x_offs, float y_offs) … … 521 523 void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 522 524 { 523 //GLuint colorsTex = mFbo4->GetColorBuffer(0)->GetTexture();524 525 GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 525 526 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); … … 566 567 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 567 568 568 mFbo3->Bind(); 569 //mNewFbo->Bind(); 569 fbo->Bind(); 570 571 glDrawBuffers(1, mymrt + 3); 570 572 571 573 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 572 574 573 glDrawBuffers(1, mymrt);574 575 575 cgGLEnableProfile(RenderState::sCgFragmentProfile); 576 576 … … 618 618 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixGiParam, (const float *)oldProjViewMatrix.x); 619 619 620 GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 620 //GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture(); 621 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 621 622 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 622 623 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
Note: See TracChangeset
for help on using the changeset viewer.