Changeset 2879 for GTP/trunk/App
- Timestamp:
- 08/28/08 21:17:15 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2877 r2879 308 308 </File> 309 309 <File 310 RelativePath=".\src\ShadowMapping.cpp" 311 > 312 </File> 313 <File 314 RelativePath=".\src\ShadowMapping.h" 315 > 316 </File> 317 <File 310 318 RelativePath=".\src\SsaoShader.cpp" 311 319 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp
r2868 r2879 24 24 25 25 26 static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT}; 27 26 28 27 29 static CGprogram sCgDeferredProgram; … … 40 42 mWidth(w), mHeight(h) 41 43 { 42 mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 43 // the diffuse color buffer 44 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 44 //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 45 //mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 45 46 } 46 47 … … 50 51 if (sCgDeferredProgram) 51 52 cgDestroyProgram(sCgDeferredProgram); 53 54 //DEL_PTR(mFbo); 52 55 } 53 56 … … 111 114 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 112 115 113 mFbo->Bind(); 116 fbo->Bind(); 117 glDrawBuffers(1, mymrt + 3); 118 114 119 115 120 glPushAttrib(GL_VIEWPORT_BIT); … … 199 204 void DeferredShader::AntiAliasing(FrameBufferObject *fbo) 200 205 { 201 GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture();206 GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 202 207 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 203 208 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h
r2865 r2879 44 44 int mHeight; 45 45 46 FrameBufferObject *mFbo;46 //FrameBufferObject *mFbo; 47 47 }; 48 48 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r2878 r2879 16 16 { 17 17 case GL_FRAMEBUFFER_COMPLETE_EXT: 18 cout << "frame buffer object complete" << endl;18 //cout << "frame buffer object complete" << endl; 19 19 break; 20 20 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: … … 68 68 } 69 69 70 70 71 glGenRenderbuffersEXT(1, &mId); 71 72 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mId); 73 72 74 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, w, h); 73 74 75 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, color_attachment[attachment_idx], GL_RENDERBUFFER_EXT, mId); 76 75 77 76 78 glGenTextures(1, &mTexId); … … 141 143 Bind(); 142 144 143 cout << "creating fbo" << endl;144 145 145 /////////// 146 146 //-- create depth buffer … … 150 150 glGenRenderbuffersEXT(1, &mDepthId); 151 151 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mDepthId); 152 153 cout << "adding depth buffer" << endl;154 152 155 153 GLuint depthFormat; … … 167 165 } 168 166 169 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat, mWidth, mHeight); 167 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat, w, h); 168 169 170 170 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepthId); 171 171 172 172 if (useDepthTex) 173 173 { 174 //cout << "adding depth texture" << endl;175 176 174 glGenTextures(1, &mDepthTexId); 177 175 glBindTexture(GL_TEXTURE_2D, mDepthTexId); … … 210 208 bool useMipMap) 211 209 { 212 cout << "adding color buffer" << endl;213 214 210 Bind(); 215 211 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r2878 r2879 143 143 fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 144 144 145 PrintGLerror("here667");146 145 147 146 fbo->Bind(); … … 152 151 glPushAttrib(GL_VIEWPORT_BIT); 153 152 154 glClearColor(1, 1, 1, 1);155 153 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 156 154 … … 188 186 189 187 GrabDepthBuffer(mDepth, fbo->GetDepthTex()); 190 191 188 //ExportDepthBuffer(mDepth); PrintGLerror("grab"); 192 189 -
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(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
r2875 r2879 58 58 void AntiAliasing(FrameBufferObject *fbo); 59 59 60 void CreateNoiseTex2D();61 60 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 62 61 … … 74 73 FrameBufferObject *mOldFbo; 75 74 FrameBufferObject *mNewFbo; 76 FrameBufferObject *mFbo3;75 //FrameBufferObject *mFbo; 77 76 78 77 bool mUseGlobIllum; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2878 r2879 47 47 //-- fbos 48 48 49 FrameBufferObject *fbo ;49 FrameBufferObject *fbo = NULL; 50 50 51 51 bool isFirstTexture = true; … … 376 376 glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); 377 377 378 InitFBO();379 380 378 LeftMotion(0, 0); 381 379 MiddleMotion(0, 0); … … 432 430 SsaoShader::Init(sCgContext); 433 431 434 deferredShader = new DeferredShader(texWidth, texHeight);435 ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f);432 //deferredShader = new DeferredShader(texWidth, texHeight); 433 //ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 436 434 437 435 // initialize the render traverser … … 539 537 // this fbo basicly stores the scene information we get from standard rendering of a frame 540 538 // we store colors, normals, positions (for the ssao) 541 fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_ 24);539 fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32); 542 540 543 541 // the diffuse color buffer … … 551 549 // the normals buffer 552 550 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 551 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 552 553 // another color buffer 553 554 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 554 555 … … 574 575 void InitGLstate() 575 576 { 576 glClearColor(0. 5f, 0.5f, 0.8f, 0.0f);577 glClearColor(0.0f, 0.0, 0.2f, 0.0f); 577 578 578 579 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); … … 871 872 872 873 glEnable(GL_MULTISAMPLE_ARB); 873 fbo->Release(); 874 874 875 875 state.SetRenderType(RenderState::FIXED); 876 876 glEnable(GL_LIGHTING); … … 888 888 889 889 glEnable(GL_MULTISAMPLE_ARB); 890 fbo->Release(); 891 890 892 891 cgGLDisableProfile(RenderState::sCgFragmentProfile); 893 892 cgGLDisableProfile(RenderState::sCgVertexProfile); … … 907 906 908 907 case RenderState::DEFERRED: 908 909 if (!fbo) InitFBO(); 909 910 910 911 // multisampling does not work with deferred shading … … 987 988 988 989 if (useSsao) 990 { 991 if (!ssaoShader) ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 992 //DEL_PTR(deferredShader); 993 989 994 ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor); 995 996 } 990 997 else 998 { 999 if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight); 1000 //DEL_PTR(ssaoShader); 1001 991 1002 deferredShader->Render(fbo); 1003 } 1004 } 1005 else 1006 { 1007 /*DEL_PTR(fbo); 1008 DEL_PTR(ssaoShader); 1009 DEL_PTR(deferredShader); 1010 */ 992 1011 } 993 1012 … … 1174 1193 switch (c) 1175 1194 { 1195 1176 1196 case 'A': 1177 1197 case 'a': … … 1531 1551 DEL_PTR(renderQueue); 1532 1552 DEL_PTR(perfGraph); 1553 1554 DEL_PTR(fbo); 1555 DEL_PTR(ssaoShader); 1556 DEL_PTR(deferredShader); 1533 1557 1534 1558 if (sCgMrtVertexProgram)
Note: See TracChangeset
for help on using the changeset viewer.