- Timestamp:
- 09/23/08 12:11:29 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r2963 r2965 32 32 vector<int> nIndices; 33 33 vector<int> tIndices; 34 35 //cout << "number of vertices=" << (int)vertices.size() << endl;36 34 37 35 for (size_t i = 0; i < substrings.size(); ++ i) … … 142 140 geom->mNormals[i].z = faceNormals[i].y; 143 141 144 if (i < =geom->mTexcoordCount)142 if (i < geom->mTexcoordCount) 145 143 { 146 144 geom->mTexcoords[i].first = faceTexcoords[i].first; … … 244 242 faceVertices, faceNormals, faceTexcoords); 245 243 246 if (((line % 100 ) ==99) &&244 if (((line % 1000) == 999) && 247 245 !faceVertices.empty()) 248 246 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2961 r2965 283 283 > 284 284 </File> 285 <File 286 RelativePath=".\src\ToneMapper.cpp" 287 > 288 </File> 289 <File 290 RelativePath=".\src\ToneMapper.h" 291 > 292 </File> 285 293 <Filter 286 294 Name="timer" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2952 r2965 229 229 CreateNoiseTex2D(w, h); 230 230 231 231 232 /////////// 232 233 //-- the flip-flop fbos … … 234 235 mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 235 236 236 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR , false);237 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR , false);238 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR , false);239 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR , false);237 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 238 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 239 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 240 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 240 241 } 241 242 … … 1054 1055 } 1055 1056 1057 1058 1059 1060 1056 1061 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2957 r2965 82 82 */ 83 83 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 84 85 84 86 85 87 86 //////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r2899 r2965 45 45 46 46 ColorBufferObject::ColorBufferObject(int w, int h, 47 int attachment_idx, 47 48 FORMAT format, 48 49 WRAP_TYPE wrapType, 49 50 FILTER_TYPE filterType, 50 bool useMipMap, 51 int attachment_idx) 52 { 53 GLuint glformat, internalFormat; 54 51 FILTER_TYPE filterTypeMipMap 52 ) 53 { 54 Init(w, h, attachment_idx, format, wrapType, filterType, true, filterTypeMipMap); 55 } 56 57 58 ColorBufferObject::ColorBufferObject(int w, int h, 59 int attachment_idx, 60 FORMAT format, 61 WRAP_TYPE wrapType, 62 FILTER_TYPE filterType 63 ) 64 { 65 Init(w, h, attachment_idx, format, wrapType, filterType, false, FILTER_NEAREST); 66 } 67 68 69 ColorBufferObject::~ColorBufferObject() 70 { 71 glDeleteRenderbuffersEXT(1, &mId); 72 glDeleteTextures(1, &mTexId); 73 } 74 75 76 void ColorBufferObject::Init(int w, int h, 77 int attachment_idx, 78 FORMAT format, 79 WRAP_TYPE wrapType, 80 FILTER_TYPE filterType, 81 bool useMipMap, 82 FILTER_TYPE filterTypeMipMap 83 ) 84 { 85 mWidth = w; 86 mHeight = h; 55 87 56 88 switch (format) 57 89 { 58 90 case BUFFER_UBYTE: 59 glformat = GL_UNSIGNED_BYTE; internalFormat = GL_RGBA8; break;91 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; break; 60 92 case BUFFER_FLOAT_16: 61 glformat = GL_FLOAT; internalFormat = GL_RGBA16F_ARB; break;93 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA16F_ARB; break; 62 94 case BUFFER_FLOAT_32: 63 glformat = GL_FLOAT; internalFormat = GL_RGBA32F_ARB; break;95 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break; 64 96 default: 65 glformat = GL_UNSIGNED_BYTE; internalFormat = GL_RGBA8;97 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; 66 98 cerr << "should not come here" << endl; 67 99 } … … 71 103 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mId); 72 104 73 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, w, h);105 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, mInternalFormat, w, h); 74 106 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_RENDERBUFFER_EXT, mId); 75 107 … … 77 109 glGenTextures(1, &mTexId); 78 110 glBindTexture(GL_TEXTURE_2D, mTexId); 79 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, GL_RGBA, glformat, NULL);111 glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, GL_RGBA, mGlFormat, NULL); 80 112 81 113 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_TEXTURE_2D, mTexId, 0); … … 84 116 GLuint magfilterParam; 85 117 86 switch (filterType) 87 { 88 case FILTER_NEAREST: 89 minfilterParam = GL_NEAREST; 90 magfilterParam = GL_NEAREST; break; 91 case FILTER_LINEAR: 92 minfilterParam = GL_LINEAR; 93 magfilterParam = GL_LINEAR; break; 94 case FILTER_MIPMAP_LINEAR: 95 minfilterParam = GL_NEAREST_MIPMAP_NEAREST; 96 magfilterParam = GL_NEAREST; 97 98 //minfilterParam = GL_LINEAR_MIPMAP_NEAREST; 99 //magfilterParam = GL_LINEAR; 100 break; 101 default: 102 minfilterParam = GL_NEAREST; 118 if (filterType == FILTER_NEAREST) 103 119 magfilterParam = GL_NEAREST; 104 105 cerr << "should not come here" << endl; 106 } 107 108 120 else // FILTER_LINEAR 121 magfilterParam = GL_LINEAR; 122 123 if (!useMipMap) 124 { 125 if (filterType == FILTER_NEAREST) 126 minfilterParam = GL_NEAREST; 127 else // FILTER_LINEAR 128 minfilterParam = GL_LINEAR; 129 } 130 else 131 { 132 if (filterType == FILTER_NEAREST) 133 { 134 if (filterTypeMipMap == FILTER_NEAREST) 135 minfilterParam = GL_NEAREST_MIPMAP_NEAREST; 136 else // FILTER_LINEAR 137 minfilterParam = GL_NEAREST_MIPMAP_LINEAR; 138 } 139 else // FILTER_LINEAR 140 { 141 if (filterTypeMipMap == FILTER_NEAREST) 142 minfilterParam = GL_LINEAR_MIPMAP_NEAREST; 143 else // FILTER_LINEAR 144 minfilterParam = GL_LINEAR_MIPMAP_LINEAR; 145 } 146 } 147 109 148 GLuint wrapParam; 110 149 … … 130 169 131 170 132 ColorBufferObject::~ColorBufferObject() 133 { 134 glDeleteRenderbuffersEXT(1, &mId); 135 glDeleteTextures(1, &mTexId); 136 } 171 172 void *ColorBufferObject::ReadTexture() const 173 { 174 int bytes = 0; 175 176 switch (mInternalFormat) 177 { 178 case GL_RGBA8: 179 bytes = 8; break; 180 case GL_RGBA16F_ARB: 181 bytes = 16; break; 182 case GL_RGBA32F_ARB: 183 bytes = 32; break; 184 default: 185 cerr << "should not come here" << endl; 186 } 187 188 unsigned char *data = new unsigned char[bytes * 4 * mWidth * mHeight]; 189 190 glEnable(GL_TEXTURE_2D); 191 glBindTexture(GL_TEXTURE_2D, mTexId); 192 193 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, mGlFormat, data); 194 195 glBindTexture(GL_TEXTURE_2D, 0); 196 glDisable(GL_TEXTURE_2D); 197 198 return data; 199 } 200 201 202 /*****************************************************************/ 203 /* FrameBufferObject implementation */ 204 /*****************************************************************/ 137 205 138 206 … … 143 211 144 212 Bind(); 145 146 213 /////////// 147 214 //-- create depth buffer … … 181 248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 182 249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 250 183 251 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 184 252 … … 207 275 ColorBufferObject::WRAP_TYPE wrapType, 208 276 ColorBufferObject::FILTER_TYPE filterType, 209 bool useMipMap)277 ColorBufferObject::FILTER_TYPE filterTypeMipMap) 210 278 { 211 279 Bind(); … … 214 282 215 283 ColorBufferObject *colorBuf = 216 new ColorBufferObject(mWidth, mHeight, col, wrapType, filterType, useMipMap, idx);284 new ColorBufferObject(mWidth, mHeight, idx, col, wrapType, filterType, filterTypeMipMap); 217 285 218 286 mColorBuffers.push_back(colorBuf); … … 224 292 225 293 294 295 int FrameBufferObject::AddColorBuffer(ColorBufferObject::FORMAT col, 296 ColorBufferObject::WRAP_TYPE wrapType, 297 ColorBufferObject::FILTER_TYPE filterType) 298 { 299 Bind(); 300 301 const int idx = (int)mColorBuffers.size(); 302 303 ColorBufferObject *colorBuf = 304 new ColorBufferObject(mWidth, mHeight, idx, col, wrapType, filterType); 305 306 mColorBuffers.push_back(colorBuf); 307 308 Release(); 309 310 return idx; 311 } 312 313 226 314 void FrameBufferObject::Bind() const 227 315 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
r2957 r2965 16 16 17 17 enum FORMAT { BUFFER_UBYTE, BUFFER_FLOAT_16, BUFFER_FLOAT_32 }; 18 enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE };19 enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR , FILTER_MIPMAP_LINEAR};18 enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE }; 19 enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR }; 20 20 21 22 /** Creates color buffer without mipmap. attachment_idx describes 23 the number of the render target the buffer is attached to 24 */ 21 25 ColorBufferObject(int w, int h, 22 FORMAT c, 26 int attachment_idx , 27 FORMAT c, 28 WRAP_TYPE wrapType, 29 FILTER_TYPE filterType); 30 31 /** Same as above, with mipmapping enabled. 32 */ 33 ColorBufferObject(int w, int h, 34 int attachment_idx, 35 FORMAT c, 23 36 WRAP_TYPE wrapType, 24 37 FILTER_TYPE filterType, 25 bool useMipMap,26 int attachment_idx);38 FILTER_TYPE filterTypeMipMap 39 ); 27 40 28 41 ~ColorBufferObject(); 29 42 30 unsigned int GetTexture() const {return mTexId;} 43 unsigned int GetTexture() const { return mTexId; } 44 45 /** Returns texture data. 46 */ 47 void *ReadTexture() const; 48 31 49 32 50 protected: 33 51 52 void Init(int w, int h, 53 int attachment_idx, 54 FORMAT format, 55 WRAP_TYPE wrapType, 56 FILTER_TYPE filterType, 57 bool useMipMap, 58 FILTER_TYPE filterTypeMipMap 59 ); 60 61 62 63 /////////// 64 65 int mGlFormat; 66 int mInternalFormat; 34 67 unsigned int mId; 35 68 unsigned int mTexId; 69 70 int mWidth; 71 int mHeight; 36 72 }; 37 73 … … 43 79 public: 44 80 45 enum DEPTH_FORMAT { DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32};81 enum DEPTH_FORMAT {DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32}; 46 82 47 83 /** constructor requesting an opengl occlusion query. … … 55 91 int AddColorBuffer(ColorBufferObject::FORMAT col, 56 92 ColorBufferObject::WRAP_TYPE wrapType, 57 ColorBufferObject::FILTER_TYPE filterType, 58 bool useMipMap); 93 ColorBufferObject::FILTER_TYPE filterType); 94 95 /** Same as above, but enables mipmapping using the specified filter. 96 */ 97 int AddColorBuffer(ColorBufferObject::FORMAT col, 98 ColorBufferObject::WRAP_TYPE wrapType, 99 ColorBufferObject::FILTER_TYPE filterType, 100 ColorBufferObject::FILTER_TYPE filterTypeMipMap); 59 101 60 102 /** Returns the color buffer object on position i. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r2964 r2965 65 65 cgGLSetTextureParameter(RenderState::sTexParam, mTexture->GetId()); 66 66 cgGLEnableTextureParameter(RenderState::sTexParam); 67 cgGLEnableTextureParameter(RenderState::sDirtTexParamTex);68 67 } 69 68 else -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r2964 r2965 14 14 CGprogram RenderState::sCgMrtFragmentTexProgram = NULL; 15 15 CGparameter RenderState::sTexParam; 16 CGparameter RenderState::sDirtTexParamTex;17 16 18 17 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r2964 r2965 83 83 static CGparameter sTexParam; 84 84 85 static CGparameter sDirtTexParamTex;86 87 85 protected: 88 86 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r2957 r2965 11 11 12 12 13 14 15 13 using namespace std; 16 14 17 15 const static int texWidth = 2048; 18 16 const static int texHeight = 2048; 19 20 21 17 22 18 … … 143 139 144 140 FrameBufferObject *fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32, true); 145 fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 141 fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, 142 ColorBufferObject::WRAP_CLAMP_TO_EDGE, 143 ColorBufferObject::FILTER_NEAREST, 144 ColorBufferObject::FILTER_NEAREST); 146 145 147 146 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2963 r2965 141 141 { 142 142 mFbo = new FrameBufferObject(size, size, FrameBufferObject::DEPTH_32, true); 143 143 144 // need a color buffer to keep opengl happy 144 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 145 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, 146 ColorBufferObject::WRAP_CLAMP_TO_EDGE, 147 ColorBufferObject::FILTER_NEAREST); 148 145 149 146 150 mShadowCam = new Camera(mSize, mSize); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2963 r2965 3 3 4 4 #include "common.h" 5 #include "glInterface.h"6 5 #include "AxisAlignedBox3.h" 7 6 #include "Matrix4x4.h" 8 9 #include <Cg/cg.h>10 #include <Cg/cgGL.h>11 7 12 8 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2964 r2965 168 168 PerfTimer frameTimer, algTimer; 169 169 170 Texture *dirtTexture = NULL;171 170 172 171 … … 458 457 camera->SetFar(Magnitude(bvh->GetBox().Diagonal())); 459 458 460 dirtTexture = new Texture(model_path + "waterstain.jpg");461 //dirtTexture = new Texture(model_path + "dirt.jpg");462 dirtTexture->Create();463 464 459 InitCg(); 465 460 … … 580 575 581 576 sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth"); 582 RenderState::sDirtTexParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "dirtTex");583 577 RenderState::sTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tex"); 584 585 cgGLEnableTextureParameter(RenderState::sDirtTexParamTex);586 cgGLSetTextureParameter(RenderState::sDirtTexParamTex, dirtTexture->GetId());587 578 588 579 cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist); … … 625 616 626 617 // the diffuse color buffer 627 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_ MIPMAP_LINEAR, true);618 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 628 619 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 629 620 630 621 // the positions buffer 631 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_ MIPMAP_LINEAR, true);622 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 632 623 //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 633 624 634 625 // the normals buffer 635 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);626 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 636 627 637 628 // another color buffer 638 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false);629 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 639 630 640 631 PrintGLerror("fbo"); … … 659 650 void InitGLstate() 660 651 { 661 glClearColor( 1.4f, 0.4f, 0.4f, 1.0f);652 glClearColor(0.4f, 0.4f, 0.4f, 1.0f); 662 653 663 654 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2959 r2965 186 186 return OUT; 187 187 } 188 189 190 /*float4 FinalPass( SkyboxVS_Output Input ) : COLOR 191 { 192 float4 vColor = tex2D( s0, Input.Tex ); 193 float3 vBloom = tex2D( s1, Input.Tex ); 194 195 float vLum = g_fImageKey; 196 vColor.rgb = vColor; 197 198 // Tone mapping 199 vColor.rgb *= g_fMiddleGray /(vLum + 0.001f); 200 vColor.rgb *= (1.0f + vColor/LUM_WHITE); 201 vColor.rgb /= (1.0f + vColor); 202 203 vColor.rgb += 0.6f * vBloom; 204 vColor.a = 1.0f; 205 206 return vColor; 207 }*/ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2964 r2965 72 72 pixel pix; 73 73 74 //float4 dirtTexColor = tex2D(dirtTex, IN.texCoord.xy);75 74 float4 texColor = tex2D(tex, IN.texCoord.xy); 76 75 77 76 // save color in first render target 78 77 // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 79 //pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor * dirtTexColor;80 78 pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 81 79
Note: See TracChangeset
for help on using the changeset viewer.