- Timestamp:
- 09/20/08 23:35:20 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2957 r2960 291 291 > 292 292 </File> 293 <File294 RelativePath=".\src\SunColor.cpp"295 >296 </File>297 <File298 RelativePath=".\src\SunColor.h"299 >300 </File>301 293 <Filter 302 294 Name="timer" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r2959 r2960 8 8 namespace CHCDemoEngine 9 9 { 10 11 CGparameter Material::sDiffuseParam;12 CGparameter Material::sDiffuseTexParam;13 CGparameter Material::sAmbientParam;14 CGparameter Material::sAmbientTexParam;15 16 10 17 11 RgbaColor RandomColor(float a, float b) … … 67 61 68 62 if (mTexture) 69 {70 63 mTexture->Bind(); 71 }72 64 else 73 {74 65 glBindTexture(GL_TEXTURE_2D, 0); 75 }76 66 77 if (state->GetRenderPassType() == RenderState::DEFERRED) 78 { 79 if (mTexture) 80 { 81 cgGLSetParameter4f(sAmbientTexParam, mEmmisiveColor.r, mEmmisiveColor.g, mEmmisiveColor.b, mEmmisiveColor.a); 82 cgGLSetParameter4f(sDiffuseTexParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a); 83 } 84 else 85 { 86 cgGLSetParameter4f(sAmbientParam, mEmmisiveColor.r, mEmmisiveColor.g, mEmmisiveColor.b, mEmmisiveColor.a); 87 cgGLSetParameter4f(sDiffuseParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a); 88 } 89 } 90 else if (state->GetRenderPassType() == RenderState::FIXED) 91 { 92 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 93 glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); 94 glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r); 95 glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r); 96 } 67 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 68 glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); 69 glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r); 70 glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r); 97 71 } 98 72 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
r2957 r2960 3 3 4 4 #include "glInterface.h" 5 #include <Cg/cg.h>6 #include <Cg/cgGL.h>7 5 #include "common.h" 8 6 … … 80 78 void InitMaterial(); 81 79 82 static CGparameter sDiffuseParam;83 static CGparameter sDiffuseTexParam;84 85 static CGparameter sAmbientParam;86 static CGparameter sAmbientTexParam;87 88 80 protected: 89 81 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r2959 r2960 103 103 104 104 105 void SkyPreetham::Compute(const Vector3 &sunDir, Camera *camera, RenderState *state) 106 { 107 float sun_theta[2]; 108 109 sun_theta[0] = acos(sunDir.z); 110 111 const float cos_theta = cos(sun_theta[0]); 112 sun_theta[1] = cos_theta * cos_theta; 113 105 void SkyPreetham::RenderSkyDome(const Vector3 &sunDir, Camera *camera, RenderState *state) 106 { 107 pair<float, float> sun_theta; 114 108 Vector3 zenithColor; 115 116 zenithColor.x = ( 0.00165f * CBQ(sun_theta[0]) - 0.00374f * SQR(sun_theta[0]) + 0.00208f * sun_theta[0] + 0.0f) * SQR(mTurbidity) + 117 (-0.02902f * CBQ(sun_theta[0]) + 0.06377f * SQR(sun_theta[0]) - 0.03202f * sun_theta[0] + 0.00394f) * mTurbidity + 118 ( 0.11693f * CBQ(sun_theta[0]) - 0.21196f * SQR(sun_theta[0]) + 0.06052f * sun_theta[0] + 0.25885f); 119 120 zenithColor.y = (0.00275f * CBQ(sun_theta[0]) - 0.00610f * SQR(sun_theta[0]) + 0.00316f * sun_theta[0] + 0.0f) * SQR(mTurbidity) + 121 (-0.04214f * CBQ(sun_theta[0]) + 0.08970f * SQR(sun_theta[0]) - 0.04153f * sun_theta[0] + 0.00515f) * mTurbidity + 122 ( 0.15346f * CBQ(sun_theta[0]) - 0.26756f * SQR(sun_theta[0]) + 0.06669f * sun_theta[0] + 0.26688f); 123 124 zenithColor.z = (float)((4.0453f * mTurbidity - 4.9710f) * tan((4.0f / 9.0f - mTurbidity / 120.0f) * 125 (M_PI - 2.0f * sun_theta[0])) - 0.2155f * mTurbidity + 2.4192f); 126 127 // convert kcd/m² to cd/m² 128 zenithColor.z *= 1000.0f; 129 130 double ABCDE_x[5], ABCDE_y[5], ABCDE_Y[5]; 131 132 ABCDE_x[0] = -0.01925 * mTurbidity - 0.25922; 133 ABCDE_x[1] = -0.06651 * mTurbidity + 0.00081; 134 ABCDE_x[2] = -0.00041 * mTurbidity + 0.21247; 135 ABCDE_x[3] = -0.06409 * mTurbidity - 0.89887; 136 ABCDE_x[4] = -0.00325 * mTurbidity + 0.04517; 137 138 ABCDE_y[0] = -0.01669 * mTurbidity - 0.26078; 139 ABCDE_y[1] = -0.09495 * mTurbidity + 0.00921; 140 ABCDE_y[2] = -0.00792 * mTurbidity + 0.21023; 141 ABCDE_y[3] = -0.04405 * mTurbidity - 1.65369; 142 ABCDE_y[4] = -0.01092 * mTurbidity + 0.05291; 143 144 ABCDE_Y[0] = 0.17872 * mTurbidity - 1.46303; 145 ABCDE_Y[1] = -0.35540 * mTurbidity + 0.42749; 146 ABCDE_Y[2] = -0.02266 * mTurbidity + 5.32505; 147 ABCDE_Y[3] = 0.12064 * mTurbidity - 2.57705; 148 ABCDE_Y[4] = -0.06696 * mTurbidity + 0.37027; 149 109 vector<Vector3> ABCDE; 110 ComputeFactors(sunDir, zenithColor, ABCDE, sun_theta); 150 111 151 112 // Move skybox with camera. … … 161 122 162 123 cgGLSetParameter3f(sLightDirParam, sunDir.x, sunDir.y, sunDir.z); 163 cgGLSetParameter2f(sThetaSunParam, sun_theta [0], sun_theta[1]);124 cgGLSetParameter2f(sThetaSunParam, sun_theta.first, sun_theta.second); 164 125 cgGLSetParameter3f(sZenithColorParam, zenithColor.x, zenithColor.y, zenithColor.z); 165 126 166 cgGLSetParameter3f(sAColorParam, ABCDE _x[0], ABCDE_y[0], ABCDE_Y[0]);167 cgGLSetParameter3f(sBColorParam, ABCDE _x[1], ABCDE_y[1], ABCDE_Y[1]);168 cgGLSetParameter3f(sCColorParam, ABCDE _x[2], ABCDE_y[2], ABCDE_Y[2]);169 cgGLSetParameter3f(sDColorParam, ABCDE _x[3], ABCDE_y[3], ABCDE_Y[3]);170 cgGLSetParameter3f(sEColorParam, ABCDE _x[4], ABCDE_y[4], ABCDE_Y[4]);127 cgGLSetParameter3f(sAColorParam, ABCDE[0].x, ABCDE[0].y, ABCDE[0].z); 128 cgGLSetParameter3f(sBColorParam, ABCDE[1].x, ABCDE[1].y, ABCDE[1].z); 129 cgGLSetParameter3f(sCColorParam, ABCDE[2].x, ABCDE[2].y, ABCDE[2].z); 130 cgGLSetParameter3f(sDColorParam, ABCDE[3].x, ABCDE[3].y, ABCDE[3].z); 131 cgGLSetParameter3f(sEColorParam, ABCDE[4].x, ABCDE[4].y, ABCDE[4].z); 171 132 172 133 cgGLEnableProfile(RenderState::sCgVertexProfile); … … 265 226 */ 266 227 } 228 229 230 void SkyPreetham::ComputeFactors(const Vector3 &sunDir, 231 Vector3 &zenithColor, 232 vector<Vector3> &ABCDE, 233 std::pair<float, float> &sunThetha) const 234 { 235 sunThetha.first = acos(sunDir.z); 236 237 const float cos_theta = cos(sunThetha.first); 238 sunThetha.second = cos_theta * cos_theta; 239 240 zenithColor.x = ( 0.00165f * CBQ(sunThetha.first) - 0.00374f * SQR(sunThetha.first) + 0.00208f * sunThetha.first + 0.0f) * SQR(mTurbidity) + 241 (-0.02902f * CBQ(sunThetha.first) + 0.06377f * SQR(sunThetha.first) - 0.03202f * sunThetha.first + 0.00394f) * mTurbidity + 242 ( 0.11693f * CBQ(sunThetha.first) - 0.21196f * SQR(sunThetha.first) + 0.06052f * sunThetha.first + 0.25885f); 243 244 zenithColor.y = ( 0.00275f * CBQ(sunThetha.first) - 0.00610f * SQR(sunThetha.first) + 0.00316f * sunThetha.first + 0.0f) * SQR(mTurbidity) + 245 (-0.04214f * CBQ(sunThetha.first) + 0.08970f * SQR(sunThetha.first) - 0.04153f * sunThetha.first + 0.00515f) * mTurbidity + 246 ( 0.15346f * CBQ(sunThetha.first) - 0.26756f * SQR(sunThetha.first) + 0.06669f * sunThetha.first + 0.26688f); 247 248 zenithColor.z = (float)((4.0453f * mTurbidity - 4.9710f) * tan((4.0f / 9.0f - mTurbidity / 120.0f) * 249 (M_PI - 2.0f * sunThetha.first)) - 0.2155f * mTurbidity + 2.4192f); 250 251 // convert kcd/m² to cd/m² 252 zenithColor.z *= 1000.0f; 253 254 ABCDE.push_back(Vector3(-0.01925 * mTurbidity - 0.25922, -0.01669 * mTurbidity - 0.26078, 0.17872 * mTurbidity - 1.46303)); 255 ABCDE.push_back(Vector3(-0.06651 * mTurbidity + 0.00081, -0.09495 * mTurbidity + 0.00921, -0.35540 * mTurbidity + 0.42749)); 256 ABCDE.push_back(Vector3(-0.00041 * mTurbidity + 0.21247, -0.00792 * mTurbidity + 0.21023, -0.02266 * mTurbidity + 5.32505)); 257 ABCDE.push_back(Vector3(-0.06409 * mTurbidity - 0.89887, -0.04405 * mTurbidity - 1.65369, 0.12064 * mTurbidity - 2.57705)); 258 ABCDE.push_back(Vector3(-0.00325 * mTurbidity + 0.04517, -0.01092 * mTurbidity + 0.05291, -0.06696 * mTurbidity + 0.37027)); 259 } 260 261 262 void SkyPreetham::ComputeSunColor(const Vector3 &sunDir, Vector3 &ambient, Vector3 &diffuse) const 263 { 264 // sunDir is sun direction 265 // ambient color: shadow color 266 // diffuse color: sun color 267 pair<float, float> sun_theta; 268 Vector3 zenithColor; 269 vector<Vector3> ABCDE; 270 271 ComputeFactors(sunDir, zenithColor, ABCDE, sun_theta); 272 273 ambient = zenithColor; 274 275 Vector3 zenith_XYZ; 276 277 zenith_XYZ.x = (ambient.x / ambient.y) * ambient.z; 278 zenith_XYZ.y = ambient.z; 279 zenith_XYZ.z = ((1.0f - ambient.x - ambient.y) / ambient.y) * ambient.z; 280 281 ambient.x = 3.240479f * zenith_XYZ.x - 1.537150f * zenith_XYZ.y - 0.498535f * zenith_XYZ.z; 282 ambient.y = -0.969256f * zenith_XYZ.x + 1.875992f * zenith_XYZ.y + 0.041556f * zenith_XYZ.z; 283 ambient.z = 0.055648f * zenith_XYZ.x - 0.204043f * zenith_XYZ.y + 1.057311f * zenith_XYZ.z; 284 285 // downscale ambient color 286 ambient *= 5e-5f; 287 288 // simulate the sun intensity by modulating the ambient term. 289 ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z())); 290 ambient += Vector3(0.2f); 291 292 Vector3 num; 293 294 num.x = (1.0f + ABCDE[0].x * exp(ABCDE[1].x / sunDir.z)) * (1.0f + ABCDE[2].x)+ ABCDE[4].x; 295 num.y = (1.0f + ABCDE[0].y * exp(ABCDE[1].y / sunDir.z)) * (1.0f + ABCDE[2].y)+ ABCDE[4].y; 296 num.z = (1.0f + ABCDE[0].z * exp(ABCDE[1].z / sunDir.z)) * (1.0f + ABCDE[2].z)+ ABCDE[4].z; 297 298 Vector3 den; 299 300 den.x = (1.0f + ABCDE[0].x * exp(ABCDE[1].x)) * (1.0f + ABCDE[2].x * exp(ABCDE[3].x * sun_theta.first) + ABCDE[4].x * sun_theta.second); 301 den.y = (1.0f + ABCDE[0].y * exp(ABCDE[1].y)) * (1.0f + ABCDE[2].y * exp(ABCDE[3].y * sun_theta.first) + ABCDE[4].y * sun_theta.second); 302 den.z = (1.0f + ABCDE[0].z * exp(ABCDE[1].z)) * (1.0f + ABCDE[2].z * exp(ABCDE[3].z * sun_theta.first) + ABCDE[4].z * sun_theta.second); 303 304 305 Vector3 xyY = (num / den) * zenithColor; 306 307 Vector3 XYZ; 308 309 XYZ.x = (xyY.x / xyY.y) * xyY.z; 310 XYZ.y = xyY.z; 311 XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z; 312 313 314 Vector3 color; 315 color.x = 3.240479f * XYZ.x - 1.537150f * XYZ.y - 0.498535f * XYZ.z; 316 color.y = -0.969256f * XYZ.x + 1.875992f * XYZ.y + 0.041556f *XYZ.z; 317 color.z = 0.055648f * XYZ.x - 0.204043f * XYZ.y + 1.057311f * XYZ.z; 318 319 // Calculate final sun diffuse color. 320 diffuse = color * 0.00017f; 321 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h
r2958 r2960 3 3 4 4 #include "glInterface.h" 5 5 #include "common.h" 6 6 #include <Cg/cg.h> 7 7 #include <Cg/cgGL.h> … … 22 22 virtual ~SkyPreetham(); 23 23 24 void Compute(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Camera *camera, CHCDemoEngine::RenderState *state);24 void RenderSkyDome(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Camera *camera, CHCDemoEngine::RenderState *state); 25 25 26 26 static void Init(CGcontext context); 27 28 void ComputeFactors(const CHCDemoEngine::Vector3 &sunDir, 29 CHCDemoEngine::Vector3 &zenithColor, 30 std::vector<CHCDemoEngine::Vector3> &ABCDE, 31 std::pair<float, float> &sunThetha) const; 32 33 void ComputeSunColor(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Vector3 &ambient, CHCDemoEngine::Vector3 &diffuse) const; 34 27 35 28 36 protected: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r2957 r2960 25 25 if (mIsIdentity) return; 26 26 27 // note: would not need to pass the model matrix, 28 // as all required information is avaiabl in the glstate 29 // however, we require it compute the word positions, 30 // as computing the world position by use the inverse of the viewprojection 31 // matrix turned out to be too inaccurate for temporal reprojection 32 27 33 if (state->GetRenderPassType() == RenderState::DEFERRED) 28 34 { … … 39 45 if (mIsIdentity) return; 40 46 47 // reset model matrix 41 48 if (state->GetRenderPassType() == RenderState::DEFERRED) 42 49 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2959 r2960 37 37 #include "Light.h" 38 38 #include "SceneEntityConverter.h" 39 #include "SunColor.h"40 39 #include "ObjConverter.h" 41 40 #include "SkyPreetham.h" … … 415 414 InitGLstate(); 416 415 416 417 Vector3 cubeCenter(470.398f, 240.364f, 182.5f); 418 AxisAlignedBox3 box(cubeCenter - Vector3(2.0f), cubeCenter + Vector3(2.0f)); 419 420 Material *mat = new Material(RgbaColor(1, 0.4, 0.4, 0)); 421 Transform3 *tf = new Transform3(); 422 cube = SceneEntityConverter().ConvertBox(box, mat, tf); 423 424 //aeroplane = ObjConverter().Load(model_path + "toyplane.obj"); 425 //if (!aeroplane) cerr << "loadig plane failed" << endl; 426 427 skyDome = ObjConverter().Load(model_path + "sky.obj"); 428 if (!skyDome) cerr << "loadig plane failed" << endl; 429 430 const float turbitiy = 3.0f; 431 preetham = new SkyPreetham(turbitiy, skyDome); 432 417 433 glEnable(GL_MULTISAMPLE_ARB); 418 434 glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); … … 538 554 539 555 sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth"); 540 Material::sDiffuseTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "diffuse");541 Material::sAmbientTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "ambient");542 556 543 557 cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist); … … 559 573 560 574 sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth"); 561 Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse");562 Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient");563 564 575 cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist); 565 576 } … … 625 636 glEnable(GL_DEPTH_TEST); 626 637 627 SetupLighting();628 629 638 glColor3f(1.0f, 1.0f, 1.0f); 630 639 glShadeModel(GL_SMOOTH); … … 656 665 else 657 666 cout << "successfully created font" << endl; 658 659 Vector3 cubeCenter(470.398f, 240.364f, 182.5f);660 AxisAlignedBox3 box(cubeCenter - Vector3(2.0f), cubeCenter + Vector3(2.0f));661 662 Material *mat = new Material(RgbaColor(1, 0.4, 0.4, 0));663 Transform3 *tf = new Transform3();664 cube = SceneEntityConverter().ConvertBox(box, mat, tf);665 666 //aeroplane = ObjConverter().Load(model_path + "toyplane.obj");667 //if (!aeroplane) cerr << "loadig plane failed" << endl;668 669 skyDome = ObjConverter().Load(model_path + "sky.obj");670 if (!skyDome) cerr << "loadig plane failed" << endl;671 672 const float turbitiy = 3.0f;673 preetham = new SkyPreetham(turbitiy, skyDome);674 667 675 668 … … 820 813 821 814 822 SunColor().Compute(lightDir, sunAmbient, sunDiffuse);815 preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse); 823 816 824 817 const float maxComponent = sunDiffuse.MaxComponent(); … … 1976 1969 //glEnable(GL_LIGHTING); 1977 1970 1978 preetham-> Compute(-light->GetDirection(), camera, &state);1971 preetham->RenderSkyDome(-light->GetDirection(), camera, &state); 1979 1972 1980 1973 cgGLDisableProfile(RenderState::sCgVertexProfile); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2958 r2960 67 67 pixel fragtex(fragin IN, 68 68 uniform sampler2D tex, 69 uniform float maxDepth, 70 uniform float4 ambient, 71 uniform float4 diffuse) 69 uniform float maxDepth) 72 70 { 73 71 pixel pix; 74 72 75 73 // save color in first render target 76 pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 74 // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 75 pix.col = (glstate.material.emission + glstate.material.diffuse) * tex2D(tex, IN.texCoord.xy); 77 76 78 77 // save world position in second render target … … 82 81 83 82 // hack: squeeze some information about ambient into the texture 84 pix.norm.w = ambient.x;83 pix.norm.w = glstate.material.emission.x; 85 84 // store projection coordinates with positions (used for ssao) 86 85 pix.pos.w = IN.projPos.w; … … 98 97 99 98 pixel frag(fragin IN, 100 uniform float maxDepth, 101 uniform float4 ambient, 102 uniform float4 diffuse 103 ) 99 uniform float maxDepth) 104 100 { 105 101 pixel pix; 106 102 107 pix.col = diffuse; 103 // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 104 pix.col = glstate.material.diffuse + glstate.material.emission; 108 105 pix.pos = IN.worldPos * maxDepth; 109 106 … … 111 108 112 109 // hack: squeeze some information about the ambient term into the target 113 pix.norm.w = ambient.x;110 pix.norm.w = glstate.material.emission.x; 114 111 pix.pos.w = IN.mypos.w; 115 112
Note: See TracChangeset
for help on using the changeset viewer.