Changeset 2954 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 09/17/08 19:35:11 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2951 r2954 389 389 390 390 391 void Bvh::UpdateMinDistance(BvhNode *node) const 392 { 393 node->mDistance = node->GetBox().GetMinDistance(sNearPlane); 391 void Bvh::UpdateDistance(BvhNode *node) const 392 { 393 //node->mDistance = node->GetBox()GetMinDistance(sNearPlane); 394 node->mDistance = sNearPlane.Distance(node->GetBox().Center()); 394 395 } 395 396 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r2951 r2954 524 524 */ 525 525 void InitFrame(Camera *camera); 526 /** Stores the orthogonal distance from the viewpoint 527 to the nearest bounding box vertex with the node.526 /** Stores the orthogonal distance from the viewpoint to a point on the node. 527 We choose the the nearest bounding box vertex . 528 528 Note that negative values can appear because culling is done only afterwards 529 529 */ 530 void Update MinDistance(BvhNode *node) const;530 void UpdateDistance(BvhNode *node) const; 531 531 /** Returns the maximum distance from the near plane to this node. 532 532 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Light.h
r2952 r2954 19 19 20 20 Vector3 GetDirection() const { return mDirection; } 21 void SetDirection(const Vector3 &dir) { mDirection = dir; } 21 22 22 23 RgbaColor GetColor() const { return mColor; } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r2953 r2954 65 65 void RenderTraverser::EnqueueNode(BvhNode *node) 66 66 { 67 mBvh->Update MinDistance(node);67 mBvh->UpdateDistance(node); 68 68 mDistanceQueue.push(node); 69 69 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r2930 r2954 172 172 void QuadraticDiscSampleGenerator2::Generate(float *samples) const 173 173 { 174 #if 0 174 175 float r[2]; 175 176 Sample2 *s = (Sample2 *)samples; … … 185 186 s[i].x = mRadius * r[1] * sin(2.0f * M_PI * r[0]); 186 187 s[i].y = mRadius * r[1] * cos(2.0f * M_PI * r[0]); 187 188 //s[i].x = mRadius * r[1] * r[1] * sin(2.0f * M_PI * r[0]); 189 //s[i].y = mRadius * r[1] * r[1] * cos(2.0f * M_PI * r[0]); 190 } 191 } 188 } 189 #else 190 191 PoissonDiscSampleGenerator2 poisson(mNumSamples, 1.0f); 192 poisson.Generate(samples); 193 194 Sample2 *s = (Sample2 *)samples; 195 196 // multiply with lenght to get quadratic dependence on the distance 197 for (int i = 0; i < mNumSamples; ++ i) 198 { 199 Sample2 spl = s[i]; 200 201 float len = sqrt(spl.x * spl.x + spl.y * spl.y); 202 spl.x *= len * mRadius; 203 spl.y *= len * mRadius; 204 } 205 #endif 206 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2953 r2954 266 266 if (sinGamma < 1e-6f) return 1e6f; 267 267 268 return (nearPlane + sqrt(nearPlane * (nearPlane + d * sinGamma))) / sinGamma; 268 const float scale = 2.0f; 269 return scale * (nearPlane + sqrt(nearPlane * (nearPlane + d * sinGamma))) / sinGamma; 269 270 } 270 271 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2953 r2954 37 37 #include "Light.h" 38 38 #include "SceneEntityConverter.h" 39 #include "SunColor.h" 40 39 41 40 42 … … 71 73 int renderMode = RenderTraverser::CHCPLUSPLUS; 72 74 // eye near plane distance 73 float nearDist = 1.0f;75 float nearDist = 0.2f; 74 76 float farDist = 1e6f; 75 77 /// the field of view … … 171 173 172 174 bool useLODs = true; 175 176 bool moveLight = false; 173 177 174 178 //DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON; … … 235 239 void InitFBO(); 236 240 241 void RightMotionLight(int x, int y); 242 237 243 void RenderShadowMap(float newfar); 238 244 … … 638 644 Transform3 *tf = new Transform3(NULL); 639 645 cube = SceneEntityConverter().ConvertBox(box, mat, tf); 646 647 ////////////////////////////// 648 649 GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f}; 650 651 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 652 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 653 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT); 640 654 } 641 655 … … 751 765 void SetupLighting() 752 766 { 753 glEnable(GL_LIGHTING);767 //glEnable(GL_LIGHTING); 754 768 glEnable(GL_LIGHT0); 755 769 770 Vector3 lightDir = -light->GetDirection(); 771 772 756 773 /////////// 757 774 //-- first light: sunlight 758 775 759 //GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; 760 GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0}; 761 GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 762 GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 776 GLfloat ambient[] = {0.25f, 0.25f, 0.3f, 1.0f}; 777 GLfloat diffuse[] = {1.0f, 0.95f, 0.85f, 1.0f}; 778 GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f}; 779 780 Vector3 sunAmbient; 781 Vector3 sunDiffuse; 782 783 Vector3 h; 784 785 h.x = lightDir.x; 786 h.y = lightDir.z; 787 h.z = lightDir.y; 788 789 790 SunColor().Compute(h, sunAmbient, sunDiffuse); 791 792 const float maxComponent = sunDiffuse.MaxComponent(); 793 //cout<< "sunambient: " << sunAmbient << " mag " << Magnitude(sunDiffuse) << " max: " << maxComponent << endl; 794 795 ambient[0] = sunAmbient.x; 796 ambient[1] = sunAmbient.y; 797 ambient[2] = sunAmbient.z; 798 799 sunDiffuse /= maxComponent; 800 801 diffuse[0] = sunDiffuse.x; 802 diffuse[1] = sunDiffuse.y; 803 diffuse[2] = sunDiffuse.z; 804 805 //cout<< "sunambient: " << sunAmbient << endl; 806 //cout<< "sundiffuse: " << sunDiffuse << endl; 763 807 764 808 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); … … 766 810 glLightfv(GL_LIGHT0, GL_SPECULAR, specular); 767 811 768 Vector3 lightDir = -light->GetDirection();769 812 GLfloat position[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f}; 770 813 glLightfv(GL_LIGHT0, GL_POSITION, position); 771 772 #if 0773 774 ////////////775 //-- second light776 777 // physically incorrect to have second directional light,778 // but gives nicer shading for fixed function779 780 glEnable(GL_LIGHT1);781 782 GLfloat ambient1[] = {0.2, 0.2, 0.2, 1.0};783 GLfloat diffuse1[] = {1.0, 1.0, 1.0, 1.0};784 GLfloat specular1[] = {0.0, 0.0, 0.0, 1.0};785 786 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);787 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);788 glLightfv(GL_LIGHT1, GL_SPECULAR, specular1);789 790 GLfloat position1[] = {-0.5f, 0.5f, 0.4f, 0.0f};791 glLightfv(GL_LIGHT1, GL_POSITION, position1);792 793 //GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};794 795 #endif796 797 //////////////////////////////798 799 GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};800 801 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);802 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);803 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT);804 814 } 805 815 … … 876 886 cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 877 887 878 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);879 888 } 880 889 … … 956 965 state.SetUseAlphaToCoverage(false); 957 966 967 state.Reset(); 958 968 state.SetRenderType(RenderState::DEPTH_PASS); 959 969 … … 1009 1019 glEnableClientState(GL_NORMAL_ARRAY); 1010 1020 1021 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1022 1011 1023 break; 1012 1024 } … … 1022 1034 1023 1035 // set up lights 1024 Vector3 lightDir = -light->GetDirection(); 1025 GLfloat lightPos[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f}; 1026 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); 1027 1028 // second light 1029 //GLfloat lightPos1[] = {-0.5f, 0.5f, 0.4f, 0.0f}; 1030 //glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); 1036 SetupLighting(); 1031 1037 1032 1038 … … 1380 1386 showAlgorithmTime = !showAlgorithmTime; 1381 1387 break; 1382 1388 case GLUT_KEY_F10: 1389 moveLight = !moveLight; 1390 break; 1383 1391 case GLUT_KEY_LEFT: 1384 1392 { … … 1405 1413 } 1406 1414 break; 1407 case GLUT_ACTIVE_ALT:1408 altKeyPressed = true;1409 break;1410 1415 default: 1411 1416 return; … … 1443 1448 void Mouse(int button, int state, int x, int y) 1444 1449 { 1445 int specialKey = glutGetModifiers();1446 1447 1450 if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN)) 1448 1451 { … … 1458 1461 yMotionBegin = y; 1459 1462 1460 glutMotionFunc(RightMotion); 1463 if (!moveLight) 1464 glutMotionFunc(RightMotion); 1465 else 1466 glutMotionFunc(RightMotionLight); 1461 1467 } 1462 1468 else if ((button == GLUT_MIDDLE_BUTTON) && (state == GLUT_DOWN)) … … 1490 1496 camera->SetPosition(pos); 1491 1497 1498 xEyeBegin = x; 1499 yMotionBegin = y; 1500 1501 glutPostRedisplay(); 1502 } 1503 1504 1505 void RightMotionLight(int x, int y) 1506 { 1507 float theta = 0.2f * M_PI * (xEyeBegin - x) / 180.0f; 1508 float phi = 0.2f * M_PI * (yMotionBegin - y) / 180.0f; 1509 1510 Vector3 lightDir = light->GetDirection(); 1511 1512 Matrix4x4 roty = RotationYMatrix(theta); 1513 Matrix4x4 rotx = RotationXMatrix(phi); 1514 1515 lightDir = roty * lightDir; 1516 lightDir = rotx * lightDir; 1517 1518 light->SetDirection(lightDir); 1519 1492 1520 xEyeBegin = x; 1493 1521 yMotionBegin = y; … … 1928 1956 glDrawBuffers(3, mrt); 1929 1957 glClear(GL_COLOR_BUFFER_BIT); 1958 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1930 1959 } 1931 1960 else -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2930 r2954 27 27 28 28 #define ILLUM_INTENSITY 5e-1f; 29 //#define ILLUM_INTENSITY 9e-1f; 29 30 30 31 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2952 r2954 36 36 float3 lightDir) 37 37 { 38 const float diffuseLight = saturate(dot(normal, lightDir));39 40 38 /* 41 39 float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); … … 43 41 float diffuseLight2 = saturate(dot(normal, light2)); 44 42 */ 45 float diffuse = diffuseLight;// + diffuseLight2; 43 // diffuse intensity 44 const float angle = saturate(dot(normal, lightDir)); 45 46 float4 lightDiffuse = glstate.light[0].diffuse; 47 float4 diffuse = angle * lightDiffuse; 46 48 47 49 // global ambient 48 const float4 ambient = 0.25f; 49 //const float4 ambient = 0.0f; 50 50 const float4 ambient = glstate.light[0].ambient; 51 51 52 return (ambient + diffuse) * color * (1.0f - amb) + amb * color; 52 53 } … … 76 77 float4 col = shade(IN, color, position, normal, amb, lightDir); 77 78 78 //OUT.color = float4(1.0f);79 79 OUT.color = col; 80 80 OUT.color.w = color.w; … … 93 93 ) 94 94 { 95 //float shadowDepth = tex2D(shadowMap, lightSpacePos).x; 96 //return step(depth, shadowDepth); 97 95 98 float total_d = 0.0; 96 99 97 100 for (int i = 0; i < NUM_SAMPLES; ++ i) 98 101 { … … 120 123 return total_d; 121 124 } 122 123 124 #if 0125 /** The mrt shader for standard rendering126 */127 pixel main_shadow(fragment IN,128 uniform sampler2D colors,129 uniform sampler2D positions,130 uniform sampler2D normals,131 uniform sampler2D shadowMap,132 uniform float4x4 shadowMatrix,133 uniform float maxDepth,134 uniform float sampleWidth,135 uniform float3 lightDir136 )137 {138 pixel OUT;139 140 float4 norm = tex2D(normals, IN.texCoord.xy);141 float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));142 float4 position = tex2D(positions, IN.texCoord.xy);143 144 145 // an ambient color term146 float amb = norm.w;147 148 float3 normal = normalize(norm.xyz);149 float4 col = shade(IN, color, position, normal, amb);150 151 position *= maxDepth;152 position.w = 1.0f;153 154 float4 lightSpacePos = mul(shadowMatrix, position);155 lightSpacePos /= lightSpacePos.w;156 157 OUT.color = col;158 159 float shadowDepth[9];160 161 float w = sampleWidth;162 163 // pcf sampling using 3 x 3 tab164 shadowDepth[0] = tex2D(shadowMap, lightSpacePos.xy).x;165 166 shadowDepth[1] = tex2D(shadowMap, lightSpacePos.xy + float2( w, w)).x;167 shadowDepth[2] = tex2D(shadowMap, lightSpacePos.xy + float2( w, -w)).x;168 shadowDepth[3] = tex2D(shadowMap, lightSpacePos.xy + float2(-w, -w)).x;169 shadowDepth[4] = tex2D(shadowMap, lightSpacePos.xy + float2(-w, w)).x;170 171 shadowDepth[5] = tex2D(shadowMap, lightSpacePos.xy + float2( w, 0)).x;172 shadowDepth[6] = tex2D(shadowMap, lightSpacePos.xy + float2( 0, w)).x;173 shadowDepth[7] = tex2D(shadowMap, lightSpacePos.xy + float2(-w, 0)).x;174 shadowDepth[8] = tex2D(shadowMap, lightSpacePos.xy + float2( 0, -w)).x;175 176 177 float depth = lightSpacePos.z;178 179 float d = 0.0f;180 181 for (int i = 0; i < 9; ++ i)182 {183 d += step(shadowDepth[i], depth);184 }185 186 d /= 9.0f;187 188 if (amb < 0.9f) // hack: prevent shadowing the sky189 {190 // base lighting191 const float x = 0.4f;192 OUT.color *= x + (1.0f - x) * (1.0f - d);193 }194 195 /*196 // hard shadows197 float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x;198 199 if ((amb < 0.9f) && // hack: prevent shadowing the sky200 (lightSpacePos.z > shadowDepth))201 {202 OUT.color *= 0.1f;203 }*/204 205 OUT.color.w = color.w;206 207 return OUT;208 }209 210 #else211 125 212 126 … … 237 151 // diffuse intensity 238 152 const float angle = saturate(dot(normal, lightDir)); 239 float diffuse = angle; 153 //float4 lightDiffuse = float4(1.0f, 1.0f, 0.9f, 1.0f); 154 float4 lightDiffuse = glstate.light[0].diffuse; 155 //float4(1.0f, 1.0f, 0.9f, 1.0f); 156 157 float4 diffuse = lightDiffuse * angle; 240 158 241 159 // calc diffuse illumination + shadow term … … 256 174 257 175 // global ambient 258 const float4 ambient = 0.25f; 176 //const float4 ambient = 0.25f; 177 const float4 ambient = glstate.light[0].ambient; 259 178 260 179 // base lighting … … 266 185 return OUT; 267 186 } 268 269 #endif
Note: See TracChangeset
for help on using the changeset viewer.