- Timestamp:
- 08/21/08 20:17:46 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2844 r2860 42 42 void Camera::Precompute(const Vector3 &direction) 43 43 { 44 /*45 Vector3 side = CrossProd(Vector3(1, 0, 0), direction);46 Vector3 up = -Normalize(CrossProd(side, direction));47 Vector3 right = -Normalize(CrossProd(direction, up));48 */49 44 Vector3 up = Vector3(0, 0, 1); 50 45 Vector3 right = Normalize(CrossProd(up, direction)); … … 53 48 mBaseOrientation = Matrix4x4(right, up, direction); 54 49 mViewOrientation = mBaseOrientation; 55 56 /*cout << "right: " << right << endl;57 cout << "up: " << up << endl;58 cout << "dir: " << direction << endl;59 */60 50 } 61 51 … … 241 231 } 242 232 243 Vector3 h2 = direction; // h2.x = 0;233 Vector3 h2 = direction; 244 234 245 235 if (SqrMagnitude(h2) > 0) 246 236 { 247 237 h2.Normalize(); 248 mYaw = -acos(DotProd(h2, h1)); //Vector3(0, 1, 0)));238 mYaw = -acos(DotProd(h2, h1)); 249 239 } 250 240 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2859 r2860 3 3 #include "RenderState.h" 4 4 #include "SampleGenerator.h" 5 #include "Vector3.h" 6 #include "Camera.h" 5 7 6 8 7 9 using namespace std; 8 10 9 GLenummrt[] = {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}; 10 12 11 13 namespace CHCDemoEngine 12 14 { 15 16 // number of ssao samples 17 #define NUM_SAMPLES 16 18 13 19 14 20 static CGprogram sCgSsaoProgram = NULL; … … 25 31 static CGparameter sExpFactorParam; 26 32 27 28 #define NUM_SAMPLES 16 33 static GLuint noiseTex; 29 34 30 35 // ssao random spherical samples … … 54 59 55 60 56 SsaoShader::SsaoShader(int w, int h, float expFactor, float scaleFactor): 57 mWidth(w), mHeight(h), mExpFactor(expFactor), mScaleFactor(scaleFactor) 61 SsaoShader::SsaoShader(int w, int h, 62 Camera *cam, 63 float expFactor, 64 float scaleFactor 65 ): 66 mWidth(w), mHeight(h), 67 mCamera(cam), 68 mExpFactor(expFactor), 69 mScaleFactor(scaleFactor) 58 70 {} 59 71 … … 113 125 GLuint normalsTex = fbo->GetColorBuffer(0)->GetTexture(); 114 126 127 GLuint oldTex = fbo2->GetColorBuffer(0)->GetTexture(); 128 115 129 glPushAttrib(GL_VIEWPORT_BIT); 116 130 glViewport(0, 0, mWidth, mHeight); 117 131 118 glDrawBuffers(1, m rt);132 glDrawBuffers(1, mymrt); 119 133 120 134 glDisable(GL_ALPHA_TEST); … … 172 186 173 187 // note: slightly larger texture hides ambient occlusion error on border but costs resolution 174 // float offs2= 0.55f;175 float offs2= 0.5f;176 177 glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(- offs2, -offs2, -0.5f);178 glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f);179 glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2, offs2, -0.5f);180 glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(- offs2, offs2, -0.5f);188 //const float new_offs = 0.55f; 189 const float new_offs = 0.5f; 190 191 glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-new_offs, -new_offs, -0.5f); 192 glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( new_offs, -new_offs, -0.5f); 193 glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( new_offs, new_offs, -0.5f); 194 glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-new_offs, new_offs, -0.5f); 181 195 182 196 glEnd(); 183 197 184 cgGLDisableTextureParameter(sColorsTexParam Ssao);185 cgGLDisableTextureParameter(sPositionsTexParam Ssao);186 cgGLDisableTextureParameter(sNormalsTexParam Ssao);187 cgGLDisableTextureParameter(sNoiseTexParam Ssao);188 cgGLDisableTextureParameter(sOldTexParam Ssao);198 cgGLDisableTextureParameter(sColorsTexParam); 199 cgGLDisableTextureParameter(sPositionsTexParam); 200 cgGLDisableTextureParameter(sNormalsTexParam); 201 cgGLDisableTextureParameter(sNoiseTexParam); 202 cgGLDisableTextureParameter(sOldTexParam); 189 203 190 204 cgGLDisableProfile(RenderState::sCgFragmentProfile); … … 254 268 255 269 270 void SsaoShader::ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br) 271 { 272 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 273 274 mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 275 276 #if 1 // matT: debug this!! 277 278 bl = Normalize(nbl - fbl); 279 br = Normalize(nbr - fbr); 280 tl = Normalize(ftl - ntl); 281 tr = Normalize(ftr - ntr); 282 283 #else // just take camera direction 284 285 bl = -Normalize(mCamera->GetDirection()); 286 br = -Normalize(mCamera->GetDirection()); 287 tl = -Normalize(mCamera->GetDirection()); 288 tr = -Normalize(mCamera->GetDirection()); 289 290 #endif 291 292 // normalize to 0 .. 1 293 bl = bl * 0.5f + 0.5f; 294 br = br * 0.5f + 0.5f; 295 tl = tl * 0.5f + 0.5f; 296 tr = tr * 0.5f + 0.5f; 297 } 298 299 300 void SsaoShader::CreateNoiseTex2D() 301 { 302 GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 303 304 for (int i = 0; i < mWidth * mHeight * 3; i += 3) 305 { 306 // create random samples over sphere 307 const float rx = RandomValue(0, 1); 308 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 309 310 randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 311 randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 312 randomNormals[i + 2] = 0; 313 } 314 315 glEnable(GL_TEXTURE_2D); 316 glGenTextures(1, &noiseTex); 317 glBindTexture(GL_TEXTURE_2D, noiseTex); 318 319 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 323 324 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 325 326 glBindTexture(GL_TEXTURE_2D, 0); 327 glDisable(GL_TEXTURE_2D); 328 329 delete [] randomNormals; 330 331 cout << "created noise texture" << endl; 332 333 PrintGLerror("noisetexture"); 334 } 335 256 336 257 337 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
r2859 r2860 12 12 13 13 class FrameBufferObject; 14 class Vector3; 15 class Camera; 14 16 15 17 … … 21 23 public: 22 24 /** constructor for a deferred shader taking the requested output image size, 23 the exponential smoothing factor for temporal reprojection. 24 25 The last parameter is a just a scale factor 26 for the scene depth in order to get better floating point precision in the shader 27 This must be reciprocal value of the scale factor used in the mrt shader. 25 the current camera, the exponential smoothing factor for temporal reprojection, 26 and a scaling factor. 27 28 The parameter scaleFactor must be reciprocal value of the 29 scale factor used for creating the positions texture. It is used recover the 30 exact scene size that was scaled in order to improve floating point precision. 28 31 */ 29 SsaoShader(int w, int h, float expFactor, float scaleFactor);32 SsaoShader(int w, int h, Camera *cam, float expFactor, float scaleFactor); 30 33 /** The algorithm renders the scene given an fbo. 31 34 The fbo must have color buffer, position buffer, normal buffer. … … 55 58 /// this is just a scale factor for the scene depth in order to get better float precision in the shader 56 59 float mScaleFactor; 60 61 Camera *mCamera; 62 63 64 private: 65 66 void CreateNoiseTex2D(); 67 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 68 57 69 }; 58 70 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2859 r2860 668 668 // this fbo basicly stores the scene information we get from standard rendering of a frame 669 669 // we store colors, normals, positions (for the ssao) 670 myfbo = new FrameBufferObject(texWidth, texHeight, true, FrameBufferObject::DEPTH_24);670 fbo = new FrameBufferObject(texWidth, texHeight, true, FrameBufferObject::DEPTH_24); 671 671 672 672 673 673 // the diffuse color buffer 674 myfbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, 675 ColorBufferObject::WRAP_CLAMP_TO_EDGE, 676 ColorBufferObject::FILTER_LINEAR, 677 false, false); 674 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 678 675 679 676 // the positions buffer 680 myfbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, 681 ColorBufferObject::WRAP_CLAMP_TO_EDGE, 682 ColorBufferObject::FILTER_NEAREST, 683 false, false); 677 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 684 678 685 679 // the normals buffer 686 myfbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, 687 ColorBufferObject::WRAP_CLAMP_TO_EDGE, 688 ColorBufferObject::FILTER_NEAREST, 689 false, false); 690 691 680 fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 681 692 682 693 683
Note: See TracChangeset
for help on using the changeset viewer.