Changeset 3114 for GTP/trunk


Ignore:
Timestamp:
11/10/08 10:10:50 (16 years ago)
Author:
mattausch
Message:

worked on dynamic objects: now ook, but have to work on render queue

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
16 edited

Legend:

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

    r3068 r3114  
    6161 
    6262 
    63 void Technique::Render(RenderState *state) 
     63void Technique::Render(RenderState *state, SceneEntity *ent) 
    6464{ 
    6565        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 
     
    6868        glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r); 
    6969 
    70         state->SetState(this); 
     70        state->SetState(this, ent); 
    7171} 
    7272 
     
    9494 
    9595 
    96 void Material::Render(RenderState *state) 
     96void Material::Render(RenderState *state, SceneEntity *parent) 
    9797{ 
    9898        // set technique if available 
    9999        int idx = min((int)mTechniques.size() - 1 , state->GetRenderTechnique()); 
    100         mTechniques[idx]->Render(state); 
     100        mTechniques[idx]->Render(state, parent); 
    101101} 
    102102 
     
    117117{ 
    118118        Technique *tech = new Technique(); 
    119  
    120119        mTechniques.push_back(tech); 
    121120} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h

    r3065 r3114  
    4848class Technique  
    4949{ 
     50 
    5051friend class ResourceManager; 
    5152friend class RenderQueue; 
     53friend class Material; 
    5254 
    5355public: 
     
    6163        /** Renders this technique. 
    6264        */ 
    63         void Render(RenderState *state); 
     65        void Render(RenderState *state, SceneEntity *parent = NULL); 
    6466        /** Initialize this technique material with default values 
    6567        */ 
     
    126128        ShaderProgram *mFragmentProgram; 
    127129        ShaderProgram *mVertexProgram; 
     130 
    128131        /// if this material can write colors 
    129132        bool mColorWriteEnabled; 
     
    149152        /** Renders this material. 
    150153        */ 
    151         void Render(RenderState *state); 
     154        void Render(RenderState *state, SceneEntity *parent); 
    152155 
    153156        void AddTechnique(Technique *t); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp

    r3110 r3114  
    196196 
    197197                        if (ent) ent->Prepare(mState); 
    198                         shape->Render(mState); 
     198                        shape->Render(mState, ent); 
    199199                        if (ent) ent->GetTransform()->Unload(mState); 
    200200                } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3074 r3114  
    136136 
    137137         
    138 void RenderState::SetState(Technique *tech) 
    139 { 
    140         if (mCurrentTechnique == tech) 
    141                 return; 
     138void RenderState::SetState(Technique *tech, SceneEntity *ent) 
     139{ 
     140        //if (mCurrentTechnique == tech) return; 
    142141 
    143142        mCurrentTechnique = tech; 
     
    152151        const bool depthWrite = tech->IsDepthWriteEnabled(); 
    153152 
     153 
    154154        if (mDepthWriteEnabled && !depthWrite)  
    155155        { 
     
    256256                } 
    257257                         
    258                 tech->GetFragmentProgramParameters()->UpdateParameters(); 
     258                tech->GetFragmentProgramParameters()->UpdateParameters(ent); 
    259259        } 
    260260        else 
     
    267267        } 
    268268 
    269         ShaderProgram *vert = tech->GetVertexProgram(); 
    270  
    271         if (vert) 
     269        ShaderProgram *vtx = tech->GetVertexProgram(); 
     270 
     271        if (vtx) 
    272272        { 
    273273                if (!mVertexProgramEnabled) 
     
    277277                } 
    278278 
    279                 if (vert != mCurrentVertexProgram) 
    280                 { 
    281                         mCurrentVertexProgram = vert; 
     279                if (vtx != mCurrentVertexProgram) 
     280                { 
     281                        mCurrentVertexProgram = vtx; 
    282282                        mCurrentVertexProgram->Bind(); 
    283283                } 
    284284                 
    285                 tech->GetVertexProgramParameters()->UpdateParameters(); 
     285                tech->GetVertexProgramParameters()->UpdateParameters(ent); 
    286286        } 
    287287        else 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h

    r3068 r3114  
    3333        */ 
    3434        bool SetMode(Mode mode); 
    35         /** Sets the current render state. 
     35        /** Sets the current render state with the current technique + scene entity 
    3636        */ 
    37         void SetState(Technique *tech); 
     37        void SetState(Technique *tech, SceneEntity *ent = NULL); 
    3838        /** Returns the current render state. 
    3939        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3113 r3114  
    304304        deferred->SetVertexProgram(sDefaultVertexProgramMrt); 
    305305 
    306         static Matrix4x4 identity = IdentityMatrix(); 
    307  
    308         // default values: these are only updated for dynamic objects 
    309         deferred->GetVertexProgramParameters()->SetMatrix(1, identity); 
    310         deferred->GetVertexProgramParameters()->SetMatrix(2, identity); 
     306        deferred->GetVertexProgramParameters()->SetModelMatrixParam(1); 
     307        deferred->GetVertexProgramParameters()->SetOldModelMatrixParam(2); 
    311308 
    312309        mat->AddTechnique(deferred); 
     
    317314 
    318315        Technique *depthPass = new Technique(*tech); 
     316 
    319317        depthPass->SetColorWriteEnabled(false); 
    320318        depthPass->SetLightingEnabled(false); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r3113 r3114  
    100100 
    101101        for (; sit != sit_end; ++ sit) 
    102                 (*sit)->Render(state); 
     102                (*sit)->Render(state, this); 
    103103 
    104104        mTransform->Unload(state); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp

    r3113 r3114  
    9191        fragmentProgMrtTex->AddParameter("viewMatrix", 0); 
    9292 
     93 
     94        // vertex program 
    9395        vertexProgMrt->AddParameter("viewMatrix", 0); 
    94          
    95         // these parameters are used for ssao 
     96        // needed for for ssao 
    9697        vertexProgMrt->AddParameter("modelMatrix", 1); 
    9798        vertexProgMrt->AddParameter("oldModelMatrix", 2); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp

    r3113 r3114  
    55#include "Camera.h" 
    66#include "Light.h" 
    7  
     7#include "SceneEntity.h" 
     8#include "Transform3.h" 
    89 
    910using namespace std; 
     
    3233mViewDirParam(-1), 
    3334mViewMatrixParam(-1), 
    34 mLightDirParam(-1) 
     35mLightDirParam(-1), 
     36mModelMatrixParam(-1), 
     37mOldModelMatrixParam(-1) 
    3538{ 
    3639} 
     
    4245mViewDirParam(-1), 
    4346mViewMatrixParam(-1), 
    44 mLightDirParam(-1) 
     47mLightDirParam(-1), 
     48mModelMatrixParam(-1), 
     49mOldModelMatrixParam(-1) 
    4550{ 
    4651} 
     
    5964        mLightDirParam = -1; 
    6065        mViewMatrixParam = -1; 
     66 
     67        mModelMatrixParam = -1; 
     68        mOldModelMatrixParam = -1; 
    6169} 
    6270 
     
    171179 
    172180 
     181void GPUProgramParameters::SetModelMatrixParam(int idx) 
     182{ 
     183        mModelMatrixParam = idx; 
     184} 
     185 
     186 
     187void GPUProgramParameters::SetOldModelMatrixParam(int idx) 
     188{ 
     189        mOldModelMatrixParam = idx; 
     190} 
     191 
     192 
    173193void GPUProgramParameters::SetValue1f(const string &name, float val) 
    174194{ 
     
    225245 
    226246 
    227 void GPUProgramParameters::UpdateParameters() 
     247void GPUProgramParameters::UpdateParameters(SceneEntity *ent) 
    228248{ 
    229249        if (!mProgram) return; 
     
    305325        if (mViewMatrixParam >= 0) 
    306326                mProgram->SetMatrix(mViewMatrixParam, sCurrentViewMatrix); 
     327 
     328        if (ent) 
     329        { 
     330                if (mModelMatrixParam >= 0) 
     331                        mProgram->SetMatrix(mModelMatrixParam, ent->GetTransform()->GetMatrix()); 
     332                if (mOldModelMatrixParam >= 0) 
     333                        mProgram->SetMatrix(mOldModelMatrixParam, ent->GetTransform()->GetOldMatrix()); 
     334        } 
    307335} 
    308336 
     
    347375 
    348376        for (int i = 0; i < maxParams; ++ i) 
    349         { 
    350377                mParameters[i] = NULL; 
    351         } 
    352378} 
    353379 
     
    391417{ 
    392418        for (int i = 0; i < numElements; ++ i) 
    393         { 
    394419                AddParameter(params[i], startIdx + i); 
    395         } 
    396420} 
    397421 
     
    403427 
    404428        if (it == mParamHash.end()) 
    405         { 
    406429                p = cgGetNamedParameter(mProgram, name.c_str()); 
    407         } 
    408430        else 
    409         { 
    410431                p = mParameters[(*it).second]; 
    411         } 
    412432 
    413433        //cout << "name: " << name << " " << p << " " << mProgram << endl; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h

    r3113 r3114  
    3434        */ 
    3535        GPUProgramParameters(); 
    36  
    37         /** Constructor which initialized this parameter set for a given program. 
     36        /** Constructor which initializes this parameter set for a given program. 
    3837        */ 
    3938        GPUProgramParameters(ShaderProgram *p); 
    40  
     39        /** Sets the assoziated program (a 1:n relationship) 
     40        */ 
    4141        void SetProgram(ShaderProgram *p) { mProgram = p; } 
    4242        /** Resets this parameter set. 
     
    8484        */ 
    8585        void SetLightDirParam(int idx); 
    86  
    87          
     86        /** This parameter is connected to the current light direction  
     87                that is updated once per frame. 
     88        */ 
     89        void SetModelMatrixParam(int idx); 
     90        /** This parameter is connected to the current light direction  
     91                that is updated once per frame. 
     92        */ 
     93        void SetOldModelMatrixParam(int idx); 
     94 
     95 
    8896 
    8997        /////////// 
     
    110118        /** Feeds the shader program with the parameter values. 
    111119        */ 
    112         void UpdateParameters(); 
     120        void UpdateParameters(SceneEntity *ent = NULL); 
    113121        /** Function should be called once per frame to update frame related parameters. 
    114122        */ 
     
    190198        int mLightDirParam; 
    191199        int mViewMatrixParam; 
     200        int mModelMatrixParam; 
     201        int mOldModelMatrixParam; 
    192202 
    193203        std::vector<FloatParam> mFloats; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp

    r3074 r3114  
    2424 
    2525 
    26 void Shape::Render(RenderState *state) 
     26void Shape::Render(RenderState *state, SceneEntity *ent) 
    2727{ 
    28         if (mMaterial) mMaterial->Render(state); 
     28        if (mMaterial) mMaterial->Render(state, ent); 
    2929         
    3030        mGeometry->Render(state); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.h

    r3072 r3114  
    3434        /** Renders this node. 
    3535        */ 
    36         void Render(RenderState *state);         
     36        void Render(RenderState *state, SceneEntity *ent = NULL);        
    3737        /** Set pointer to the geometry 
    3838        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r3089 r3114  
    1414 
    1515 
    16 Transform3::Transform3(const Matrix4x4 &trafo): mMatrix(trafo) 
     16Transform3::Transform3(const Matrix4x4 &trafo):  
     17mMatrix(trafo), mOldMatrix(trafo) 
    1718{ 
    1819        mIsIdentity = false; 
     
    3233void Transform3::Unload(RenderState *state) 
    3334{ 
    34         if (!mIsIdentity) 
    35         { 
    36                 glPopMatrix(); 
    37         } 
     35        if (!mIsIdentity) glPopMatrix(); 
    3836} 
    3937 
     
    4240{ 
    4341        mIsIdentity = false; 
     42        mOldMatrix = mMatrix; 
    4443        mMatrix = mMatrix * trafo; 
    4544} 
     
    5049        mIsIdentity = true; 
    5150        mMatrix = IdentityMatrix(); 
     51        mOldMatrix = mMatrix; 
    5252} 
    5353 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h

    r3113 r3114  
    3030        */ 
    3131        void Unload(RenderState *state); 
    32         /** Returns the trafo matrix. 
    33         */ 
    34         inline Matrix4x4 GetMatrix() const  { return mMatrix; } 
    35         /** Returns pointer to trafo matrix 
    36         */ 
    37         inline const Matrix4x4 *GetPMatrix() const { return &mMatrix; } 
    38         /** See Get 
    39         */ 
    40         inline void SetMatrix(const Matrix4x4 &trafo) { mIsIdentity = false; mMatrix = trafo; } 
    4132        /** Right multiplies with the given matrix. 
    4233        */ 
     
    4536        */ 
    4637        void Reset(); 
     38        /** Returns the trafo matrix. 
     39        */ 
     40        inline Matrix4x4 GetMatrix() const { return mMatrix; } 
     41        /** See Get 
     42        */ 
     43        inline void SetMatrix(const Matrix4x4 &trafo) ; 
     44        /** Returns the old trafo matrix. 
     45        */ 
     46        inline Matrix4x4 GetOldMatrix() const { return mOldMatrix; } 
    4747        /** Returns true if this transformation is the identity. 
    4848        */ 
     
    5454        /// transform matrix  
    5555        Matrix4x4 mMatrix; 
     56        /// the previous transformation matrix 
     57        Matrix4x4 mOldMatrix; 
    5658        /// if this matrix is still the identity matrix 
    5759        bool mIsIdentity; 
     
    5961 
    6062 
     63void Transform3::SetMatrix(const Matrix4x4 &trafo)  
     64{  
     65        mIsIdentity = false;  
     66        mOldMatrix = mMatrix;  
     67        mMatrix = trafo; 
     68} 
     69 
     70 
    6171} 
    6272 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3113 r3114  
    908908 
    909909        oldTrafo = buddha->GetTransform()->GetMatrix(); 
    910         vtxParams->SetMatrix(2, oldTrafo); 
     910        //vtxParams->SetMatrix(2, oldTrafo); 
    911911 
    912912        Vector3 buddhaPos = motionPath->GetCurrentPosition(); 
     
    915915        buddha->GetTransform()->SetMatrix(trafo); 
    916916 
    917         vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix()); 
     917        //vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix()); 
    918918 
    919919 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3113 r3114  
    110110        const float projectedEyeSpaceDepth = length(translatedPos) * invlen; 
    111111         
    112         float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 0 : abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 
     112        float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ?  
     113                0 : abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 
    113114 
    114115        return depthDif; 
Note: See TracChangeset for help on using the changeset viewer.