- Timestamp:
- 08/31/08 13:15:30 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2886 r2887 551 551 </File> 552 552 <File 553 RelativePath=".\src\Light.h" 554 > 555 </File> 556 <File 553 557 RelativePath=".\src\LODInfo.h" 554 558 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r2868 r2887 10 10 winHeight=768 11 11 camPosition=483.398f 242.364f 186.078f 12 camDirection= 1 0 012 camDirection=-1 0 0 13 13 useFullScreen=0 14 14 useLODs=1 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2885 r2887 368 368 369 369 // store near plane 370 sNearPlane = Plane3( mCamera->GetDirection(), mCamera->GetPosition());370 sNearPlane = Plane3(-mCamera->GetDirection(), mCamera->GetPosition()); 371 371 } 372 372 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2864 r2887 8 8 9 9 using namespace std; 10 11 // this is the start vector. 12 // warning: our coordinate system has the negative z axis pointing up 13 // which is different from the system used in opengl!! 14 static Vector3 startVector = Vector3(0, 1, 0); 10 15 11 16 … … 20 25 21 26 mPitch = mYaw = 0; 22 Precompute(Vector3(0, 1, 0)); 27 Precompute(startVector); 28 29 CalculateFromPitchAndYaw(); 23 30 } 24 31 … … 36 43 37 44 mPitch = mYaw = 0; 38 Precompute(Vector3(0, 1, 0)); 45 Precompute(startVector); 46 47 CalculateFromPitchAndYaw(); 39 48 } 40 49 … … 49 58 mViewOrientation = mBaseOrientation; 50 59 } 51 52 60 53 61 … … 173 181 const float h_far = w_far / GetAspect(); 174 182 175 const Vector3 view = GetDirection();183 const Vector3 view = -GetDirection(); 176 184 const Vector3 fc = mPosition + view * z_far; 177 185 … … 225 233 Normalize(dir); 226 234 227 mPitch = atan2(dir.x, dir.z); 228 mYaw = atan2(dir.y, sqrt((dir.x * dir.x) + (dir.z * dir.z))); 235 //mPitch = atan2(dir.x, dir.z); 236 //mYaw = atan2(dir.y, sqrt((dir.x * dir.x) + (dir.z * dir.z))); 237 238 mPitch = -atan2(dir.x, dir.y); 239 mYaw = atan2(dir.z, sqrt((dir.x * dir.x) + (dir.y * dir.y))); 229 240 230 241 CalculateFromPitchAndYaw(); … … 246 257 Vector3 Camera::GetDirection() const 247 258 { 248 return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]);259 return Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 249 260 } 250 261 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r2879 r2887 5 5 #include "SceneQuery.h" 6 6 #include "RenderTraverser.h" 7 #include "FrameBufferObject.h" 8 7 9 #include <IL/il.h> 8 10 #include <assert.h> 9 #include "FrameBufferObject.h" 11 10 12 11 13 … … 33 35 34 36 35 void startil()37 static void startil() 36 38 { 37 39 ilInit(); … … 40 42 41 43 42 void stopil()44 static void stopil() 43 45 { 44 46 ilShutDown(); … … 51 53 52 54 53 //void GrabDepthBuffer(float *data, RenderTexture *rt) 54 void GrabDepthBuffer(float *data, GLuint depthTexture) 55 static void GrabDepthBuffer(float *data, GLuint depthTexture) 55 56 { 56 57 glEnable(GL_TEXTURE_2D); … … 64 65 65 66 66 void ExportDepthBuffer(float *data)67 static void ExportDepthBuffer(float *data) 67 68 { 68 69 startil(); … … 92 93 93 94 94 SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer): 95 SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, 96 RenderTraverser *renderer): 95 97 mSceneBox(sceneBox), mDepth(NULL) 96 98 { … … 135 137 136 138 orthoCam->SetNear(0.0f); 137 orthoCam->Yaw(M_PI * 0.5f); 138 139 orthoCam->SetDirection(Vector3(0, 0, 1)); 140 141 cout << orthoCam->GetDirection() << endl; 139 142 Vector3 pos = Vector3(mSceneBox.Center().x, mSceneBox.Center().y, mSceneBox.Max().z); 140 143 orthoCam->SetPosition(pos); … … 147 150 148 151 glDrawBuffers(1, mrt); 149 152 153 glPushAttrib(GL_VIEWPORT_BIT); 150 154 glViewport(0, 0, texWidth, texHeight); 151 glPushAttrib(GL_VIEWPORT_BIT);152 155 153 156 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 186 189 187 190 GrabDepthBuffer(mDepth, fbo->GetDepthTex()); 188 //ExportDepthBuffer(mDepth); PrintGLerror("grab");191 ExportDepthBuffer(mDepth); PrintGLerror("grab"); 189 192 190 193 DEL_PTR(fbo); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2886 r2887 104 104 /** Generate poisson disc distributed sample points on the unit disc 105 105 */ 106 static void GenerateSamples() 107 { 108 #if 0 109 static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 110 poisson.Generate((Sample2 *)samples); 111 #else 112 113 const float radius = 1.0f; 114 const float sigma = ComputeSigmaFromRadius(1.0f); 115 116 static HaltonSequence halton; 117 118 for (int i = 0; i < NUM_SAMPLES; ++ i) 119 { 120 Sample2 s; 121 Vector3 input; 122 123 halton.GetNext(3, (float *)&input.x); 124 125 PolarGaussianOnDisk(input, // input (RND in interval [0-1)x[0-1)) 126 sigma, // standard deviation of gaussian distribution 127 radius, // standard deviation of gaussian distribution 128 s); // result 129 samples[i] = s; 130 } 131 #endif 106 static void GenerateSamples(int sampling) 107 { 108 switch (sampling) 109 { 110 case SsaoShader::POISSON: 111 { 112 static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 113 poisson.Generate((Sample2 *)samples); 114 } 115 break; 116 case SsaoShader::GAUSS: 117 { 118 const float radius = 1.0f; 119 const float sigma = 0.25f;//ComputeSigmaFromRadius(1.0f); 120 121 static HaltonSequence halton; 122 123 for (int i = 0; i < NUM_SAMPLES; ++ i) 124 { 125 Sample2 s; 126 Vector3 input; 127 128 halton.GetNext(3, (float *)&input.x); 129 130 //GaussianOn2D(cinput, // input (RND in interval [0-1)x[0-1)) 131 // sigma, // standard deviation of gaussian distribution 132 // outputVec) // resulting vector according to gaussian distr. 133 134 PolarGaussianOnDisk(input, // input (RND in interval [0-1)x[0-1)) 135 sigma, // standard deviation of gaussian distribution 136 radius, // standard deviation of gaussian distribution 137 s); // result 138 samples[i] = s; 139 } 140 } 141 break; 142 default: 143 break; 144 } 132 145 } 133 146 … … 179 192 mScaleFactor(scaleFactor), 180 193 mUseTemporalCoherence(true), 181 mUseGlobIllum(false) 194 mUseGlobIllum(false), 195 mSampling(POISSON) 182 196 { 183 197 // create noise texture for ssao … … 286 300 287 301 // generate samples for ssao kernel 288 GenerateSamples();302 //GenerateSamples(mSampling); 289 303 290 304 sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples"); … … 292 306 //cgCompileProgram(sCgSsaoProgram); 293 307 294 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);308 //cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 295 309 } 296 310 else … … 326 340 327 341 // generate samples for ssao kernel 328 GenerateSamples();329 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples);342 //GenerateSamples(); 343 //cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 330 344 331 345 cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f)); … … 515 529 // in the first case, the sample patterns look nicer, but the kernel 516 530 // needs longer to converge 517 GenerateSamples( );531 GenerateSamples(mSampling); 518 532 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 519 533 } … … 755 769 // in the first case, the sample patterns look nicer, but the kernel 756 770 // needs longer to converge 757 GenerateSamples( );771 GenerateSamples(mSampling); 758 772 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 759 773 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
r2886 r2887 47 47 void SetUseTemporalCoherence(bool temporal); 48 48 49 enum SAMPLING_METHOD {POISSON, GAUSS}; 50 51 void SetSamplingMethod(int s) { mSampling = s;} 52 49 53 50 54 protected: … … 80 84 bool mUseGlobIllum; 81 85 bool mUseTemporalCoherence; 86 87 int mSampling; 82 88 }; 83 89 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2884 r2887 35 35 #include "SsaoShader.h" 36 36 #include "DeferredShader.h" 37 #include "ShadowMapping.h" 38 #include "Light.h" 37 39 38 40 … … 170 172 bool useLODs = true; 171 173 174 int samplingMethod = SsaoShader::POISSON; 172 175 173 176 static Matrix4x4 matProjectionView = IdentityMatrix(); 174 177 175 178 ShadowMapping *shadowMapping = NULL; 179 Light *light = NULL; 176 180 177 181 // function forward declarations … … 213 217 214 218 219 215 220 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 216 221 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } … … 326 331 camera->SetNear(nearDist); 327 332 333 cout << "here2 " << Normalize(camDir) << endl; 334 328 335 camera->SetDirection(camDir); 336 cout << "here3 " << camera->GetDirection() << endl; 329 337 camera->SetPosition(camPos); 330 338 … … 425 433 DeferredShader::Init(sCgContext); 426 434 SsaoShader::Init(sCgContext); 435 ShadowMapping::Init(sCgContext); 427 436 428 437 //deferredShader = new DeferredShader(texWidth, texHeight); 429 438 //ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 430 439 440 431 441 // initialize the render traverser 432 442 ResetTraverser(); … … 435 445 436 446 sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 447 448 light = new Light(Vector3(0, 0, -1), RgbaColor(1, 1, 1, 1)); 449 450 shadowMapping = new ShadowMapping(bvh->GetBox(), 512); 451 shadowMapping->ComputeShadowMap(light, traverser); 437 452 438 453 // frame time is restarted every frame … … 845 860 camera->Pitch(-KeyRotationAngle()); 846 861 if (upKeyPressed) 862 KeyHorizontalMotion(-KeyShift()); 863 if (downKeyPressed) 847 864 KeyHorizontalMotion(KeyShift()); 848 if (downKeyPressed)849 KeyHorizontalMotion(-KeyShift());850 865 if (ascendKeyPressed) 851 866 KeyVerticalMotion(KeyShift()); … … 862 877 } 863 878 879 880 //shadowMapping->ComputeShadowMap(light, traverser); 881 882 883 864 884 // render without shading 865 885 switch (renderType) … … 1098 1118 SceneEntity::SetUseLODs(useLODs); 1099 1119 break; 1120 case 'P': 1121 case 'p': 1122 if (samplingMethod == SsaoShader::GAUSS) 1123 samplingMethod = SsaoShader::POISSON; 1124 else 1125 samplingMethod = SsaoShader::GAUSS; 1126 1127 ssaoShader->SetSamplingMethod(samplingMethod); 1128 1129 break; 1100 1130 case 'g': 1101 1131 case 'G': … … 1345 1375 camera->Pitch(eyeXAngle); 1346 1376 1347 pos += horView * (yMotionBegin - y) * 0.2f;1377 pos -= horView * (yMotionBegin - y) * 0.2f; 1348 1378 1349 1379 camera->SetPosition(pos); … … 1387 1417 rVec = rot * rVec; 1388 1418 1389 pos -= rVec * (x - horizontalMotionBegin) * 0.1f;1419 pos += rVec * (x - horizontalMotionBegin) * 0.1f; 1390 1420 pos[2] += (verticalMotionBegin - y) * 0.1f; 1391 1421 … … 1496 1526 glMultMatrixf((float *)rotZ.x); 1497 1527 1528 // inverse translation in order to fix current position 1498 1529 Vector3 pos = camera->GetPosition(); 1499 1530 glTranslatef(-pos.x, -pos.y, -pos.z); … … 1508 1539 glClear(GL_DEPTH_BUFFER_BIT); 1509 1540 1510 1511 1541 //////////// 1512 1542 //-- visualization of the occlusion culling 1513 1543 1514 1544 visualization->Render(); 1515 1545 1546 glColor3f(0.0f, 1.0f, 0.0f); 1547 glBegin(GL_LINES); 1548 glVertex3d(pos.x, pos.y, pos.z); 1549 glVertex3d(pos.x + 100, pos.y, pos.z); 1550 glEnd(); 1551 1552 glColor3f(0.0f, 0.0f, 1.0f); 1553 glBegin(GL_LINES); 1554 glVertex3d(pos.x, pos.y, pos.z); 1555 glVertex3d(pos.x, pos.y + 100, pos.z); 1556 glEnd(); 1516 1557 1517 1558 // reset previous settings -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2886 r2887 2 2 #define __SHADERENV_H 3 3 4 #define NUM_SAMPLES 85 //#define NUM_SAMPLES 164 //#define NUM_SAMPLES 8 5 #define NUM_SAMPLES 16 6 6 7 7 // rule of thumb: approx 1 / NUM_SAMPLES 8 //#define SAMPLE_INTENSITY 0.15f9 #define SAMPLE_INTENSITY 0.25f8 #define SAMPLE_INTENSITY 0.14f 9 //#define SAMPLE_INTENSITY 0.28f 10 10 11 11 #define AREA_SIZE 5e-1f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r2884 r2887 84 84 float4 s3 = tex2Dlod(colors, float4(offset + IN.lb.xy * w, 0, 0)); 85 85 86 float4 sx = tex2D(colors, IN.c.xy); 87 88 //return (sx + sx) * 0.5f; 86 //float4 sx = tex2D(colors, IN.c.xy); 89 87 90 88 return (s0 + s1 + s2 + s3) * 0.25f; 91 //return (s0 + s1 + s2 + s3) * 0.25f;92 93 89 //return float4(w); 94 90 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2884 r2887 24 24 { 25 25 float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 26 //float4 lightDir = float4(0.0f, 1.0f, 0.0f, 0.0f); 26 27 float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 27 28 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2884 r2887 96 96 97 97 // if normal perpenticular to view dir, only half of the samples count 98 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 99 100 total_color.w -= cos_angle * distance_intensity * view_correction; 101 102 total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 98 //const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 99 //total_color.w -= cos_angle * distance_intensity * view_correction; 100 //total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 101 102 total_color.w -= cos_angle * distance_intensity; 103 total_color.xyz += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; 103 104 } 104 105 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2886 r2887 88 88 // if surface normal perpenticular to view dir, approx. half of the samples will not count 89 89 // => compensate for this (on the other hand, projected sampling area could be larger!) 90 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 90 //const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 91 //total_ao += cos_angle * distance_intensity * view_correction; 91 92 92 total_ao += cos_angle * distance_intensity * view_correction;93 total_ao += cos_angle * distance_intensity; 93 94 } 94 95 95 return max(0.0f, 1.0f - total_ao); 96 //return max(0.0f, 1.0f - total_ao); 97 return saturate(dot(currentViewDir, currentNormal)); 96 98 } 97 99 … … 178 180 float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 179 181 180 OUT.illum_col = col * ao.x; 181 //OUT.illum_col = ao; 182 //OUT.illum_col = col * ao.x; 183 OUT.illum_col = ao; 184 182 185 OUT.illum_col.w = ao.w; 183 186
Note: See TracChangeset
for help on using the changeset viewer.