Ignore:
Timestamp:
09/18/08 08:06:31 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r2954 r2955  
    11#include "SkyPreetham.h" 
     2#include "common.h" 
     3#include "Vector3.h" 
     4 
     5 
    26//#include <rendering/effect/FEffect.h> 
    37//#include <rendering/FVertexbuffer.h> 
    48 
    59 
     10inline float CBQ(float x) 
     11{ 
     12        return x * x * x; 
     13} 
     14 
     15 
     16inline float SQR(float x) 
     17{ 
     18        return x * x ; 
     19} 
    620 
    721 
     
    923 
    1024 
    11 SkyPreetham::SkyPreetham(): 
    12         mEffect(NULL), 
    13         mTurbidity(4.0), 
    14         mSunEffect(NULL), 
    15         mSunTexture(NULL), 
    16         mSunQuad(NULL) 
     25SkyPreetham::SkyPreetham(float turbitity): 
     26//      mEffect(NULL), 
     27        mTurbidity(turbitity) 
     28//      mSunEffect(NULL), 
     29//      mSunTexture(NULL), 
     30//      mSunQuad(NULL) 
    1731{ 
    18         mEffect = D().getScene().getEffect("../effects/sky_preetham.fx"); 
     32/*      mEffect = D().getScene().getEffect("../effects/sky_preetham.fx"); 
    1933 
    2034        mVertexBuffer = D().getScene().getVertexBuffer("../models/sky.vbo"); 
     
    2236        mSunEffect = D().getScene().getEffect("../effects/sky_sun.fx"); 
    2337        mSunTexture = D().getScene().getTexture2D("../textures/sky_sun.png"); 
    24  
    25         createSunQuad(); 
     38*/ 
     39        CreateSunQuad(); 
    2640} 
    2741 
     
    2943SkyPreetham::~SkyPreetham() 
    3044{ 
    31         FDelete(mSunQuad); 
     45        //DEL_PTR(mSunQuad); 
    3246} 
    3347 
    3448 
    3549 
    36 void SkyPreetham::Compute() 
     50void SkyPreetham::Compute(const Vector3 &sunDir) 
    3751{ 
     52        float sun_theta[2]; 
    3853 
    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); 
    4255 
    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; 
    4558 
     59        Vector3 zenithColor; 
    4660 
    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); 
    4964 
    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); 
    5171 
    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); 
    7172        // convert kcd/m² to cd/m² 
    7273        zenithColor.z *= 1000; 
     
    7475        double ABCDE_x[5], ABCDE_y[5], ABCDE_Y[5]; 
    7576 
    76         ABCDE_x[0] = -0.01925 * mTurbidity   - 0.25922; 
    77         ABCDE_x[1] = -0.06651 * mTurbidity   + 0.00081; 
    78         ABCDE_x[2] = -0.00041 * mTurbidity   + 0.21247; 
    79         ABCDE_x[3] = -0.06409 * mTurbidity   - 0.89887; 
    80         ABCDE_x[4] = -0.00325 * mTurbidity   + 0.04517; 
     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; 
    8182 
    82         ABCDE_y[0] = -0.01669 * mTurbidity  - 0.26078; 
    83         ABCDE_y[1] = -0.09495 * mTurbidity   + 0.00921; 
    84         ABCDE_y[2] = -0.00792 * mTurbidity   + 0.21023; 
    85         ABCDE_y[3] = -0.04405 * mTurbidity   - 1.65369; 
    86         ABCDE_y[4] = -0.01092 * mTurbidity   + 0.05291; 
     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; 
    8788 
    88         ABCDE_Y[0] =  0.17872 * mTurbidity   - 1.46303; 
    89         ABCDE_Y[1] = -0.35540 * mTurbidity   + 0.42749; 
    90         ABCDE_Y[2] = -0.02266 * mTurbidity   + 5.32505; 
    91         ABCDE_Y[3] =  0.12064 * mTurbidity   - 2.57705; 
    92         ABCDE_Y[4] = -0.06696 * mTurbidity   + 0.37027; 
     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; 
    9394 
    94  
     95/* 
    9596        F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_NO_OVERWRITE); 
    9697 
     
    126127 
    127128        F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_AND_OVERWRITE); 
     129        */ 
    128130} 
    129131 
    130132 
    131 void SkyPreetham::renderSunDisk() 
     133void SkyPreetham::RenderSunDisk() 
    132134{ 
     135        /* 
    133136        F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_ADDITIVE); 
    134137 
     
    154157 
    155158        F().getRenderDevice().setDefaultBlendingMode(FRenderDevice::BLENDING_NONE); 
     159        */ 
    156160} 
    157161 
    158162 
    159 void SkyPreetham::createSunQuad() 
     163void SkyPreetham::CreateSunQuad() 
    160164{ 
     165        /* 
    161166        mSunQuad = new FVertexBuffer(); 
    162167        mSunQuad->setupPrimitiveType(FVertexBuffer::PRIMITIVES_TRIANGLES); 
     
    180185        mSunQuad->setIndex(4, 1); 
    181186        mSunQuad->setIndex(5, 3); 
     187        */ 
    182188} 
Note: See TracChangeset for help on using the changeset viewer.