Changeset 2957


Ignore:
Timestamp:
09/19/08 11:41:18 (16 years ago)
Author:
mattausch
Message:

preetham working

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
3 added
18 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r2954 r2957  
    196196                        > 
    197197                        <File 
    198                                 RelativePath=".\src\AxisAlignedBox3.cpp" 
    199                                 > 
    200                         </File> 
    201                         <File 
    202198                                RelativePath=".\src\BvhLoader.cpp" 
    203199                                > 
     
    224220                        </File> 
    225221                        <File 
    226                                 RelativePath=".\src\FrameBufferObject.cpp" 
    227                                 > 
    228                         </File> 
    229                         <File 
    230                                 RelativePath=".\src\FrameBufferObject.h" 
    231                                 > 
    232                         </File> 
    233                         <File 
    234222                                RelativePath=".\src\glfont2.cpp" 
    235223                                > 
     
    252240                        </File> 
    253241                        <File 
    254                                 RelativePath=".\src\Halton.cpp" 
    255                                 > 
    256                         </File> 
    257                         <File 
    258                                 RelativePath=".\src\Halton.h" 
    259                                 > 
    260                         </File> 
    261                         <File 
    262                                 RelativePath=".\src\Matrix4x4.cpp" 
    263                                 > 
    264                         </File> 
    265                         <File 
    266                                 RelativePath=".\src\Matrix4x4.h" 
    267                                 > 
    268                         </File> 
    269                         <File 
    270242                                RelativePath=".\src\MotionPath.cpp" 
    271243                                > 
     
    276248                        </File> 
    277249                        <File 
     250                                RelativePath=".\src\ObjConverter.cpp" 
     251                                > 
     252                        </File> 
     253                        <File 
     254                                RelativePath=".\src\ObjConverter.h" 
     255                                > 
     256                        </File> 
     257                        <File 
    278258                                RelativePath=".\src\PerformanceGraph.cpp" 
    279259                                > 
     
    284264                        </File> 
    285265                        <File 
    286                                 RelativePath=".\src\Plane3.cpp" 
    287                                 > 
    288                         </File> 
    289                         <File 
    290                                 RelativePath=".\src\Plane3.h" 
    291                                 > 
    292                         </File> 
    293                         <File 
    294                                 RelativePath=".\src\Polygon3.cpp" 
    295                                 > 
    296                         </File> 
    297                         <File 
    298                                 RelativePath=".\src\Polygon3.h" 
    299                                 > 
    300                         </File> 
    301                         <File 
    302                                 RelativePath=".\src\Polyhedron.cpp" 
    303                                 > 
    304                         </File> 
    305                         <File 
    306                                 RelativePath=".\src\Polyhedron.h" 
    307                                 > 
    308                         </File> 
    309                         <File 
    310266                                RelativePath=".\src\SampleGenerator.cpp" 
    311267                                > 
     
    324280                        </File> 
    325281                        <File 
    326                                 RelativePath=".\src\SceneQuery.cpp" 
    327                                 > 
    328                         </File> 
    329                         <File 
    330                                 RelativePath=".\src\SceneQuery.h" 
    331                                 > 
    332                         </File> 
    333                         <File 
    334282                                RelativePath=".\src\shaderenv.h" 
    335283                                > 
    336284                        </File> 
    337285                        <File 
    338                                 RelativePath=".\src\ShadowMapping.cpp" 
    339                                 > 
    340                         </File> 
    341                         <File 
    342                                 RelativePath=".\src\ShadowMapping.h" 
    343                                 > 
    344                         </File> 
    345                         <File 
    346286                                RelativePath=".\src\SkyPreetham.cpp" 
    347287                                > 
     
    357297                        <File 
    358298                                RelativePath=".\src\SunColor.h" 
    359                                 > 
    360                         </File> 
    361                         <File 
    362                                 RelativePath=".\src\Triangle3.cpp" 
    363                                 > 
    364                         </File> 
    365                         <File 
    366                                 RelativePath=".\src\Triangle3.h" 
    367                                 > 
    368                         </File> 
    369                         <File 
    370                                 RelativePath=".\src\Vector3.cpp" 
    371                                 > 
    372                         </File> 
    373                         <File 
    374                                 RelativePath=".\src\Vector3.h" 
    375299                                > 
    376300                        </File> 
     
    579503                                </File> 
    580504                                <File 
     505                                        RelativePath=".\src\FrameBufferObject.h" 
     506                                        > 
     507                                </File> 
     508                                <File 
    581509                                        RelativePath=".\src\Geometry.h" 
    582510                                        > 
     
    612540                                <File 
    613541                                        RelativePath=".\src\SceneEntity.h" 
     542                                        > 
     543                                </File> 
     544                                <File 
     545                                        RelativePath=".\src\SceneQuery.h" 
     546                                        > 
     547                                </File> 
     548                                <File 
     549                                        RelativePath=".\src\ShadowMapping.h" 
    614550                                        > 
    615551                                </File> 
     
    689625                                </File> 
    690626                                <File 
     627                                        RelativePath=".\src\FrameBufferObject.cpp" 
     628                                        > 
     629                                </File> 
     630                                <File 
    691631                                        RelativePath=".\src\Geometry.cpp" 
    692632                                        > 
     
    772712                                <File 
    773713                                        RelativePath=".\src\SceneEntity.cpp" 
     714                                        > 
     715                                </File> 
     716                                <File 
     717                                        RelativePath=".\src\SceneQuery.cpp" 
     718                                        > 
     719                                </File> 
     720                                <File 
     721                                        RelativePath=".\src\ShadowMapping.cpp" 
    774722                                        > 
    775723                                </File> 
     
    848796                        </File> 
    849797                        <File 
     798                                RelativePath=".\src\shaders\sky_preetham.cg" 
     799                                > 
     800                        </File> 
     801                        <File 
    850802                                RelativePath=".\src\shaders\ssao.cg" 
    851803                                > 
     
    853805                        <File 
    854806                                RelativePath=".\src\shaders\ssao3d.cg" 
     807                                > 
     808                        </File> 
     809                </Filter> 
     810                <Filter 
     811                        Name="math" 
     812                        > 
     813                        <File 
     814                                RelativePath=".\src\AxisAlignedBox3.cpp" 
     815                                > 
     816                        </File> 
     817                        <File 
     818                                RelativePath=".\src\Halton.cpp" 
     819                                > 
     820                        </File> 
     821                        <File 
     822                                RelativePath=".\src\Halton.h" 
     823                                > 
     824                        </File> 
     825                        <File 
     826                                RelativePath=".\src\Matrix4x4.cpp" 
     827                                > 
     828                        </File> 
     829                        <File 
     830                                RelativePath=".\src\Matrix4x4.h" 
     831                                > 
     832                        </File> 
     833                        <File 
     834                                RelativePath=".\src\Plane3.cpp" 
     835                                > 
     836                        </File> 
     837                        <File 
     838                                RelativePath=".\src\Plane3.h" 
     839                                > 
     840                        </File> 
     841                        <File 
     842                                RelativePath=".\src\Polygon3.cpp" 
     843                                > 
     844                        </File> 
     845                        <File 
     846                                RelativePath=".\src\Polygon3.h" 
     847                                > 
     848                        </File> 
     849                        <File 
     850                                RelativePath=".\src\Polyhedron.cpp" 
     851                                > 
     852                        </File> 
     853                        <File 
     854                                RelativePath=".\src\Polyhedron.h" 
     855                                > 
     856                        </File> 
     857                        <File 
     858                                RelativePath=".\src\Triangle3.cpp" 
     859                                > 
     860                        </File> 
     861                        <File 
     862                                RelativePath=".\src\Triangle3.h" 
     863                                > 
     864                        </File> 
     865                        <File 
     866                                RelativePath=".\src\Vector3.cpp" 
     867                                > 
     868                        </File> 
     869                        <File 
     870                                RelativePath=".\src\Vector3.h" 
    855871                                > 
    856872                        </File> 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r2954 r2957  
    1111camPosition=483.398f 242.364f 186.078f 
    1212camDirection=1 0 0 
    13 lightDirection=-0.8f 1.0f -0.7f 
     13#lightDirection=-0.8f 1.0f -0.7f 
    1414#lightDirection=0.2f -1.0f -.5f 
     15lightDirection=0.0f 0.0f -1.0f 
    1516useFullScreen=0 
    1617useLODs=1 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r2952 r2957  
    9090        int mHeight; 
    9191 
    92         /// this is just a scale factor for the scene depth in order to get better float precision in the shader 
     92        /// a scale factor of scene positions in order to get better float precision in the shader 
    9393        float mScaleFactor; 
    9494 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h

    r2899 r2957  
    88namespace CHCDemoEngine  
    99{  
    10  
    11  
    1210 
    1311/** This class implements a wrapper for a color buffer object 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h

    r2844 r2957  
    4343public: 
    4444 
     45        /** Sets default material (ambient intensity 0.2f, diffuse intensity 1.0f) 
     46        */ 
    4547        Material(); 
    4648 
     49        /** Sets ambient and diffuse color to color 
     50        */ 
    4751        Material(const RgbaColor &color); 
    4852 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r2953 r2957  
    3636        bool hasTrafo; 
    3737        str.read(reinterpret_cast<char *>(&hasTrafo), sizeof(bool)); 
    38  
    39         Matrix4x4 *m; 
    4038         
    4139        SceneEntity *sceneGeom; 
     40        Transform3 *trafo; 
    4241 
    4342        if (!hasTrafo) 
    4443        { 
    45                 m = NULL; 
     44                trafo = new Transform3(); 
    4645        } 
    4746        else 
    4847        { 
    49                 m = new Matrix4x4(); 
    50                 str.read(reinterpret_cast<char *>(m->x), sizeof(Matrix4x4)); 
    51         } 
    52  
    53         Transform3 *trafo = new Transform3(m); 
     48                Matrix4x4 m; 
     49                str.read(reinterpret_cast<char *>(m.x), sizeof(Matrix4x4)); 
     50                 
     51                trafo = new Transform3(m); 
     52        } 
     53 
    5454        mTrafos.push_back(trafo); 
    5555 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r2865 r2957  
    152152AxisAlignedBox3 SceneEntity::GetTransformedBoundingBox() const 
    153153{ 
    154         Matrix4x4 *mat = mTransform->GetMatrix(); 
    155  
    156         if (!mat) 
     154        if (mTransform->IsIdentity()) 
    157155                return mBox; 
    158156 
    159         return Transform(mBox, *mat); 
     157        Matrix4x4 mat = mTransform->GetMatrix(); 
     158 
     159        return Transform(mBox, mat); 
    160160} 
    161161 
     
    169169Vector3 SceneEntity::GetCenter() const 
    170170{ 
    171         Matrix4x4 *mat = mTransform->GetMatrix(); 
     171        if (mTransform->IsIdentity()) 
     172                return mCenter; 
    172173 
    173         if (!mat) return mCenter; 
     174        Matrix4x4 mat = mTransform->GetMatrix(); 
    174175 
    175         return (*mat) * mCenter; 
     176        return mat * mCenter; 
    176177} 
    177178 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2953 r2957  
    156156 
    157157        glDisable(GL_CULL_FACE); 
    158  
    159         glShadeModel(GL_FLAT); 
    160158        glEnable(GL_DEPTH_TEST); 
    161159 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp

    r2867 r2957  
    5656AxisAlignedBox3 Shape::GetTransformedBoundingBox() const 
    5757{ 
    58         Matrix4x4 *mat = mParent->GetTransform()->GetMatrix(); 
    59  
    60         if (!mat) 
     58        if (mParent->GetTransform()->IsIdentity()) 
    6159                return mGeometry->GetBoundingBox(); 
    6260 
    63         return Transform(mGeometry->GetBoundingBox(), *mat); 
     61        Matrix4x4 mat = mParent->GetTransform()->GetMatrix(); 
     62 
     63        return Transform(mGeometry->GetBoundingBox(), mat); 
    6464} 
    6565 
     
    6767Vector3 Shape::GetCenter() const 
    6868{ 
    69         Matrix4x4 *mat = mParent->GetTransform()->GetMatrix(); 
     69        if (mParent->GetTransform()->IsIdentity()) 
     70                return mCenter; 
    7071 
    71         if (!mat) return mCenter; 
     72        Matrix4x4 mat = mParent->GetTransform()->GetMatrix(); 
    7273 
    73         return (*mat) * mCenter; 
     74        return mat * mCenter; 
    7475} 
    7576 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r2956 r2957  
    22#include "common.h" 
    33#include "Vector3.h" 
    4  
    5  
    6 //#include <rendering/effect/FEffect.h> 
    7 //#include <rendering/FVertexbuffer.h> 
     4#include "SceneEntity.h" 
     5#include "Transform3.h" 
     6#include "Camera.h" 
     7#include "RenderState.h" 
     8 
     9using namespace CHCDemoEngine; 
     10using namespace std; 
     11 
     12 
     13 
     14static CGprogram sCgSkyProgram = NULL; 
     15static CGparameter sLightDirParam; 
     16static CGparameter sThetaSunParam; 
     17static CGparameter sZenithColorParam; 
     18static CGparameter sAColorParam; 
     19static CGparameter sBColorParam; 
     20static CGparameter sCColorParam; 
     21static CGparameter sDColorParam; 
     22static CGparameter sEColorParam; 
    823 
    924 
     
    2035 
    2136 
    22 using namespace CHCDemoEngine; 
    23  
    24  
    25 SkyPreetham::SkyPreetham(float turbitity): 
    26 //      mEffect(NULL), 
    27         mTurbidity(turbitity) 
    28 //      mSunEffect(NULL), 
    29 //      mSunTexture(NULL), 
     37void SkyPreetham::Init(CGcontext context) 
     38{        
     39        sCgSkyProgram =  
     40                cgCreateProgramFromFile(context,  
     41                                                                CG_SOURCE, 
     42                                                                "src/shaders/sky_preetham.cg",  
     43                                                                RenderState::sCgVertexProfile, 
     44                                                                "default_vs", 
     45                                                                NULL); 
     46 
     47        if (sCgSkyProgram != NULL) 
     48        { 
     49                cgGLLoadProgram(sCgSkyProgram); 
     50 
     51                sLightDirParam = cgGetNamedParameter(sCgSkyProgram, "lightDir"); 
     52                sThetaSunParam = cgGetNamedParameter(sCgSkyProgram, "thetaSun"); 
     53                sZenithColorParam = cgGetNamedParameter(sCgSkyProgram, "zenithColor"); 
     54                sAColorParam = cgGetNamedParameter(sCgSkyProgram, "aColor"); 
     55                sBColorParam = cgGetNamedParameter(sCgSkyProgram, "bColor"); 
     56                sCColorParam = cgGetNamedParameter(sCgSkyProgram, "cColor"); 
     57                sDColorParam = cgGetNamedParameter(sCgSkyProgram, "dColor"); 
     58                sEColorParam = cgGetNamedParameter(sCgSkyProgram, "eColor"); 
     59        } 
     60        else 
     61                cerr << "sky program failed to load" << endl; 
     62} 
     63 
     64 
     65SkyPreetham::SkyPreetham(float turbitity, SceneEntity *skyDome): 
     66mSkyDome(skyDome), 
     67mTurbidity(turbitity) 
    3068//      mSunQuad(NULL) 
    3169{ 
    32 /*      mEffect = D().getScene().getEffect("../effects/sky_preetham.fx"); 
    33  
    34         mVertexBuffer = D().getScene().getVertexBuffer("../models/sky.vbo"); 
    35  
    36         mSunEffect = D().getScene().getEffect("../effects/sky_sun.fx"); 
    37         mSunTexture = D().getScene().getTexture2D("../textures/sky_sun.png"); 
    38 */ 
    3970        CreateSunQuad(); 
    4071} 
     
    4778 
    4879 
    49  
    50 void SkyPreetham::Compute(const Vector3 &sunDir) 
     80void SkyPreetham::Compute(const Vector3 &sunDir, Camera *camera, RenderState *state) 
    5181{ 
    5282        float sun_theta[2]; 
    5383 
    54         sun_theta[0] = acos(sunDir.y); 
    55  
    56         const float cos_theta =  cos(sun_theta[0]); 
     84        //sun_theta[0] = acos(sunDir.y); 
     85        sun_theta[0] = acos(sunDir.z); 
     86 
     87        const float cos_theta = cos(sun_theta[0]); 
    5788        sun_theta[1] = cos_theta * cos_theta; 
    5889 
     
    93124        ABCDE_Y[4] = -0.06696 * mTurbidity + 0.37027; 
    94125 
    95 /* 
    96         F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_NO_OVERWRITE); 
     126        //F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_NO_OVERWRITE); 
    97127 
    98128        // Move skybox with camera. 
    99         mPosition = D().getScene().getCamera().getPosition(); 
    100  
    101         mPosition.y -= 2.0; 
    102  
    103         setTransform(); 
    104  
    105         mEffect->setVariableVector3("LightDirection", D().getScene().getLight().getDirection()); 
     129        Vector3 position = camera->GetPosition(); 
     130 
     131 
     132        const float scaleFactor = 100.0f; 
     133 
     134        position.z -= 10 * scaleFactor; 
     135        Matrix4x4 m = TranslationMatrix(position); 
     136 
     137        Matrix4x4 s = ScaleMatrix(scaleFactor, scaleFactor, scaleFactor); 
     138        mSkyDome->GetTransform()->SetMatrix(s * m); 
     139 
     140         
     141        cgGLSetParameter3f(sLightDirParam, sunDir.x, sunDir.y, sunDir.z); 
     142        cgGLSetParameter2f(sThetaSunParam, sun_theta[0], sun_theta[1]); 
     143        cgGLSetParameter3f(sZenithColorParam, zenithColor.x, zenithColor.y, zenithColor.z); 
     144 
     145        cgGLSetParameter3f(sAColorParam, ABCDE_x[0], ABCDE_y[0], ABCDE_Y[0]); 
     146        cgGLSetParameter3f(sBColorParam, ABCDE_x[1], ABCDE_y[1], ABCDE_Y[1]); 
     147        cgGLSetParameter3f(sCColorParam, ABCDE_x[2], ABCDE_y[2], ABCDE_Y[2]); 
     148        cgGLSetParameter3f(sDColorParam, ABCDE_x[3], ABCDE_y[3], ABCDE_Y[3]); 
     149        cgGLSetParameter3f(sEColorParam, ABCDE_x[4], ABCDE_y[4], ABCDE_Y[4]); 
     150 
     151        /*mEffect->setVariableVector3("LightDirection", D().getScene().getLight().getDirection()); 
    106152        mEffect->setVariableVector2("ThetaSun", sun_theta); 
    107153        mEffect->setVariableVector3("ZenithColor", zenithColor); 
     
    111157        mEffect->setVariableVector3("DColor",FVector3((FFloat)ABCDE_x[3], (FFloat)ABCDE_y[3], (FFloat)ABCDE_Y[3])); 
    112158        mEffect->setVariableVector3("EColor",FVector3((FFloat)ABCDE_x[4], (FFloat)ABCDE_y[4], (FFloat)ABCDE_Y[4])); 
    113  
    114  
    115         mEffect->activate(); 
    116  
    117         F().getRenderDevice().setDefaultPolygonMode(true, FRenderDevice::CULL_NONE); 
     159*/ 
     160 
     161        cgGLEnableProfile(RenderState::sCgVertexProfile); 
     162        cgGLBindProgram(sCgSkyProgram); 
    118163 
    119164        // Render sky dome. 
    120         mVertexBuffer->render(); 
     165        mSkyDome->Render(state); 
    121166 
    122167        // Render additively blended sun disc. 
    123         renderSunDisk(); 
    124  
    125         F().getRenderDevice().setDefaultPolygonMode(true, FRenderDevice::CULL_BACKFACES); 
    126  
    127  
    128         F().getRenderDevice().setDefaultDepthStencilMode(FRenderDevice::DEPTHSTENCIL_TEST_AND_OVERWRITE); 
    129         */ 
     168        RenderSunDisk(); 
    130169} 
    131170 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h

    r2955 r2957  
    11#ifndef _SKYPREETHAM_H__ 
    22#define _SKYPREETHAM_H__ 
     3 
     4#include "glInterface.h" 
     5 
     6#include <Cg/cg.h> 
     7#include <Cg/cgGL.h> 
    38 
    49 
    510namespace CHCDemoEngine{ 
    611class Vector3; 
     12class SceneEntity; 
     13class RenderState; 
     14class Camera; 
    715} 
    816 
     
    1018{ 
    1119public: 
    12         // Constructor and destructor. 
    13         SkyPreetham(float turbitity); 
     20        /// Constructor taking sky turbitity as parameter and the sky dome geometry 
     21        SkyPreetham(float turbitity, CHCDemoEngine::SceneEntity *skyDome); 
    1422        virtual ~SkyPreetham(); 
    1523 
    16         void Compute(const CHCDemoEngine::Vector3 &sunDir); 
     24        void Compute(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Camera *camera, CHCDemoEngine::RenderState *state); 
     25 
     26        static void Init(CGcontext context); 
    1727 
    1828protected: 
     
    2939        FVertexBuffer*  mSunQuad; 
    3040*/ 
     41        CHCDemoEngine::SceneEntity *mSkyDome; 
     42 
    3143        float mTurbidity; 
    3244}; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SunColor.cpp

    r2955 r2957  
    55 
    66using namespace CHCDemoEngine; 
     7using namespace std; 
    78 
    89 
     
    2425 
    2526        // sunDir is sun direction 
    26         // ambient color :shadow color 
    27         // diffuse color :sun color 
     27        // ambient color: shadow color 
     28        // diffuse color: sun color 
    2829 
    2930        float sun_theta[2]; 
    3031         
    31         sun_theta[0] = acos(sunDir.y); 
     32        sun_theta[0] = acos(sunDir.z); 
    3233 
    33         const float cos_theta =  cos(sun_theta[0]); 
     34        const float cos_theta = cos(sun_theta[0]); 
    3435        sun_theta[1] = cos_theta * cos_theta; 
    3536 
     
    6667 
    6768        // simulate the sun intensity by modulating the ambient term. 
    68         ambient *= (1.0f - 0.90f * DotProd(sunDir, Vector3(0, 1, 0))); 
     69        ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z())); 
    6970        ambient += Vector3(0.2f); 
    7071 
     
    9192        Vector3 num; 
    9293           
    93         num.x = (1.0f + ABCDE_x[0] * exp( ABCDE_x[1] / sunDir.y )) * (1.0f + ABCDE_x[2])+ ABCDE_x[4];     
    94         num.y = (1.0f + ABCDE_y[0] * exp( ABCDE_y[1] / sunDir.y )) * (1.0f + ABCDE_y[2])+ ABCDE_y[4];    
    95         num.z = (1.0f + ABCDE_Y[0] * exp( ABCDE_Y[1] / sunDir.y )) * (1.0f + ABCDE_Y[2])+ ABCDE_Y[4];    
     94        num.x = (1.0f + ABCDE_x[0] * exp( ABCDE_x[1] / sunDir.z )) * (1.0f + ABCDE_x[2])+ ABCDE_x[4];     
     95        num.y = (1.0f + ABCDE_y[0] * exp( ABCDE_y[1] / sunDir.z )) * (1.0f + ABCDE_y[2])+ ABCDE_y[4];    
     96        num.z = (1.0f + ABCDE_Y[0] * exp( ABCDE_Y[1] / sunDir.z )) * (1.0f + ABCDE_Y[2])+ ABCDE_Y[4];    
    9697 
    9798 
     
    103104 
    104105 
    105         Vector3 xyY = num / den * zenithColor;     
     106        Vector3 xyY = (num / den) * zenithColor;     
    106107 
    107108        Vector3 XYZ;                                                                                              
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r2955 r2957  
    11#include "Transform3.h" 
    2 #include "Matrix4x4.h" 
    32#include "RenderState.h" 
    43 
     
    109 
    1110 
    12 Transform3::Transform3(Matrix4x4 *trafo): mMatrix(trafo) 
     11Transform3::Transform3(const Matrix4x4 &trafo): mMatrix(trafo) 
    1312{ 
     13        mIsIdentity = false; 
    1414} 
    1515 
    1616 
    17 Transform3::~Transform3() 
     17Transform3::Transform3() 
    1818{ 
    19         DEL_PTR(mMatrix); 
     19        Reset(); 
    2020} 
    2121 
     
    2323void Transform3::Load(RenderState *state) 
    2424{ 
    25         if (!mMatrix) return; 
     25        if (mIsIdentity) return; 
    2626         
    2727        if (state->GetRenderPassType() == RenderState::DEFERRED) 
    2828        { 
    29                 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix->x); 
     29                cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix.x); 
    3030        } 
    3131 
    3232        glPushMatrix(); 
    33         glMultMatrixf((float *)mMatrix->x); 
     33        glMultMatrixf((float *)mMatrix.x); 
    3434} 
    3535 
     
    3737void Transform3::Unload(RenderState *state) 
    3838{ 
    39         if (!mMatrix) return; 
     39        if (mIsIdentity) return; 
    4040 
    4141        if (state->GetRenderPassType() == RenderState::DEFERRED) 
     
    4848} 
    4949 
     50 
     51void Transform3::MultMatrix(const Matrix4x4 &trafo) 
     52{ 
     53        mIsIdentity = false; 
     54        mMatrix = mMatrix * trafo; 
    5055} 
     56 
     57 
     58void Transform3::Reset() 
     59{ 
     60        mIsIdentity = true; 
     61        mMatrix = IdentityMatrix(); 
     62} 
     63 
     64 
     65} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h

    r2952 r2957  
    22#define __TRANSFORM3_H 
    33 
     4#include "Matrix4x4.h" 
    45#include "glInterface.h" 
    56#include "common.h" 
     
    1213 
    1314class RenderState; 
    14 class Matrix4x4; 
    1515 
    1616 
    17 /** Class representing a transformation 
     17/** Class representing a wrapper class for a 3D transformation 
    1818*/ 
    1919class Transform3 
     
    2121public: 
    2222         
    23         /** Creates a scene entity. 
     23        /** Creates a transformation. 
    2424        */ 
    25         Transform3(Matrix4x4 *trafo); 
    26  
    27         ~Transform3(); 
     25        Transform3(const Matrix4x4 &trafo); 
     26        /** The identity transformation. 
     27        */ 
     28        Transform3(); 
    2829        /** Loads this transformation. 
    2930        */ 
     
    3233        */ 
    3334        void Unload(RenderState *state); 
    34         /** Returns the trafo of this scene entity. 
     35        /** Returns the trafo matrix. 
    3536        */ 
    36         inline Matrix4x4 *GetMatrix() const  { return mMatrix; } 
     37        inline Matrix4x4 GetMatrix() const  { return mMatrix; } 
     38        /** See Get 
     39        */ 
     40        inline void SetMatrix(const Matrix4x4 &trafo) { mMatrix = trafo; } 
     41        /** Right multiplies with the given matrix. 
     42        */ 
     43        inline void MultMatrix(const Matrix4x4 &trafo); 
     44        /** Resets trafo to identiy. 
     45        */ 
     46        void Reset(); 
     47        /** Returns true if this transformation is the identity. 
     48        */ 
     49        inline bool IsIdentity() const { return mIsIdentity; } 
    3750 
    3851        static CGparameter sModelMatrixParam; 
     
    4154 
    4255        /// transform matrix  
    43         Matrix4x4 *mMatrix; 
     56        Matrix4x4 mMatrix; 
     57        /// if this matrix is still the identity matrix 
     58        bool mIsIdentity; 
    4459}; 
    4560 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Triangle3.cpp

    r2782 r2957  
    5959        Vector3 v1 = mVertices[0] - mVertices[1], v2=mVertices[2] - mVertices[1]; 
    6060        return 0.5f * Magnitude(CrossProd(v2, v1)); 
    61 } 
    62  
    63  
    64 bool Triangle3::CheckValidity() const 
    65 { 
    66         return !( 
    67                 EpsilonEqualV3(mVertices[0], mVertices[1]) || 
    68                 EpsilonEqualV3(mVertices[0], mVertices[2]) || 
    69                 EpsilonEqualV3(mVertices[1], mVertices[2]) 
    70                 ); 
    7161} 
    7262 
     
    135125 
    136126 
     127bool Triangle3::Valid() const 
     128{ 
     129        const Vector3 a = mVertices[0] - mVertices[1]; 
     130        const Vector3 b = mVertices[0] - mVertices[2]; 
     131        const Vector3 cross_a_b = CrossProd(a, b); 
     132 
     133        const float eps = 1e-6f; 
     134         
     135        if (SqrMagnitude(cross_a_b) <= eps * eps)  
     136        { 
     137                // v0, v1 & v2 lies on a line (area == 0) 
     138                return false; 
     139        } 
     140 
     141        return true; 
    137142} 
     143 
     144 
     145} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Triangle3.h

    r2782 r2957  
    2929        */ 
    3030        AxisAlignedBox3 GetBoundingBox() const; 
    31         /** Checks if this triangle is ill-defined. 
    32         */ 
    33         bool CheckValidity() const; 
    3431        /** Intersects triangle with plane, returns intersection points 
    3532                if intersection is happening. 
     
    4138                                                          Vector3 &intersectB) const; 
    4239 
     40        /** Returns false if this triangle is ill-defined, true otherwise 
     41        */ 
     42        bool Valid() const; 
    4343           
    4444        friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2955 r2957  
    3838#include "SceneEntityConverter.h" 
    3939#include "SunColor.h" 
     40#include "ObjConverter.h" 
     41#include "SkyPreetham.h" 
    4042 
    4143 
     
    9193RenderTraverser *shadowTraverser = NULL; 
    9294 
     95SkyPreetham *preetham = NULL; 
     96 
    9397 
    9498/// these values get scaled with the frame rate 
     
    166170PerfTimer frameTimer, algTimer; 
    167171 
     172 
     173 
    168174/// the used render type for this render pass 
    169175enum RenderMethod 
     
    204210 
    205211SceneEntity *cube = NULL; 
     212SceneEntity *aeroplane = NULL; 
     213SceneEntity *skyDome = NULL; 
    206214 
    207215bool altKeyPressed = false; 
     
    463471 
    464472        DeferredRenderer::Init(sCgContext); 
     473        SkyPreetham::Init(sCgContext); 
    465474 
    466475 
     
    649658 
    650659        Vector3 cubeCenter(470.398f, 240.364f, 182.5f); 
    651  
    652660        AxisAlignedBox3 box(cubeCenter - Vector3(2.0f), cubeCenter + Vector3(2.0f)); 
    653661 
    654662        Material *mat = new Material(RgbaColor(1, 0.4, 0.4, 0)); 
    655         Transform3 *tf = new Transform3(NULL); 
     663        Transform3 *tf = new Transform3(); 
    656664        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        preetham = new SkyPreetham(3.0f, skyDome); 
     673 
    657674 
    658675        ////////////////////////////// 
     
    799816 
    800817 
    801         SunColor().Compute(h, sunAmbient, sunDiffuse); 
     818        SunColor().Compute(lightDir, sunAmbient, sunDiffuse); 
    802819 
    803820        const float maxComponent = sunDiffuse.MaxComponent(); 
     
    896913        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    897914        cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 
    898  
    899915} 
    900916 
     
    10571073        else 
    10581074        { 
    1059                 //glEnable(GL_CULL_FACE); 
    1060                 //cube->Render(&state); 
    1061  
    10621075                // actually render the scene geometry using the specified algorithm 
    10631076                traverser->RenderScene(); 
     
    19471960        SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end(); 
    19481961 
    1949         for (sit = skyGeometry.begin(); sit != sit_end; ++ sit) 
    1950                 (*sit)->Render(&state); 
     1962        //      for (sit = skyGeometry.begin(); sit != sit_end; ++ sit) 
     1963        //              (*sit)->Render(&state); 
     1964 
     1965        //cube->Render(&state); 
     1966        //aeroplane->Render(&state); 
     1967        glDisable(GL_CULL_FACE); 
     1968        preetham->Compute(-light->GetDirection(), camera, &state); 
     1969        glEnable(GL_CULL_FACE); 
     1970        cgGLDisableProfile(RenderState::sCgVertexProfile); 
    19511971} 
    19521972 
     
    19741994        else 
    19751995        { 
    1976                 glShadeModel(GL_SMOOTH); 
    19771996                glEnable(GL_LIGHTING); 
    1978  
    19791997                state.SetRenderPassType(RenderState::FIXED); 
    19801998        } 
    19811999 
    1982  
     2000        glShadeModel(GL_SMOOTH); 
    19832001        glEnableClientState(GL_NORMAL_ARRAY); 
    19842002 
     
    20112029{ 
    20122030        Vector3 playerPos = camera->GetPosition(); 
    2013  
    20142031        bool validIntersect = sceneQuery->CalcIntersection(playerPos); 
    20152032 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2952 r2957  
    5252        vtxout OUT; 
    5353 
    54         // transform the vertex position into eye space 
    5554        OUT.color = IN.color; 
    56  
    5755        OUT.texCoord = IN.texCoord; 
    5856 
Note: See TracChangeset for help on using the changeset viewer.