Changeset 3005 for GTP/trunk/App/Demos/Vis/FriendlyCulling
- Timestamp:
- 10/05/08 23:13:58 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3004 r3005 256 256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 257 257 258 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals);259 258 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGB, GL_FLOAT, randomNormals); 260 259 … … 555 554 cerr << "tone program failed to load" << endl; 556 555 556 557 557 sCgDownSampleProgram = 558 558 cgCreateProgramFromFile(context, … … 587 587 } 588 588 else 589 cerr << " intensityprogram failed to load" << endl;589 cerr << "downsample program failed to load" << endl; 590 590 591 591 PrintGLerror("init"); … … 610 610 611 611 FrameBufferObject::Release(); 612 613 612 cgGLEnableProfile(RenderState::sCgFragmentProfile); 614 613 … … 683 682 ) 684 683 { 685 //#ifdef USE_3D_SSAO684 #ifdef USE_3D_SSAO 686 685 // bias from [-1, 1] to [0, 1] 687 686 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, … … 691 690 692 691 Matrix4x4 m = projViewMatrix * biasMatrix; 693 694 692 cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 695 //#endif 693 #else 694 cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)projViewMatrix.x); 695 #endif 696 696 697 697 698 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); … … 869 870 870 871 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 871 872 872 cgGLEnableProfile(RenderState::sCgFragmentProfile); 873 873 … … 1316 1316 void DeferredRenderer::DownSample(FrameBufferObject *fbo) 1317 1317 { 1318 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 1319 GLuint colorsTex = colorBuffer->GetTexture(); 1320 1321 cgGLEnableProfile(RenderState::sCgFragmentProfile); 1322 cgGLBindProgram(sCgDownSampleProgram); 1323 1324 cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex); 1325 cgGLEnableTextureParameter(sColorsTexDownSampleParam); 1326 1327 mDownSampleFbo->Bind(); 1328 1329 glDrawBuffers(1, mrt); 1330 1331 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1332 1333 cgGLEnableProfile(RenderState::sCgFragmentProfile); 1334 cgGLBindProgram(sCgDownSampleProgram); 1335 1318 1336 //glPushAttrib(GL_VIEWPORT_BIT); 1319 1337 glViewport(0, 0, mWidth / 2, mHeight / 2); … … 1329 1347 glPushMatrix(); 1330 1348 glLoadIdentity(); 1331 1332 1333 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);1334 GLuint colorsTex = colorBuffer->GetTexture();1335 1336 cgGLEnableProfile(RenderState::sCgFragmentProfile);1337 cgGLBindProgram(sCgDownSampleProgram);1338 1339 cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex);1340 cgGLEnableTextureParameter(sColorsTexDownSampleParam);1341 1342 mDownSampleFbo->Bind();1343 1344 glDrawBuffers(1, mrt);1345 1346 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);1347 1348 cgGLEnableProfile(RenderState::sCgFragmentProfile);1349 cgGLBindProgram(sCgDownSampleProgram);1350 1349 1351 1350 const float offs = 0.5f; … … 1364 1363 FrameBufferObject::Release(); 1365 1364 1366 //glPopAttrib();1367 glViewport(0, 0, mWidth, mHeight);1368 PrintGLerror("downsample");1369 1370 1365 float *data = (float *)mDownSampleFbo->GetColorBuffer(0)->ReadTexture(); 1371 1366 //float *data = (float *)mFbo->GetColorBuffer(colorBufferIdx)->ReadTexture(); … … 1378 1373 glPopMatrix(); 1379 1374 1375 //glPopAttrib(); 1376 glViewport(0, 0, mWidth, mHeight); 1377 PrintGLerror("downsample"); 1378 1380 1379 delete [] data; 1381 1382 PrintGLerror("shadow map");1383 1380 } 1384 1381 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r2999 r3005 86 86 mHeight = h; 87 87 88 int myformat= GL_RGBA;88 int components = GL_RGBA; 89 89 90 90 switch (format) 91 91 { 92 case BUFFER_UBYTE: 92 case RGB_UBYTE: 93 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGB8; 94 components = GL_RGB; 95 break; 96 case RGBA_UBYTE: 93 97 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; break; 94 case BUFFER_FLOAT_16:98 case RGBA_FLOAT_16: 95 99 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA16F_ARB; break; 96 case BUFFER_FLOAT_32: 100 case RGB_FLOAT_32: 101 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB32F_ARB; 102 components = GL_RGB; 103 break; 104 case RGBA_FLOAT_32: 97 105 mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break; 98 case BUFFER_LUMINANCE_ALPHA:99 mGlFormat = GL_FLOAT; mInternalFormat = GL_LUMINANCE_ALPHA ;100 myformat = GL_LUMINANCE_ALPHA;101 break;102 106 default: 103 107 mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; … … 115 119 glGenTextures(1, &mTexId); 116 120 glBindTexture(GL_TEXTURE_2D, mTexId); 117 glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, myformat, mGlFormat, NULL);121 glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, components, mGlFormat, NULL); 118 122 119 123 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_TEXTURE_2D, mTexId, 0); … … 185 189 switch (mInternalFormat) 186 190 { 191 case GL_RGB8: 192 bytes = 3; break; 187 193 case GL_RGBA8: 188 bytes = 8; break;194 bytes = 4; break; 189 195 case GL_RGBA16F_ARB: 190 196 bytes = 16; break; 197 case GL_RGB32F_ARB: 198 bytes = 24; break; 191 199 case GL_RGBA32F_ARB: 192 200 bytes = 32; break; … … 198 206 glBindTexture(GL_TEXTURE_2D, mTexId); 199 207 200 GLint width, height;208 /*GLint width, height; 201 209 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); 202 210 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); 203 204 //cout << "w: " << width << "h: " << height << endl;205 206 unsigned char *data = new unsigned char[bytes * 4 * width * height];211 cout << "w: " << width << "h: " << height << endl; 212 */ 213 214 unsigned char *data = new unsigned char[bytes * 4 * mWidth * mHeight]; 207 215 208 216 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, data); … … 210 218 glBindTexture(GL_TEXTURE_2D, 0); 211 219 glDisable(GL_TEXTURE_2D); 212 213 float *d = (float *)data;214 220 215 221 return data; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
r3001 r3005 15 15 public: 16 16 17 enum FORMAT { RGB A_UBYTE, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32};17 enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32}; 18 18 enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE }; 19 19 enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR }; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3002 r3005 203 203 DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_QUADRATIC; 204 204 205 206 static Matrix4x4 matProjectionView = IdentityMatrix();207 208 209 205 ShadowMap *shadowMap = NULL; 210 206 DirectionalLight *light = NULL; … … 287 283 static CGparameter sBLParamTex; 288 284 289 static Matrix4x4 oldViewProjMatrix;290 static Matrix4x4 old MatViewing;285 static Matrix4x4 viewProjMat = IdentityMatrix(); 286 static Matrix4x4 oldViewProjMat = IdentityMatrix(); 291 287 292 288 … … 668 664 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 669 665 // the positions buffer 670 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);671 //fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST);666 //fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 667 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 672 668 // the normals buffer 673 669 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); … … 905 901 { 906 902 // store matrix of last frame 907 oldViewProjMatrix = matProjectionView; 908 camera->GetModelViewMatrix(oldMatViewing); 903 oldViewProjMat = viewProjMat; 909 904 910 905 glMatrixMode(GL_PROJECTION); … … 926 921 927 922 // store matrix for later use 928 matProjectionView= matViewing * matProjection;923 viewProjMat = matViewing * matProjection; 929 924 930 925 if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) … … 1170 1165 // otherwise the temporal coherency is broken 1171 1166 BvhNode::SetCurrentState(1); 1172 shadowMap->RenderShadowView(shadowTraverser, matProjectionView);1167 shadowMap->RenderShadowView(shadowTraverser, viewProjMat); 1173 1168 BvhNode::SetCurrentState(0); 1174 1169 } … … 1177 1172 // actually render the scene geometry using the specified algorithm 1178 1173 traverser->RenderScene(); 1179 /* 1180 #if 0 1181 SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end(); 1182 1183 for (sit = sceneEntities.begin(); sit != sit_end; ++ sit) 1184 renderQueue->Enqueue(*sit); 1185 #else 1186 1187 SceneEntityContainer::const_iterator sit, sit_end = sceneEntities2.end(); 1188 1189 for (sit = sceneEntities2.begin(); sit != sit_end; ++ sit) 1190 renderQueue->Enqueue(*sit); 1191 #endif 1192 */ 1193 renderQueue->Apply(); 1174 //renderQueue->Apply(); 1194 1175 } 1195 1176 … … 1244 1225 1245 1226 ShadowMap *sm = showShadowMap ? shadowMap : NULL; 1246 ssaoShader->Render(fbo, oldViewProjMat rix, matProjectionView, ssaoTempCohFactor, light, useHDR, sm);1227 ssaoShader->Render(fbo, oldViewProjMat, viewProjMat, ssaoTempCohFactor, light, useHDR, sm); 1247 1228 } 1248 1229 … … 2173 2154 2174 2155 // the scene is rendered withouth any shading 2175 shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView);2156 shadowMap->ComputeShadowMap(shadowTraverser, viewProjMat); 2176 2157 2177 2158 glEnable(GL_CULL_FACE); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2992 r3005 48 48 float4 outColor; 49 49 50 if (position.w > 1e19f) outColor = color; 50 // hack: prevent shading the sky 51 if (position.z > 1e19f) outColor = color; 51 52 //if (emmisive > 1.5f) outColor = color; 52 53 else outColor = (ambient + diffuse) * color; 53 54 54 55 return outColor; 55 //return saturate((((ambient + diffuse)) * (1.0f - emmisive) + emmisive) * color);56 56 } 57 57 … … 188 188 // calc diffuse illumination + shadow term 189 189 //if ((emmisive < 1.5f) // hack: prevent shadowing the sky 190 if ( 191 (position.w < 1e19f) 190 if ((position.z < 1e19f) 192 191 && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 193 192 ) … … 209 208 // base lighting 210 209 //OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 211 OUT.color = (position. w> 1e19f) ? color: (ambient + diffuse) * color;210 OUT.color = (position.z > 1e19f) ? color: (ambient + diffuse) * color; 212 211 213 212 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3004 r3005 37 37 struct pixel 38 38 { 39 40 41 float4pos: COLOR1;42 39 float4 col: COLOR0; 40 //float4 pos: COLOR1; 41 float3 pos: COLOR1; 42 float4 norm: COLOR2; 43 43 }; 44 44 … … 113 113 pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 114 114 115 #if 1 115 116 // save world position in second render target 116 pix.pos = IN.worldPos * maxDepth; 117 // store the projected depth 118 pix.pos.w = projPos.z; 117 pix.pos = IN.worldPos.xyz * maxDepth; 118 #endif 119 119 120 120 return pix; … … 150 150 pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 151 151 152 pix.pos = IN.worldPos * maxDepth; 153 // store the projected depth154 pix.pos.w = projPos.z; 152 #if 1 153 pix.pos = IN.worldPos.xyz * maxDepth; 154 #endif 155 155 156 156 return pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
r2982 r3005 31 31 { 32 32 float4 col: COLOR0; 33 float 4pos: COLOR1;33 float3 pos: COLOR1; 34 34 float4 norm: COLOR2; 35 35 }; … … 112 112 113 113 pix.col = IN.color2; 114 pix. pos = 1e20f;114 pix.col.w = 2.0f; 115 115 116 116 pix.norm.xyz = IN.normal; 117 pix.norm.w = IN.mypos.w; 118 119 pix.pos = 1e20f; 117 120 118 pix.norm.w = IN.mypos.w;119 pix.pos.w = 1e20f;120 121 pix.col.w = 2.0f;122 123 121 return pix; 124 122 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3004 r3005 170 170 171 171 172 // the current world position173 const float4 centerPosition = tex2D(positions, IN.texCoord.xy);174 175 172 #if USE_EYE_SPACE_DEPTH 176 173 /// reconstruct position from the eye space depth 177 174 float3 viewDir = IN.view; 178 175 const float eyeDepth = tex2D(colors, IN.texCoord.xy).w; 179 float4 centerPosition2; 180 181 centerPosition 2.xyz = eyePos - viewDir * eyeDepth;182 centerPosition 2.w = centerPosition.w;183 184 const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition 2, w, eyePos, bl, br, tl, tr);176 177 float4 centerPosition; 178 centerPosition.xyz = eyePos - viewDir * eyeDepth; 179 centerPosition.w = centerPosition.w; 180 181 const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 185 182 #else 186 183 184 // the current world position 185 const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 186 187 187 const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 188 188 189 189 #endif 190 190 191 // get the current depth 191 ///////////////// 192 //-- compute temporally smoothing 193 194 float4 realPos = centerPosition * maxDepth; 195 realPos.w = 1.0f; 196 197 // calulcate the current depth 192 198 //const float currentDepth = centerPosition.w; 193 199 … … 198 204 199 205 200 /////////////////201 //-- compute temporally smoothing202 203 float4 realPos = centerPosition * maxDepth;204 realPos.w = 1.0f;205 206 207 206 /////////// 208 207 //-- reprojection new frame into old one … … 210 209 // calculate projected depth 211 210 float4 projPos = mul(oldModelViewProj, realPos); 212 projPos /= oldPos.w;211 projPos /= projPos.w; 213 212 214 213 // the current depth projected into the old frame -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3003 r3005 22 22 float4 DownSample(frag IN, 23 23 uniform sampler2D colors, 24 float2 downSampleOffs[4]): COLOR24 uniform float2 downSampleOffs[4]): COLOR 25 25 { 26 26 float4 average = .0f; … … 130 130 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 131 131 132 if (oldLogLum > 1e-5f) // too hight log lum132 if (oldLogLum > 1e-5f) // too bright 133 133 OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f); 134 134 else
Note: See TracChangeset
for help on using the changeset viewer.