Changeset 3112


Ignore:
Timestamp:
11/09/08 23:06:26 (16 years ago)
Author:
mattausch
Message:

played around with indexing for offset vector, but now choosing different approach: computing offset to old pos in fragment shader!

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

Legend:

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

    r3111 r3112  
    340340                 "samples", "bl", "br", "tl", "tr",  
    341341                 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr",  
    342                  "oldtl", "oldtr", "attribsTex", "inverseModelTrafo"}; 
     342                 "oldtl", "oldtr", "attribsTex", "inverseModelTrafos"}; 
    343343        sCgSsaoProgram->AddParameters(ssaoParams, 0, 19); 
    344344         
     
    565565        sCgSsaoProgram->SetTexture(i ++, attribsTex); 
    566566 
    567         sCgSsaoProgram->SetMatrix(i ++, invTrafo); 
     567        float trafos[32]; 
     568        for (int i = 0; i < 16; ++ i) 
     569                trafos[i] = ((const float *)invTrafo.x)[i]; 
     570 
     571        static Matrix4x4 identity = IdentityMatrix(); 
     572 
     573        for (int i = 0; i < 16; ++ i) 
     574                trafos[i+16] = ((const float *)identity.x)[i]; 
     575 
     576        sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2); 
    568577        //sCgSsaoProgram->SetMatrix(i ++, IdentityMatrix()); 
    569578 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp

    r3057 r3112  
    4545        if(lastError) 
    4646        { 
    47                 printf("%s\n\n", cgGetErrorString(lastError)); 
     47                Debug << "\n" << cgGetErrorString(lastError) << endl; 
     48                Debug << "\n" << cgGetLastListing(sCgContext) << endl; 
     49                /*printf("%s\n\n", cgGetErrorString(lastError)); 
    4850                printf("%s\n", cgGetLastListing(sCgContext)); 
    49                  
     51                */ 
    5052                printf("Cg error, exiting...\n"); 
     53 
    5154 
    5255                exit(0); 
     
    6366        // get the optimal fragment profile 
    6467        sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
     68        //sCgFragmentProfile = CG_PROFILE_GPU_FP; 
     69                //CG_PROFILE_FP40;; 
    6570        cgGLSetOptimalOptions(sCgFragmentProfile); 
    6671        // get the optimal vertex profile 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp

    r3104 r3112  
    2121 
    2222 
     23 
    2324/*********************************************************/ 
    2425/*         GPUProgramParameters implementation           */ 
     
    5253        mMatrices.clear(); 
    5354        mArrays.clear(); 
     55        mMatrixArrays.clear(); 
    5456 
    5557        mTimerParam = -1; 
     
    118120 
    119121 
     122void GPUProgramParameters::SetMatrixArray(int idx, float *mats, int numElements) 
     123{ 
     124        if (mMatrixArrays.size() < idx + 1) 
     125                mMatrixArrays.resize(idx + 1); 
     126 
     127        mMatrixArrays[idx] = MatrixArrayParam(mats, numElements); 
     128} 
     129 
     130 
    120131void GPUProgramParameters::SetTexture(int idx, unsigned int tex) 
    121132{ 
     
    199210{ 
    200211        SetMatrix(mProgram->GetParamIdxByName(name), mat); 
     212} 
     213 
     214 
     215void GPUProgramParameters::SetMatrixArray(const string &name, float *mats, int numElements) 
     216{ 
     217        SetMatrixArray(mProgram->GetParamIdxByName(name), mats, numElements); 
    201218} 
    202219 
     
    272289        } 
    273290 
     291        for (int i = 0; i < (int)mMatrixArrays.size(); ++ i) 
     292        { 
     293                const MatrixArrayParam &p = mMatrixArrays[i]; 
     294 
     295                if (p.mValid) 
     296                        mProgram->SetMatrixArray(i, p.mValues, p.mNumEntries); 
     297        } 
     298 
    274299        if (mTimerParam >= 0) 
    275300                mProgram->SetValue1f(mTimerParam, sCurrentTimer); 
     
    295320        // transform to view space 
    296321        cam->GetViewOrientationMatrix(vo); 
    297         //sCurrentLightDir = /*vo **/ -light->GetDirection(); 
    298322        sCurrentLightDir = vo * -light->GetDirection(); 
    299323} 
     
    441465 
    442466 
     467void ShaderProgram::SetMatrixArray(int idx, float *mats, int numElements) 
     468{ 
     469        cgGLSetMatrixParameterArrayfc(GetParameter(idx), 0, numElements, (const float *)mats); 
     470} 
     471 
     472 
     473 
    443474void ShaderProgram::SetTexture(int idx, unsigned int tex) 
    444475{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h

    r3104 r3112  
    5656        void SetArray2f(int idx, float *vals, int numElements); 
    5757        void SetArray3f(int idx, float *vals, int numElements); 
    58  
    5958        /** Sets the texture parameter. 
    6059        */ 
     
    6362        */ 
    6463        void SetMatrix(int idx, Matrix4x4 *mat); 
     64        /** Sets an array of matrices 
     65        */ 
     66        void SetMatrixArray(int idx, float *vals, int numElements); 
    6567 
    6668        //////////// 
     
    9698        void SetArray2f(const std::string &name, float *vals, int numElements); 
    9799        void SetArray3f(const std::string &name, float *vals, int numElements); 
     100 
    98101        /** Sets the texture parameter. 
    99102        */ 
     
    102105        */ 
    103106        void SetMatrix(const std::string &name, Matrix4x4 *mat); 
     107        /** Sets an array of matrices 
     108        */ 
     109        void SetMatrixArray(const std::string &name, float *vals, int numElements); 
     110 
    104111        /** Feeds the shader program with the parameter values. 
    105112        */ 
     
    120127                { 
    121128                        for (int i = 0; i < mNumComponents; ++ i) 
    122                         { 
    123129                                mValues[i] = val[i]; 
    124                         } 
    125130                } 
    126131 
     
    164169        }; 
    165170 
     171 
     172        struct MatrixArrayParam 
     173        { 
     174                MatrixArrayParam(): mValues(NULL), mNumEntries(0), mValid(false) {} 
     175                MatrixArrayParam(float *mats, int numEntries):  
     176                mValues(mats), mNumEntries(numEntries), mValid(true) 
     177                {} 
     178 
     179                bool mValid; 
     180                float *mValues; 
     181 
     182                int mNumEntries; 
     183        }; 
     184 
     185 
    166186        /// the program this parameter set is connected to 
    167187        ShaderProgram *mProgram; 
     
    176196        std::vector<MatrixParam> mMatrices; 
    177197        std::vector<ArrayParam> mArrays; 
     198        std::vector<MatrixArrayParam> mMatrixArrays; 
    178199}; 
    179200 
     
    215236        void SetArray3f(int idx, float *vals, int numElements); 
    216237        void SetMatrix(int idx, const Matrix4x4 &mat); 
     238        void SetMatrixArray(int idx, float *mats, int numElements); 
    217239 
    218240        void SetTexture(int idx, unsigned int tex); 
     
    233255        */ 
    234256        void SetMatrix(const std::string &name, const Matrix4x4 &mat); 
     257        /** Sets array of matrices 
     258        */ 
     259        void SetMatrixArray(const std::string &name, float *mats, int numElements); 
    235260        /** Sets the texture parameter. 
    236261        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3111 r3112  
    529529                dynamicObjects[i]->mId = 0; 
    530530         
    531         buddha->mId = 250; 
     531        //buddha->mId = 250; 
     532        buddha->mId = 1; 
    532533 
    533534 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3111 r3112  
    66 
    77#define USE_EYESPACE_DEPTH 1 
     8//#extension GL_EXT_gpu_shader4 : enable 
     9 
    810 
    911 
     
    130132                                                                uniform float3 tl, 
    131133                                                                uniform float3 tr,  
     134                                                                float3 projPos, 
    132135                                                                float invW, 
    133                                                                 float3 projPos, 
    134                                                                 float4x4 inverseModelTrafo, 
     136                                                                float4x4 inverseModelTrafos[2], 
    135137                                                                float id, 
    136138                                                                uniform sampler2D noiseTex, 
     
    148150        //////////// 
    149151        //-- dynamic objects 
    150          
     152        /*float4x4 dummy; 
     153        uniform mat4 ident = float4x4(1); 
     154        x = dot(vec, ident[n]); 
     155*/ 
     156        float4x4 dummyTrafo = inverseModelTrafos[(int)id]; 
    151157        //float4x4 trafo = (id < 10.0f) ? oldModelViewProj : mul(oldModelViewProj, inverseModelTrafo); 
    152         float4x4 trafo = mul(oldModelViewProj, inverseModelTrafo); 
     158        float4x4 trafo = mul(oldModelViewProj, dummyTrafo); 
    153159 
    154160        // compute translational portion 
     
    351357                   uniform float3 oldtr, 
    352358                   uniform sampler2D attribsTex, 
    353                    uniform float4x4 inverseModelTrafo 
     359                   uniform float4x4 inverseModelTrafos[2] 
    354360                   ) 
    355361{ 
     
    369375         
    370376        float4 projPos = mul(modelViewProj, eyeSpacePos); 
    371         const float w = 1.0f / projPos.w; 
    372         projPos *= w; 
    373         float scaleFactor = SAMPLE_RADIUS * w; 
     377        const float invw = 1.0f / projPos.w; 
     378        projPos *= invw; 
     379        float scaleFactor = SAMPLE_RADIUS * invw; 
    374380         
    375381        float2 ao = float2(1.0f, 0); 
     
    387393        OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos, 
    388394                                              oldTex, oldModelViewProj, temporalCoherence, 
    389                                               colors, w, bl, br, tl, tr, projPos, inverseModelTrafo, id.z, 
    390                                                                           noiseTex, samples, scaleFactor, oldbl, oldbr, oldtl, oldtr); 
     395                                              colors,  
     396                                                                          bl, br, tl, tr,  
     397                                                                          projPos.xyz,  
     398                                                                          invw,  
     399                                                                          inverseModelTrafos, 
     400                                                                          id.z, 
     401                                                                          noiseTex,  
     402                                                                          samples,  
     403                                                                          scaleFactor,  
     404                                                                          oldbl, oldbr, oldtl, oldtr); 
    391405 
    392406        //OUT.illum_col.xyz = id; 
Note: See TracChangeset for help on using the changeset viewer.