Changeset 2837 for GTP/trunk/App/Demos
- Timestamp:
- 07/15/08 11:35:23 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2834 r2837 244 244 </File> 245 245 <File 246 RelativePath=".\src\Halton.cpp" 247 > 248 </File> 249 <File 250 RelativePath=".\src\Halton.h" 251 > 252 </File> 253 <File 246 254 RelativePath=".\src\Matrix4x4.cpp" 247 255 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2836 r2837 29 29 #include "PerformanceGraph.h" 30 30 #include "Environment.h" 31 #include "Halton.h" 31 32 32 33 … … 169 170 bool upKeyPressed = false; 170 171 bool downKeyPressed = false; 171 bool nineKeyPressed = false;172 bool eightKeyPressed = false;172 bool descendKeyPressed = false; 173 bool ascendKeyPressed = false; 173 174 174 175 bool useSsao = false; … … 186 187 bool useFullScreen = false; 187 188 189 float expFactor = 0.1f; 188 190 189 191 // ssao number of samples … … 275 277 276 278 static CGparameter sSamplesParamSsao; 277 278 static CGparameter sOldTexParam;279 279 static CGparameter sOldTexParamSsao; 280 281 280 static CGparameter sNoiseMultiplierParam; 281 static CGparameter sExpFactorParamSsao; 282 282 283 283 284 static void cgErrorCallback() … … 313 314 int returnCode = 0; 314 315 316 Vector3 camPos(.0f, .0f, .0f); 317 315 318 cout << "=== reading environment file === " << endl; 316 319 317 env.Read("src/default.env"); 318 319 env.GetIntParam(string("assumedVisibleFrames"), assumedVisibleFrames); 320 env.GetIntParam(string("maxBatchSize"), maxBatchSize); 321 env.GetIntParam(string("trianglesPerVirtualLeaf"), trianglesPerVirtualLeaf); 322 323 env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion); 324 env.GetFloatParam(string("keyRotation"), keyRotation); 325 326 env.GetIntParam(string("winWidth"), winWidth); 327 env.GetIntParam(string("winHeight"), winHeight); 328 329 env.GetBoolParam(string("useFullScreen"), useFullScreen); 330 //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 331 332 Vector3 camPos; 333 env.GetVectorParam(string("camPosition"), camPos); 334 335 cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 336 cout << "maxBatchSize: " << maxBatchSize << endl; 337 cout << "trianglesPerVirtualLeaf: " << trianglesPerVirtualLeaf << endl; 338 339 cout << "keyForwardMotion: " << keyForwardMotion << endl; 340 cout << "keyRotation: " << keyRotation << endl; 341 cout << "winWidth: " << winWidth << endl; 342 cout << "winHeight: " << winHeight << endl; 343 cout << "useFullScreen: " << useFullScreen << endl; 344 cout << "camPosition: " << camPos << endl; 345 320 string envFileName = "default.env"; 321 if (!env.Read(envFileName)) 322 { 323 cerr << "loading environment " << envFileName << " failed!" << endl; 324 } 325 else 326 { 327 env.GetIntParam(string("assumedVisibleFrames"), assumedVisibleFrames); 328 env.GetIntParam(string("maxBatchSize"), maxBatchSize); 329 env.GetIntParam(string("trianglesPerVirtualLeaf"), trianglesPerVirtualLeaf); 330 331 env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion); 332 env.GetFloatParam(string("keyRotation"), keyRotation); 333 334 env.GetIntParam(string("winWidth"), winWidth); 335 env.GetIntParam(string("winHeight"), winHeight); 336 337 env.GetBoolParam(string("useFullScreen"), useFullScreen); 338 //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 339 env.GetFloatParam(string("expFactor"), expFactor); 340 341 env.GetVectorParam(string("camPosition"), camPos); 342 343 cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 344 cout << "maxBatchSize: " << maxBatchSize << endl; 345 cout << "trianglesPerVirtualLeaf: " << trianglesPerVirtualLeaf << endl; 346 347 cout << "keyForwardMotion: " << keyForwardMotion << endl; 348 cout << "keyRotation: " << keyRotation << endl; 349 cout << "winWidth: " << winWidth << endl; 350 cout << "winHeight: " << winHeight << endl; 351 cout << "useFullScreen: " << useFullScreen << endl; 352 cout << "camPosition: " << camPos << endl; 353 cout << "expFactor: " << expFactor << endl; 354 } 346 355 347 356 /////////////////////////// … … 560 569 sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 561 570 sMaxDepthParamSsao = cgGetNamedParameter(sCgSsaoProgram, "maxDepth"); 571 sExpFactorParamSsao = cgGetNamedParameter(sCgSsaoProgram, "expFactor"); 562 572 563 573 cgGLSetParameter1f(sMaxDepthParamSsao, myfar / 10.0f); 574 cgGLSetParameter1f(sExpFactorParamSsao, expFactor); 564 575 565 576 sSamplesParamSsao = cgGetNamedParameter(sCgSsaoProgram, "samples"); … … 588 599 sColorsTexParam = cgGetNamedParameter(sCgDeferredProgram, "colors"); 589 600 sNormalsTexParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 590 591 sOldTexParam = cgGetNamedParameter(sCgDeferredProgram, "oldTex");592 601 } 593 602 else … … 647 656 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer); 648 657 649 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA 32F_ARB, texWidth, texHeight);658 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 650 659 int samples = 8; 651 660 //glEnable(GL_MULTISAMPLE_ARB); … … 656 665 glBindTexture(GL_TEXTURE_2D, colorsTex); 657 666 658 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA 32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);667 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 659 668 //glGenerateMipmapEXT(GL_TEXTURE_2D); 660 669 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0); … … 742 751 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer1); 743 752 744 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA 32F_ARB, texWidth, texHeight);753 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 745 754 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer1); 746 755 … … 748 757 glBindTexture(GL_TEXTURE_2D, colorsTex1); 749 758 750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA 32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);759 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 751 760 //glGenerateMipmapEXT(GL_TEXTURE_2D); 752 761 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex1, 0); … … 777 786 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer2); 778 787 779 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA 32F_ARB, texWidth, texHeight);788 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 780 789 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer2); 781 790 … … 783 792 glBindTexture(GL_TEXTURE_2D, colorsTex2); 784 793 785 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA 32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);794 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 786 795 //glGenerateMipmapEXT(GL_TEXTURE_2D); 787 796 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex2, 0); … … 789 798 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 790 799 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 791 792 800 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 793 801 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 802 794 803 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 795 804 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); … … 890 899 "", 891 900 "'-'/'+' - decreases/increases max batch size", 892 "' 4'/'5' - decreases/increases triangles per virtual bvh leaf (sets bvh depth)",893 "' 6'/'7' - decreases/increases assumed visible frames",894 "' 8'/'9' - downward/upward motion",901 "'1'/'2' - downward/upward motion", 902 "'3'/'4' - decreases/increases triangles per virtual bvh leaf (sets bvh depth)", 903 "'5'/'6' - decreases/increases assumed visible frames", 895 904 "", 896 905 "'R' - use render queue", … … 1100 1109 if (downKeyPressed) 1101 1110 KeyHorizontalMotion(-KeyShift()); 1102 if (eightKeyPressed) 1111 if (ascendKeyPressed) 1112 KeyVerticalMotion(KeyShift()); 1113 if (descendKeyPressed) 1103 1114 KeyVerticalMotion(-KeyShift()); 1104 if (nineKeyPressed)1105 KeyVerticalMotion(KeyShift());1106 1115 1107 1116 // place view on ground … … 1278 1287 traverser->SetMaxBatchSize(maxBatchSize); 1279 1288 break; 1280 case '6':1281 assumedVisibleFrames -= 1;1282 if (assumedVisibleFrames < 1) assumedVisibleFrames = 1;1283 traverser->SetAssumedVisibleFrames(assumedVisibleFrames);1284 break;1285 case '7':1286 assumedVisibleFrames += 1;1287 traverser->SetAssumedVisibleFrames(assumedVisibleFrames);1288 break;1289 1289 case 'M': 1290 1290 case 'm': … … 1292 1292 traverser->SetUseMultiQueries(useMultiQueries); 1293 1293 break; 1294 case '1': 1295 descendKeyPressed = true; 1296 break; 1297 case '2': 1298 ascendKeyPressed = true; 1299 break; 1300 case '3': 1301 if (trianglesPerVirtualLeaf >= 100) 1302 trianglesPerVirtualLeaf -= 100; 1303 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 1304 break; 1305 case '4': 1306 trianglesPerVirtualLeaf += 100; 1307 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 1308 break; 1309 case '5': 1310 assumedVisibleFrames -= 1; 1311 if (assumedVisibleFrames < 1) assumedVisibleFrames = 1; 1312 traverser->SetAssumedVisibleFrames(assumedVisibleFrames); 1313 break; 1314 case '6': 1315 assumedVisibleFrames += 1; 1316 traverser->SetAssumedVisibleFrames(assumedVisibleFrames); 1317 break; 1318 case '7': 1319 expFactor *= 0.5f; 1320 break; 1294 1321 case '8': 1295 eightKeyPressed = true; 1296 break; 1297 case '9': 1298 nineKeyPressed = true; 1299 break; 1322 expFactor *= 2.0f; 1323 if (expFactor > 1.0f) expFactor = 1.0f; 1324 break; 1300 1325 case 'o': 1301 1326 case 'O': … … 1333 1358 } 1334 1359 break; 1335 case '4':1336 if (trianglesPerVirtualLeaf >= 100)1337 trianglesPerVirtualLeaf -= 100;1338 1339 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf);1340 break;1341 case '5':1342 trianglesPerVirtualLeaf += 100;1343 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf);1344 break;1345 1360 default: 1346 1361 return; … … 1394 1409 downKeyPressed = false; 1395 1410 break; 1396 case '8': 1397 eightKeyPressed = false; 1398 break; 1399 1400 case '9': 1401 nineKeyPressed = false; 1411 case '1': 1412 descendKeyPressed = false; 1413 break; 1414 case '2': 1415 ascendKeyPressed = false; 1402 1416 break; 1403 1417 … … 2094 2108 2095 2109 cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 17.0f)); 2110 cgGLSetParameter1f(sExpFactorParamSsao, expFactor); 2096 2111 2097 2112 GenerateSamples(); cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); … … 2109 2124 cgGLSetTextureParameter(sNormalsTexParam, normalsTex); 2110 2125 cgGLEnableTextureParameter(sNormalsTexParam); 2111 2112 cgGLSetTextureParameter(sOldTexParam, oldTex);2113 cgGLEnableTextureParameter(sOldTexParam);2114 2126 } 2115 2127 … … 2146 2158 cgGLDisableTextureParameter(sPositionsTexParam); 2147 2159 cgGLDisableTextureParameter(sNormalsTexParam); 2148 cgGLDisableTextureParameter(sOldTexParam);2149 2160 } 2150 2161 … … 2212 2223 void GenerateSamples() 2213 2224 { 2225 static HaltonSequence halton; 2226 2227 float r[2]; 2228 2214 2229 // generates poisson distribution on disc 2215 2230 float minDist = 2.0f / sqrt((float)NUM_SAMPLES); … … 2227 2242 ++ totalTries; 2228 2243 2229 const float rx = RandomValue(-1, 1); 2230 const float ry = RandomValue(-1, 1); 2244 halton.GetNext(2, r); 2245 2246 //const float rx = RandomValue(-1, 1); 2247 //const float ry = RandomValue(-1, 1); 2248 2249 const float rx = r[0] * 2.0f - 1.0f; 2250 const float ry = r[1] * 2.0f - 1.0f; 2231 2251 2232 2252 // check if in disk, else exit early … … 2260 2280 } 2261 2281 } 2262 //cout << "sample: " << samples[i] << " " << i / 2 << " " << samples[i + 1] << " r: " << sqrt(samples[i] * samples[i] + samples[i + 1] * samples[i + 1]) << " tries: " << totalTries << endl;2282 //cout << "sample: " << samples[i] << " " << i / 2 << " " << samples[i + 1] << " r: " << sqrt(samples[i] * samples[i] + samples[i + 1] * samples[i + 1]) << " tries: " << totalTries << endl; 2263 2283 } 2264 2284 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2836 r2837 5 5 //#define NUM_SAMPLES 8 6 6 #define NUM_SAMPLES 16 7 8 // rule of thumb: approx 1 / NUM_SAMPLES 9 #define SAMPLE_INTENSITY 0.2 7 10 //#define SAMPLE_INTENSITY 0.125f 8 // rule of thumb: approx 1 / NUM_SAMPLES9 #define SAMPLE_INTENSITY 0.22 //0.0625f10 11 11 12 #define AREA_SIZE 5e-1f 12 13 #define VIEW_CORRECTION_SCALE 0.3f 14 #define DISTANCE_SCALE 1e-6f 13 15 14 16 struct fragment … … 23 25 struct pixel 24 26 { 25 27 float4 color: COLOR0; 26 28 }; 27 29 … … 96 98 97 99 // distance between current position and sample position controls AO intensity. 98 const float distanceScale = 1e-6f;99 100 100 float distance_intensity = 101 (SAMPLE_INTENSITY * distanceScale) / (distanceScale+ length_to_sample * length_to_sample);101 (SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample); 102 102 103 103 // if normal perpenticular to view dir, only half of the samples count 104 float view_correction = 1.0f + 0.5f* (1.0f - dot(currentViewDir, currentNormal));104 float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 105 105 106 106 total_ao += cos_angle * distance_intensity * view_correction; … … 119 119 uniform float3 currentViewDir, 120 120 uniform float noiseMultiplier, 121 uniform float4 centerPosition) 121 uniform float4 centerPosition 122 ) 122 123 { 123 124 // the w coordinate from the persp. projection … … 158 159 159 160 // distance between current position and sample position controls AO intensity. 160 const float distanceScale = 1e-6f;161 162 161 float distance_intensity = 163 (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample); 164 165 const float view_correction_scale = 0.5f; 162 (SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample); 163 166 164 // if normal perpenticular to view dir, only half of the samples count 167 float view_correction = 1.0f + view_correction_scale* (1.0f - dot(currentViewDir, currentNormal));165 float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 168 166 169 167 total_ao += cos_angle * distance_intensity * view_correction; … … 213 211 uniform sampler2D oldTex, 214 212 const uniform float4x4 oldModelViewProj, 215 uniform float maxDepth 213 uniform float maxDepth, 214 uniform float expFactor 216 215 ) 217 216 { … … 230 229 float4 col = shade(IN, colors, positions, normal.xyz, amb); 231 230 232 //float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 233 float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 234 float ao = new_col.w; 235 236 float4 attenuated_color = ao * col + new_col; 237 //float4 attenuated_color = ao * col; 238 239 //OUT.color = ao; 240 //OUT.color = ao * col; 241 //float4 col1 = attenuated_color; 242 243 const float x = 0.1f; 231 float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 232 float4 attenuated_color = ao * col; 233 234 //float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 235 //float ao = new_col.w; 236 //float4 attenuated_color = ao * col + new_col; 237 238 const float x = expFactor; 244 239 245 240 float4 dummy = centerPosition * maxDepth; … … 254 249 255 250 float oldDepth = col1.w; 256 257 if ((tex.x >= 0.0f) && (tex.x < 1.0f) && (tex.y >= 0.0f) && (tex.y < 1.0f) && (abs(newDepth - oldDepth) < 9e-4f)) 258 OUT.color = attenuated_color * x + col1 * float4(1.0f - x); 251 float depthDif = 1.0f - newDepth / oldDepth; 252 253 if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 254 (tex.y >= 0.0f) && (tex.y < 1.0f) && 255 (abs(depthDif) < 9e-4f)) 256 OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor); 259 257 else 260 258 OUT.color = attenuated_color; 261 259 262 //OUT.color = float4(centerPosition.w);263 //OUT.color = float4(oldDepth);264 //OUT.color = float4(newDepth);265 //OUT.color = float4(abs(newDepth - oldDepth));266 260 OUT.color.w = tex2D(colors, IN.texCoord.xy).w; 267 261 … … 273 267 uniform sampler2D colors, 274 268 uniform sampler2D positions, 275 uniform sampler2D normals, 276 uniform sampler2D oldTex 269 uniform sampler2D normals 277 270 ) 278 271 { … … 282 275 float amb = normal.w; 283 276 284 //OUT.color.xyz = IN.view;285 277 // expand normal 286 278 normal = normalize(normal * 2.0f - float4(1.0f)); 287 279 288 280 float4 col = shade(IN, colors, positions, normal.xyz, amb); 289 //OUT.color = col; 290 291 float4 col1 = tex2D(oldTex, IN.texCoord.xy); 292 293 const float x = 0.01f; 294 OUT.color = col * x + col1 * float4(1.0f - x); 281 OUT.color = col; 295 282 296 283 return OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2836 r2837 105 105 // hack: squeeze some information about ambient into the texture 106 106 pix.norm.w = ambient.x; 107 pix.pos.w = IN.mypos.w; //IN.projPos.w;107 pix.pos.w = IN.mypos.w; 108 108 pix.col.w = IN.mypos.z / IN.mypos.w; 109 109
Note: See TracChangeset
for help on using the changeset viewer.