- Timestamp:
- 08/26/08 13:30:31 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2866 r2867 64 64 65 65 66 SsaoShader::SsaoShader(int w, int h, 67 Camera *cam, 68 float scaleFactor 69 ): 66 SsaoShader::SsaoShader(int w, int h, Camera *cam, float scaleFactor): 70 67 mWidth(w), mHeight(h), 71 68 mCamera(cam), … … 78 75 mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 79 76 // the diffuse color buffer 80 mNewFbo->AddColorBuffer( w, h, ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false);77 mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 81 78 82 79 mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 83 80 // the diffuse color buffer 84 mOldFbo->AddColorBuffer( w, h, ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false);81 mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 85 82 86 83 … … 167 164 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 168 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 169 188 // switch roles of old and new fbo 170 189 // the algorihm uses two input fbos, where the one … … 177 196 //DisplayTexture(); 178 197 AntiAliasing(fbo); 198 199 glEnable(GL_LIGHTING); 200 glDisable(GL_TEXTURE_2D); 201 202 glMatrixMode(GL_PROJECTION); 203 glPopMatrix(); 204 205 glMatrixMode(GL_MODELVIEW); 206 glPopMatrix(); 207 208 glPopAttrib(); 209 210 cgGLDisableProfile(RenderState::sCgFragmentProfile); 179 211 } 180 212 … … 186 218 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 187 219 220 if (1) 221 { 222 // generate mip map levels for position texture 223 glBindTexture(GL_TEXTURE_2D, positionsTex); 224 glGenerateMipmapEXT(GL_TEXTURE_2D); 225 } 226 227 188 228 // read the second buffer, write to the first buffer 189 229 mNewFbo->Bind(); 190 230 GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 191 231 192 glPushAttrib(GL_VIEWPORT_BIT);193 glViewport(0, 0, mWidth, mHeight);194 195 232 glDrawBuffers(1, mymrt); 196 233 197 glDisable(GL_ALPHA_TEST);198 glDisable(GL_TEXTURE_2D);199 glDisable(GL_LIGHTING);200 201 glMatrixMode(GL_PROJECTION);202 glPushMatrix();203 glLoadIdentity();204 205 glMatrixMode(GL_MODELVIEW);206 glPushMatrix();207 glLoadIdentity();208 209 const float offs = 0.5f;210 211 glOrtho(-offs, offs, -offs, offs, 0, 1);212 213 234 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 214 215 cgGLEnableProfile(RenderState::sCgFragmentProfile);216 235 217 236 cgGLBindProgram(sCgSsaoProgram); … … 265 284 cgGLDisableTextureParameter(sOldTexParam); 266 285 267 cgGLDisableProfile(RenderState::sCgFragmentProfile);268 269 glEnable(GL_LIGHTING);270 glDisable(GL_TEXTURE_2D);271 272 glMatrixMode(GL_PROJECTION);273 glPopMatrix();274 275 glMatrixMode(GL_MODELVIEW);276 glPopMatrix();277 278 glPopAttrib();279 280 286 FrameBufferObject::Release(); 281 287 … … 316 322 void SsaoShader::CreateNoiseTex2D() 317 323 { 318 GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 324 //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 325 float *randomNormals = new float[mWidth * mHeight * 3]; 319 326 320 327 for (int i = 0; i < mWidth * mHeight * 3; i += 3) … … 324 331 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 325 332 326 randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 327 randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 333 //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 334 //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 335 randomNormals[i + 0] = cos(theta); 336 randomNormals[i + 1] = sin(theta); 328 337 randomNormals[i + 2] = 0; 329 338 } … … 338 347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 339 348 340 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 349 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 350 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, mWidth, mHeight, 0, GL_RGB, GL_FLOAT, randomNormals); 341 351 342 352 glBindTexture(GL_TEXTURE_2D, 0); … … 371 381 GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 372 382 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 373 374 glPushAttrib(GL_VIEWPORT_BIT); 375 glViewport(0, 0, mWidth, mHeight); 376 377 glDisable(GL_ALPHA_TEST); 378 glDisable(GL_TEXTURE_2D); 379 glDisable(GL_LIGHTING); 380 381 glMatrixMode(GL_PROJECTION); 382 glPushMatrix(); 383 glLoadIdentity(); 384 385 glMatrixMode(GL_MODELVIEW); 386 glPushMatrix(); 387 glLoadIdentity(); 388 389 const float offs = 0.5f; 390 391 glOrtho(-offs, offs, -offs, offs, 0, 1); 383 392 384 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 393 385 … … 422 414 cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam); 423 415 424 cgGLDisableProfile(RenderState::sCgFragmentProfile); 425 426 glEnable(GL_LIGHTING); 427 glDisable(GL_TEXTURE_2D); 428 429 glMatrixMode(GL_PROJECTION); 430 glPopMatrix(); 431 432 glMatrixMode(GL_MODELVIEW); 433 glPopMatrix(); 434 435 glPopAttrib(); 436 437 PrintGLerror("deferred shading"); 416 PrintGLerror("antialiasing"); 438 417 } 439 418
Note: See TracChangeset
for help on using the changeset viewer.