- Timestamp:
- 09/18/08 08:06:31 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r2954 r2955 1 1 #include "SkyPreetham.h" 2 #include "common.h" 3 #include "Vector3.h" 4 5 2 6 //#include <rendering/effect/FEffect.h> 3 7 //#include <rendering/FVertexbuffer.h> 4 8 5 9 10 inline float CBQ(float x) 11 { 12 return x * x * x; 13 } 14 15 16 inline float SQR(float x) 17 { 18 return x * x ; 19 } 6 20 7 21 … … 9 23 10 24 11 SkyPreetham::SkyPreetham( ):12 mEffect(NULL),13 mTurbidity( 4.0),14 mSunEffect(NULL),15 mSunTexture(NULL),16 mSunQuad(NULL)25 SkyPreetham::SkyPreetham(float turbitity): 26 // mEffect(NULL), 27 mTurbidity(turbitity) 28 // mSunEffect(NULL), 29 // mSunTexture(NULL), 30 // mSunQuad(NULL) 17 31 { 18 mEffect = D().getScene().getEffect("../effects/sky_preetham.fx");32 /* mEffect = D().getScene().getEffect("../effects/sky_preetham.fx"); 19 33 20 34 mVertexBuffer = D().getScene().getVertexBuffer("../models/sky.vbo"); … … 22 36 mSunEffect = D().getScene().getEffect("../effects/sky_sun.fx"); 23 37 mSunTexture = D().getScene().getTexture2D("../textures/sky_sun.png"); 24 25 createSunQuad();38 */ 39 CreateSunQuad(); 26 40 } 27 41 … … 29 43 SkyPreetham::~SkyPreetham() 30 44 { 31 FDelete(mSunQuad);45 //DEL_PTR(mSunQuad); 32 46 } 33 47 34 48 35 49 36 void SkyPreetham::Compute( )50 void SkyPreetham::Compute(const Vector3 &sunDir) 37 51 { 52 float sun_theta[2]; 38 53 39 FVector2 sun_theta; 40 FVector3 l_dir = D().getScene().getLight().getDirection(); 41 mTurbidity = D().getScene().getLight().getTurbitity(); 54 sun_theta[0] = acos(sunDir.y); 42 55 43 sun_theta.x = acos(l_dir.y);44 sun_theta .y = cos( sun_theta.x ) * cos( sun_theta.x );56 const float cos_theta = cos(sun_theta[0]); 57 sun_theta[1] = cos_theta * cos_theta; 45 58 59 Vector3 zenithColor; 46 60 47 #define CBQ(X) ((X) * (X) * (X)) 48 #define SQR(X) ((X) * (X)) 61 zenithColor.x = ( 0.00165f * CBQ(sun_theta[0]) - 0.00374f * SQR(sun_theta[0]) + 0.00208f * sun_theta[0] + 0.0f) * SQR(mTurbidity) + 62 (-0.02902f * CBQ(sun_theta[0]) + 0.06377f * SQR(sun_theta[0]) - 0.03202f * sun_theta[0] + 0.00394f) * mTurbidity + 63 ( 0.11693f * CBQ(sun_theta[0]) - 0.21196f * SQR(sun_theta[0]) + 0.06052f * sun_theta[0] + 0.25885f); 49 64 50 const double PI = (double)3.1415926535897932; 65 zenithColor.y = (0.00275f * CBQ(sun_theta[0]) - 0.00610f * SQR(sun_theta[0]) + 0.00316f * sun_theta[0] + 0.0f) * SQR(mTurbidity) + 66 (-0.04214f * CBQ(sun_theta[0]) + 0.08970f * SQR(sun_theta[0]) - 0.04153f * sun_theta[0] + 0.00515f) * mTurbidity + 67 ( 0.15346f * CBQ(sun_theta[0]) - 0.26756f * SQR(sun_theta[0]) + 0.06669f * sun_theta[0] + 0.26688f); 68 69 zenithColor.z = (float)((4.0453f * mTurbidity - 4.9710f) * tan((4.0f / 9.0f - mTurbidity / 120.0f) * 70 (M_PI - 2.0f * sun_theta[0])) - 0.2155f * mTurbidity + 2.4192f); 51 71 52 FVector3 zenithColor;53 54 zenithColor.x = ( 0.00165f * CBQ(sun_theta.x) - 0.00374f * SQR(sun_theta.x) +55 0.00208f * sun_theta.x + 0.0f) * SQR(mTurbidity) +56 (-0.02902f * CBQ(sun_theta.x) + 0.06377f * SQR(sun_theta.x) -57 0.03202f * sun_theta.x + 0.00394f) * mTurbidity +58 ( 0.11693f * CBQ(sun_theta.x) - 0.21196f * SQR(sun_theta.x) +59 0.06052f * sun_theta.x + 0.25885f);60 61 zenithColor.y = ( 0.00275f * CBQ(sun_theta.x) - 0.00610f * SQR(sun_theta.x) +62 0.00316f * sun_theta.x + 0.0f) * SQR(mTurbidity) +63 (-0.04214f * CBQ(sun_theta.x) + 0.08970f * SQR(sun_theta.x) -64 0.04153f * sun_theta.x + 0.00515f) * mTurbidity +65 ( 0.15346f * CBQ(sun_theta.x) - 0.26756f * SQR(sun_theta.x) +66 0.06669f * sun_theta.x + 0.26688f);67 68 zenithColor.z = (float)((4.0453f * mTurbidity - 4.9710f) *69 tan((4.0f / 9.0f - mTurbidity / 120.0f) * (PI - 2.0f * sun_theta.x)) -70 0.2155f * mTurbidity + 2.4192f);71 72 // convert kcd/m² to cd/m² 72 73 zenithColor.z *= 1000; … … 74 75 double ABCDE_x[5], ABCDE_y[5], ABCDE_Y[5]; 75 76 76 ABCDE_x[0] = -0.01925 * mTurbidity 77 ABCDE_x[1] = -0.06651 * mTurbidity 78 ABCDE_x[2] = -0.00041 * mTurbidity 79 ABCDE_x[3] = -0.06409 * mTurbidity 80 ABCDE_x[4] = -0.00325 * mTurbidity 77 ABCDE_x[0] = -0.01925 * mTurbidity - 0.25922; 78 ABCDE_x[1] = -0.06651 * mTurbidity + 0.00081; 79 ABCDE_x[2] = -0.00041 * mTurbidity + 0.21247; 80 ABCDE_x[3] = -0.06409 * mTurbidity - 0.89887; 81 ABCDE_x[4] = -0.00325 * mTurbidity + 0.04517; 81 82 82 ABCDE_y[0] = -0.01669 * mTurbidity 83 ABCDE_y[1] = -0.09495 * mTurbidity 84 ABCDE_y[2] = -0.00792 * mTurbidity 85 ABCDE_y[3] = -0.04405 * mTurbidity 86 ABCDE_y[4] = -0.01092 * mTurbidity 83 ABCDE_y[0] = -0.01669 * mTurbidity - 0.26078; 84 ABCDE_y[1] = -0.09495 * mTurbidity + 0.00921; 85 ABCDE_y[2] = -0.00792 * mTurbidity + 0.21023; 86 ABCDE_y[3] = -0.04405 * mTurbidity - 1.65369; 87 ABCDE_y[4] = -0.01092 * mTurbidity + 0.05291; 87 88 88 ABCDE_Y[0] = 0.17872 * mTurbidity 89 ABCDE_Y[1] = -0.35540 * mTurbidity 90 ABCDE_Y[2] = -0.02266 * mTurbidity 91 ABCDE_Y[3] = 0.12064 * mTurbidity 92 ABCDE_Y[4] = -0.06696 * mTurbidity 89 ABCDE_Y[0] = 0.17872 * mTurbidity - 1.46303; 90 ABCDE_Y[1] = -0.35540 * mTurbidity + 0.42749; 91 ABCDE_Y[2] = -0.02266 * mTurbidity + 5.32505; 92 ABCDE_Y[3] = 0.12064 * mTurbidity - 2.57705; 93 ABCDE_Y[4] = -0.06696 * mTurbidity + 0.37027; 93 94 94 95 /* 95 96 F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_NO_OVERWRITE); 96 97 … … 126 127 127 128 F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_AND_OVERWRITE); 129 */ 128 130 } 129 131 130 132 131 void SkyPreetham:: renderSunDisk()133 void SkyPreetham::RenderSunDisk() 132 134 { 135 /* 133 136 F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_ADDITIVE); 134 137 … … 154 157 155 158 F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_NONE); 159 */ 156 160 } 157 161 158 162 159 void SkyPreetham:: createSunQuad()163 void SkyPreetham::CreateSunQuad() 160 164 { 165 /* 161 166 mSunQuad = new FVertexBuffer(); 162 167 mSunQuad->setupPrimitiveType(FVertexBuffer::PRIMITIVES_TRIANGLES); … … 180 185 mSunQuad->setIndex(4, 1); 181 186 mSunQuad->setIndex(5, 3); 187 */ 182 188 }
Note: See TracChangeset
for help on using the changeset viewer.