Changeset 3113 for GTP


Ignore:
Timestamp:
11/10/08 02:39:15 (16 years ago)
Author:
mattausch
Message:

problm with technique system

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

Legend:

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

    r3112 r3113  
    340340                 "samples", "bl", "br", "tl", "tr",  
    341341                 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr",  
    342                  "oldtl", "oldtr", "attribsTex", "inverseModelTrafos"}; 
    343         sCgSsaoProgram->AddParameters(ssaoParams, 0, 19); 
     342                 "oldtl", "oldtr", "attribsTex"}; 
     343        sCgSsaoProgram->AddParameters(ssaoParams, 0, 18); 
    344344         
    345345        string giParams[] =  
     
    574574                trafos[i+16] = ((const float *)identity.x)[i]; 
    575575 
    576         sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2); 
     576        //sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2); 
    577577        //sCgSsaoProgram->SetMatrix(i ++, IdentityMatrix()); 
    578578 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3071 r3113  
    127127        } 
    128128 
    129         static ShaderProgram *sTreeAnimationProgram = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation"); 
    130         static ShaderProgram *sTreeAnimationProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt"); 
     129 
     130        static ShaderProgram *sTreeAnimationProgram =  
     131                ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation"); 
     132        static ShaderProgram *sTreeAnimationProgramMrt =  
     133                ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt"); 
     134 
    131135 
    132136        /////////// 
     
    168172                                        /// use a timer to simulate the moving of the tree in the wind 
    169173                                        vtxParams->SetTimerParam(0); 
     174 
    170175                                        // wind direction 
    171176                                        static Vector3 windDir = Normalize(Vector3(0.8f, 0.2f, 0.0f)); 
     
    298303 
    299304        deferred->SetVertexProgram(sDefaultVertexProgramMrt); 
     305 
     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); 
     311 
    300312        mat->AddTechnique(deferred); 
    301313         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r3110 r3113  
    164164{ 
    165165        if (mTransform->IsIdentity()) return mCenter; 
    166  
    167166        return mTransform->GetMatrix() *  mCenter; 
    168167} 
     
    171170void SceneEntity::Prepare(RenderState *state) 
    172171{ 
    173         int id[] = {(mId / (255 * 255)) % 255, (mId / 255) % 255, mId % 255, 0}; 
     172        /*int id[] = {(mId / (255 * 255)) % 255, (mId / 255) % 255, mId % 255, 0}; 
    174173 
    175174        GLfloat fogColor[4] = {(float)id[0] / 255.0f, (float)id[1] / 255.0f, (float)id[2] / 255.0f, .0f}; 
    176         glFogfv(GL_FOG_COLOR, fogColor); 
     175        glFogfv(GL_FOG_COLOR, fogColor);*/ 
    177176 
    178177        mTransform->Load(state); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp

    r3112 r3113  
    44#include "ShaderProgram.h" 
    55#include "ShaderManager.h" 
     6#include "Matrix4x4.h" 
    67#include <Cg/cg.h> 
    78#include <Cg/cgGL.h> 
     
    4546        if(lastError) 
    4647        { 
     48                printf("Cg error, exiting...\n"); 
     49 
    4750                Debug << "\n" << cgGetErrorString(lastError) << endl; 
    4851                Debug << "\n" << cgGetLastListing(sCgContext) << endl; 
    49                 /*printf("%s\n\n", cgGetErrorString(lastError)); 
     52 
     53                printf("%s\n\n", cgGetErrorString(lastError)); 
    5054                printf("%s\n", cgGetLastListing(sCgContext)); 
    51                 */ 
    52                 printf("Cg error, exiting...\n"); 
    53  
    5455 
    5556                exit(0); 
     
    8586        fragmentProgMrtTex = CreateFragmentProgram("mrt", "fragtex", "defaultFragmentTexMrt"); 
    8687 
    87         // provide the current view matrix 
     88        // provide the current view matrix: 
     89        // this is an automatic parameter that is updated each frame 
    8890        fragmentProgMrt->AddParameter("viewMatrix", 0); 
    8991        fragmentProgMrtTex->AddParameter("viewMatrix", 0); 
     92 
     93        vertexProgMrt->AddParameter("viewMatrix", 0); 
     94         
     95        // these parameters are used for ssao 
     96        vertexProgMrt->AddParameter("modelMatrix", 1); 
     97        vertexProgMrt->AddParameter("oldModelMatrix", 2); 
     98         
    9099 
    91100        // add a texture parameter 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp

    r3112 r3113  
    138138 
    139139 
    140 void GPUProgramParameters::SetMatrix(int idx, Matrix4x4 *mat) 
     140void GPUProgramParameters::SetMatrix(int idx, const Matrix4x4 &mat) 
    141141{ 
    142142        if (mMatrices.size() < idx + 1) 
     
    207207 
    208208 
    209 void GPUProgramParameters::SetMatrix(const string &name, Matrix4x4 *mat) 
     209void GPUProgramParameters::SetMatrix(const string &name, const Matrix4x4 &mat) 
    210210{ 
    211211        SetMatrix(mProgram->GetParamIdxByName(name), mat); 
     
    263263                const MatrixParam &p = mMatrices[i]; 
    264264 
    265                 if (p.mValid) 
    266                         mProgram->SetMatrix(i, *p.mValue); 
     265                if (p.mValid) mProgram->SetMatrix(i, p.mValue); 
    267266        } 
    268267         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h

    r3112 r3113  
    44#include "common.h" 
    55#include "glInterface.h" 
    6  
     6#include "Matrix4x4.h" 
    77#include <Cg/cg.h> 
    88#include <Cg/cgGL.h> 
     
    1717class Vector3; 
    1818class Camera; 
    19 class Matrix4x4; 
    2019class ShadowMap; 
    2120class DirectionalLight; 
     
    5655        void SetArray2f(int idx, float *vals, int numElements); 
    5756        void SetArray3f(int idx, float *vals, int numElements); 
    58         /** Sets the texture parameter. 
     57        /** Sets a texture parameter. 
    5958        */ 
    6059        void SetTexture(int idx, unsigned int tex); 
    61         /** Sets the matrix parameter. 
    62         */ 
    63         void SetMatrix(int idx, Matrix4x4 *mat); 
     60        /** Sets a matrix parameter. 
     61        */ 
     62        void SetMatrix(int idx, const Matrix4x4 &mat); 
    6463        /** Sets an array of matrices 
    6564        */ 
    6665        void SetMatrixArray(int idx, float *vals, int numElements); 
     66 
    6767 
    6868        //////////// 
     
    104104        /** Sets the matrix parameter. 
    105105        */ 
    106         void SetMatrix(const std::string &name, Matrix4x4 *mat); 
     106        void SetMatrix(const std::string &name, const Matrix4x4 &mat); 
    107107        /** Sets an array of matrices 
    108108        */ 
    109109        void SetMatrixArray(const std::string &name, float *vals, int numElements); 
    110  
    111110        /** Feeds the shader program with the parameter values. 
    112111        */ 
     
    146145        struct MatrixParam 
    147146        { 
    148                 MatrixParam(): mValue(NULL), mValid(false) {} 
    149  
    150                 MatrixParam(Matrix4x4 *mat): mValue(mat), mValid(true) 
     147                MatrixParam(): mValue(IdentityMatrix()), mValid(false) {} 
     148 
     149                MatrixParam(const Matrix4x4 &mat): mValue(mat), mValid(true) 
    151150                {} 
    152151 
    153152                bool mValid; 
    154                 Matrix4x4 *mValue; 
     153                Matrix4x4 mValue; 
    155154        }; 
    156155 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h

    r3070 r3113  
    3333        */ 
    3434        inline Matrix4x4 GetMatrix() const  { return mMatrix; } 
     35        /** Returns pointer to trafo matrix 
     36        */ 
     37        inline const Matrix4x4 *GetPMatrix() const { return &mMatrix; } 
    3538        /** See Get 
    3639        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3112 r3113  
    5454#include "ShaderManager.h" 
    5555#include "MotionPath.h" 
    56  
     56#include "ShaderProgram.h" 
     57#include "Shape.h" 
    5758 
    5859 
     
    573574        fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
    574575        // a rgb buffer which could hold material properties 
    575         fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
     576        //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
     577        // holding the difference vector to the old frame 
     578        fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
    576579        // another color buffer 
    577580        fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); 
     
    899902void MainLoop()  
    900903{        
    901         static Matrix4x4 invTrafo = IdentityMatrix(); 
     904        GPUProgramParameters *vtxParams =  
     905                buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); 
     906 
     907        static Matrix4x4 oldTrafo; 
     908 
     909        oldTrafo = buddha->GetTransform()->GetMatrix(); 
     910        vtxParams->SetMatrix(2, oldTrafo); 
    902911 
    903912        Vector3 buddhaPos = motionPath->GetCurrentPosition(); 
    904913        Matrix4x4 trafo = TranslationMatrix(buddhaPos); 
     914         
    905915        buddha->GetTransform()->SetMatrix(trafo); 
     916 
     917        vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix()); 
     918 
    906919 
    907920        ///////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3110 r3113  
    1818        float4 eyePos: TEXCOORD1; // eye position 
    1919        float4 normal: TEXCOORD2; 
     20        float4 worldPos: TEXCOORD3; 
     21        float4 oldWorldPos: TEXCOORD4; 
    2022}; 
    2123 
     
    2527{ 
    2628        float4 color: COLOR0;   
    27         //float4 position: POSITION; 
    2829        float4 texCoord: TEXCOORD0;     
    2930 
     
    3132        float4 eyePos: TEXCOORD1; // eye position 
    3233        float4 normal: TEXCOORD2; 
     34        float4 worldPos: TEXCOORD3; 
     35        float4 oldWorldPos: TEXCOORD4; 
    3336}; 
    3437 
     
    3841        float4 col: COLOR0; 
    3942        float3 norm: COLOR1; 
    40         float3 id: COLOR2; 
     43        float3 offsVec: COLOR2; 
    4144}; 
    4245 
     
    4447#pragma position_invariant vtx 
    4548 
    46 vtxout vtx(vtxin IN) 
     49vtxout vtx(vtxin IN,  
     50                   uniform float4x4 viewMatrix, 
     51                   uniform float4x4 modelMatrix, 
     52                   uniform float4x4 oldModelMatrix) 
    4753{ 
    4854        vtxout OUT; 
     
    5662        OUT.position = mul(glstate.matrix.mvp, IN.position); 
    5763 
     64        // the normal has to be correctly transformed with the inverse transpose 
    5865        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
    5966 
     67        // transform the old vertex position into world space 
     68        OUT.worldPos = mul(modelMatrix, IN.position); 
     69        // transform the old vertex position into world space 
     70        OUT.oldWorldPos = mul(oldModelMatrix, IN.position); 
     71         
    6072        return OUT; 
    6173} 
     
    7991        // save world space normal in rt => transform back into world space by 
    8092        // multiplying with inverse view. since transforming normal with T means to  
    81         // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 
    82         pix.norm = mul(transpose(viewMatrix), IN.normal); 
     93        // multiply with the inverse transpose of T, we multiple with  
     94        // Transp(Inv(Inv(view))) = Transp(view) 
     95        pix.norm = mul(transpose(viewMatrix), IN.normal).xyz; 
    8396        // compute eye linear depth 
    8497        pix.col.w = length(IN.eyePos.xyz); 
     98 
    8599        // the scene entity id 
    86         pix.id = glstate.fog.color.xyz; 
    87         //pix.id = float3(1,1,1); 
     100        //pix.id = glstate.fog.color.xyz; 
     101        // the offset to the world pos from old frame 
     102        pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; 
    88103 
    89104        return pix; 
     
    99114        // multiplying with inverse view. since transforming normal with T means to  
    100115        // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 
    101         pix.norm = mul(transpose(viewMatrix), IN.normal); 
     116        pix.norm = mul(transpose(viewMatrix), IN.normal).xyz; 
    102117        // eye space depth 
    103118        pix.col.w = length(IN.eyePos.xyz); 
    104119        // the scene entity id 
    105         pix.id = glstate.fog.color.xyz; 
    106          
     120        //pix.id = glstate.fog.color.xyz; 
     121        // the offset to the world pos from old frame 
     122        pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; 
     123 
    107124        return pix; 
    108125} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3112 r3113  
    124124                                                                float2 texcoord0, 
    125125                                                                float3 oldEyePos, 
    126                                                                 uniform sampler2D oldTex, 
    127                                                                 uniform float4x4 oldModelViewProj, 
    128                                                                 uniform float temporalCoherence, 
    129                                                                 uniform sampler2D colors, 
    130                                                                 uniform float3 bl, 
    131                                                                 uniform float3 br, 
    132                                                                 uniform float3 tl, 
    133                                                                 uniform float3 tr,  
     126                                                                sampler2D oldTex, 
     127                                                                float4x4 oldModelViewProj, 
     128                                                                float temporalCoherence, 
     129                                                                sampler2D colors, 
     130                                                                float3 bl, 
     131                                                                float3 br, 
     132                                                                float3 tl, 
     133                                                                float3 tr,  
    134134                                                                float3 projPos, 
    135135                                                                float invW, 
    136                                                                 float4x4 inverseModelTrafos[2], 
    137                                                                 float id, 
    138                                                                 uniform sampler2D noiseTex, 
    139                                                                 uniform float2 samples[NUM_SAMPLES], 
     136                                                                sampler2D noiseTex, 
     137                                                                float2 samples[NUM_SAMPLES], 
    140138                                                                float scaleFactor, 
    141                                                                 uniform float3 oldbl, 
    142                                                                 uniform float3 oldbr, 
    143                                                                 uniform float3 oldtl, 
    144                                                                 uniform  float3 oldtr 
     139                                                                float3 oldbl, 
     140                                                                float3 oldbr, 
     141                                                                float3 oldtl, 
     142                                                                float3 oldtr, 
     143                                                                float3 diffVec 
    145144                                                                ) 
    146145{ 
    147146        float4 illum_col; 
    148147 
    149  
    150         //////////// 
    151         //-- dynamic objects 
    152         /*float4x4 dummy; 
    153         uniform mat4 ident = float4x4(1); 
    154         x = dot(vec, ident[n]); 
    155 */ 
    156         float4x4 dummyTrafo = inverseModelTrafos[(int)id]; 
    157         //float4x4 trafo = (id < 10.0f) ? oldModelViewProj : mul(oldModelViewProj, inverseModelTrafo); 
    158         float4x4 trafo = mul(oldModelViewProj, dummyTrafo); 
    159  
    160         // compute translational portion 
    161         const float3 translatedPt = worldPos.xyz - oldEyePos; 
     148        // compute position from old frame for dynamic objects + translational portion 
     149        const float3 translatedPt = worldPos.xyz - oldEyePos + diffVec; 
    162150 
    163151 
     
    166154 
    167155        // note: the old model view matrix only holds the view orientation part 
    168         float4 backProjPos = mul(trafo, float4(translatedPt, 1.0f)); 
     156        float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f)); 
    169157        backProjPos /= backProjPos.w; 
    170158         
     
    256244 
    257245        illum_col.z = invW; 
    258         //illum_col.y = depthDif; 
     246        //illum_col.x = length(diffVec*50.0f); 
    259247 
    260248        return illum_col; 
     
    356344                   uniform float3 oldtl, 
    357345                   uniform float3 oldtr, 
    358                    uniform sampler2D attribsTex, 
    359                    uniform float4x4 inverseModelTrafos[2] 
     346                   uniform sampler2D attribsTex 
    360347                   ) 
    361348{ 
     
    386373 
    387374 
     375        //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
     376        float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
     377 
    388378        ///////////////// 
    389         //-- compute temporally smoothing 
    390  
    391         float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
     379        //-- compute temporal reprojection 
    392380 
    393381        OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos, 
     
    397385                                                                          projPos.xyz,  
    398386                                                                          invw,  
    399                                                                           inverseModelTrafos, 
    400                                                                           id.z, 
    401387                                                                          noiseTex,  
    402388                                                                          samples,  
    403389                                                                          scaleFactor,  
    404                                                                           oldbl, oldbr, oldtl, oldtr); 
     390                                                                          oldbl, oldbr, oldtl, oldtr, 
     391                                                                          diffVec); 
    405392 
    406393        //OUT.illum_col.xyz = id; 
Note: See TracChangeset for help on using the changeset viewer.