- Timestamp:
- 08/22/08 13:20:06 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2860 r2861 61 61 SsaoShader::SsaoShader(int w, int h, 62 62 Camera *cam, 63 float expFactor,64 63 float scaleFactor 65 64 ): 66 65 mWidth(w), mHeight(h), 67 66 mCamera(cam), 68 mExpFactor(expFactor),69 67 mScaleFactor(scaleFactor) 70 {} 68 { 69 70 /////////// 71 //-- the flip-flop fbos 72 73 mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 74 // the diffuse color buffer 75 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 76 77 mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 78 // the diffuse color buffer 79 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 80 81 82 // create noise texture for ssao 83 CreateNoiseTex2D(); 84 } 85 86 87 SsaoShader::~SsaoShader() 88 { 89 if (sCgSsaoProgram) 90 cgDestroyProgram(sCgSsaoProgram); 91 92 DEL_PTR(mNewFbo); 93 DEL_PTR(mOldFbo); 94 95 glDeleteTextures(1, &noiseTex); 96 } 71 97 72 98 73 99 void SsaoShader::Init(CGcontext context) 74 { 75 100 { 76 101 /////////////// 77 102 … … 112 137 113 138 114 void SsaoShader::Render(FrameBufferObject *fbo, FrameBufferObject *fbo2) 115 { 116 FirstPass(fbo, fbo2); 117 SecondPass(fbo, fbo2); 118 } 119 120 121 void SsaoShader::FirstPass(FrameBufferObject *fbo, FrameBufferObject *fbo2) 122 { 123 GLuint positionsTex = fbo->GetColorBuffer(0)->GetTexture(); 139 void SsaoShader::Render(FrameBufferObject *fbo, 140 const Matrix4x4 &oldProjViewMatrix, 141 float expFactor) 142 { 143 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 144 145 // switch roles of old and new fbo 146 // the algorihm uses two input fbos, where the one 147 // contais the color buffer from the last frame, 148 // the other one will be written 149 swap(mNewFbo, mOldFbo); 150 151 FirstPass(fbo, expFactor); 152 // the second pass just renders the combined solution 153 SecondPass(fbo); 154 } 155 156 157 void SsaoShader::FirstPass(FrameBufferObject *fbo, float expFactor) 158 { 124 159 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 125 GLuint normalsTex = fbo->GetColorBuffer(0)->GetTexture(); 126 127 GLuint oldTex = fbo2->GetColorBuffer(0)->GetTexture(); 160 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 161 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 162 163 // read the second buffer, write to the first buffer 164 mNewFbo->Bind(); 165 GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 128 166 129 167 glPushAttrib(GL_VIEWPORT_BIT); … … 172 210 173 211 cgGLSetParameter1f(sMaxDepthParam, mScaleFactor); 174 cgGLSetParameter1f(sExpFactorParam, mExpFactor);212 cgGLSetParameter1f(sExpFactorParam, expFactor); 175 213 176 214 … … 215 253 glPopAttrib(); 216 254 217 PrintGLerror("displaytexture"); 218 219 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 220 255 FrameBufferObject::Release(); 221 256 222 257 PrintGLerror("ssao first pass"); … … 224 259 225 260 226 void SsaoShader::SecondPass(FrameBufferObject *fbo , FrameBufferObject *fbo2)261 void SsaoShader::SecondPass(FrameBufferObject *fbo) 227 262 { 228 263 glEnable(GL_TEXTURE_2D); 229 264 230 glBindTexture(GL_TEXTURE_2D, fbo2->GetColorBuffer(0)->GetTexture());265 glBindTexture(GL_TEXTURE_2D, mNewFbo->GetColorBuffer(0)->GetTexture()); 231 266 232 267 glDisable(GL_LIGHTING); … … 274 309 mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 275 310 276 #if 1// matT: debug this!!311 #if 0 // matT: debug this!! 277 312 278 313 bl = Normalize(nbl - fbl);
Note: See TracChangeset
for help on using the changeset viewer.