Changeset 3115 for GTP


Ignore:
Timestamp:
11/10/08 18:43:06 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
10 edited

Legend:

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

    r3066 r3115  
    1212camPosition=483.398f 242.364f 186.078f 
    1313camDirection=1 0 0 
    14 lightDirection=-0.8f 1.0f -0.7f 
     14#lightDirection=-0.8f 1.0f -0.7f 
     15lightDirection=-0.3f 0.2f -0.7f 
    1516#lightDirection=0.0f 0.0f -1.0f 
    1617useFullScreen=0 
     
    2425 
    2526# ssao temporal coherence factor 
    26 tempCohFactor=50.0f 
    27  
     27tempCohFactor=100.0f 
     28# tone mapping 
    2829useHDR=0 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3113 r3115  
    259259        //-- the flip-flop fbos 
    260260 
    261         const int dsw = w / 2; 
    262         const int dsh = h / 2; 
    263  
    264         //const int dsw = w; 
    265         //const int dsh = h; 
     261        const int dsw = w / 2; const int dsh = h / 2; 
     262        //const int dsw = w; const int dsh = h; 
    266263 
    267264        mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3114 r3115  
    168168                                        { 
    169169                                                tech->SetVertexProgram(sTreeAnimationProgramMrt); 
     170                                                vtxParams->SetOldTimerParam(5); 
    170171                                        } 
    171172 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp

    r3114 r3115  
    1717 
    1818static float sCurrentTimer = 0; 
     19static float sOldTimer = 0; 
    1920static Matrix4x4 sCurrentViewMatrix = IdentityMatrix(); 
    2021static Vector3 sCurrentViewDir = Vector3::UNIT_Y(); 
     
    158159{ 
    159160        mTimerParam = idx; 
     161} 
     162 
     163 
     164void GPUProgramParameters::SetOldTimerParam(int idx) 
     165{ 
     166        mOldTimerParam = idx; 
    160167} 
    161168 
     
    318325        if (mTimerParam >= 0) 
    319326                mProgram->SetValue1f(mTimerParam, sCurrentTimer); 
    320  
     327        if (mOldTimerParam >= 0) 
     328                mProgram->SetValue1f(mOldTimerParam, sOldTimer); 
    321329        if (mViewDirParam >= 0) 
    322330                mProgram->SetValue3f(mViewDirParam, sCurrentViewDir.x, sCurrentViewDir.y, sCurrentViewDir.z); 
     
    339347{ 
    340348        static PerfTimer mytimer; 
     349        sOldTimer = sCurrentTimer; 
    341350        sCurrentTimer = mytimer.Elapsedms(false) * M_PI / 180.0f; 
    342351 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h

    r3114 r3115  
    7272        */ 
    7373        void SetTimerParam(int idx); 
     74 
     75        void SetOldTimerParam(int idx); 
    7476        /** This parameter is connected to the current view matrix 
    7577                that is updated once per frame. 
     
    195197 
    196198        int mTimerParam; 
     199        int mOldTimerParam; 
    197200        int mViewDirParam; 
    198201        int mLightDirParam; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r3114 r3115  
    4141        mIsIdentity = false; 
    4242        mOldMatrix = mMatrix; 
    43         mMatrix = mMatrix * trafo; 
     43        mMatrix = trafo * mMatrix; 
    4444} 
    4545 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3114 r3115  
    905905                buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); 
    906906 
    907         static Matrix4x4 oldTrafo; 
    908  
    909         oldTrafo = buddha->GetTransform()->GetMatrix(); 
    910         //vtxParams->SetMatrix(2, oldTrafo); 
    911  
     907        Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix(); 
    912908        Vector3 buddhaPos = motionPath->GetCurrentPosition(); 
    913909        Matrix4x4 trafo = TranslationMatrix(buddhaPos); 
     
    915911        buddha->GetTransform()->SetMatrix(trafo); 
    916912 
    917         //vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix()); 
     913        Matrix4x4 rotMatrix = RotationZMatrix(M_PI * 1e-3f); 
     914 
     915        dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
    918916 
    919917 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3108 r3115  
    2121 
    2222//#define ILLUM_INTENSITY 8e-2f 
    23 #define ILLUM_INTENSITY 2e-2f 
     23#define ILLUM_INTENSITY 5e-3f 
    2424 
    2525#define VIEW_CORRECTION_SCALE 1.0f 
     
    2929//-- reprojection 
    3030 
    31 #define MIN_DEPTH_DIFF 5e-2f 
     31#define MIN_DEPTH_DIFF 2e-2f 
    3232#define PRECISION_SCALE 1e-1f 
    3333 
     
    5858 
    5959//#define NUM_SSAO_FILTERSAMPLES 28 
    60 #define NUM_SSAO_FILTERSAMPLES 40 
     60//#define NUM_SSAO_FILTERSAMPLES 40 
     61#define NUM_SSAO_FILTERSAMPLES 100 
    6162 
    6263 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3114 r3115  
    6666 
    6767inline float ComputeDifference(float2 offset, 
    68                                                            uniform sampler2D oldTex, 
    69                                                            const uniform float4x4 oldModelViewProj, 
    70                                                            uniform sampler2D colors, 
    71                                                            uniform sampler2D noiseTex, 
    72                                                            uniform float scaleFactor, 
    73                                                            uniform float3 bl, 
    74                                                            uniform float3 br, 
    75                                                            uniform float3 tl, 
    76                                                            uniform float3 tr,  
     68                                                           sampler2D oldTex, 
     69                                                           float4x4 oldModelViewProj, 
     70                                                           sampler2D colors, 
     71                                                           sampler2D noiseTex, 
     72                                                           float scaleFactor, 
     73                                                           float3 bl, 
     74                                                           float3 br, 
     75                                                           float3 tl, 
     76                                                           float3 tr,  
    7777                                                           float2 texcoord0, 
    7878                                                           float3 oldEyePos, 
    79                                                            uniform float3 oldbl, 
    80                                                            uniform float3 oldbr, 
    81                                                            uniform float3 oldtl, 
    82                                                            uniform float3 oldtr, 
     79                                                           float3 oldbl, 
     80                                                           float3 oldbr, 
     81                                                           float3 oldtl, 
     82                                                           float3 oldtr, 
    8383                                                           float eyeSpaceDepth 
    8484                                                           ) 
    8585{ 
    86         const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy; 
     86        const float2 mynoise = tex2Dlod(noiseTex, float4(texcoord0, 0, 0)).xy; 
    8787 
    8888        const float2 offsetTransformed = myreflect(offset, mynoise); 
     
    9393        const float3 viewVec = Interpol(texCoord, bl, br, tl, tr); 
    9494        const float3 samplePos = -viewVec * sampleEyeSpaceDepth; 
    95  
    9695        const float3 translatedPos = samplePos - oldEyePos; 
     96 
    9797        // reproject into old frame and calculate projected depth 
    9898        float4 projPos = mul(oldModelViewProj, float4(translatedPos, 1.0f)); 
    9999        projPos /= projPos.w; 
    100  
    101100        // fit from unit cube into 0 .. 1 
    102101        const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; 
     
    105104 
    106105        const float oldEyeSpaceDepth = oldPixel.w; 
     106         
     107        // projected linear depth 
    107108        const float3 oldViewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 
    108  
    109109        const float invlen = 1.0f / length(oldViewVec); 
    110         const float projectedEyeSpaceDepth = length(translatedPos) * invlen; 
    111          
    112         float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ?  
    113                 0 : abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 
     110        const float projectedEyeSpaceDepth = invlen * length(translatedPos); 
     111 
     112        float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 0 :  
     113                abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 
    114114 
    115115        return depthDif; 
     
    117117 
    118118 
    119 /** This shader computes the reprojection and stores reprojected color / depth values 
    120         as well as a boolean that  
     119/** This shader computes the reprojection and stores  
     120        reprojected color / depth values as well as a boolean that  
    121121*/ 
    122122inline float4 temporalSmoothing(float4 worldPos, 
     
    148148 
    149149        // compute position from old frame for dynamic objects + translational portion 
    150         const float3 translatedPt = worldPos.xyz - oldEyePos + diffVec; 
     150        const float3 translatedPos = worldPos.xyz - oldEyePos + diffVec; 
    151151 
    152152 
     
    155155 
    156156        // note: the old model view matrix only holds the view orientation part 
    157         float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f)); 
     157        float4 backProjPos = mul(oldModelViewProj, float4(translatedPos, 1.0f)); 
    158158        backProjPos /= backProjPos.w; 
    159159         
     
    172172        const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 
    173173        const float invLen = 1.0f / length(viewVec); 
    174         const float projectedEyeSpaceDepth = invLen * length(translatedPt); 
    175          
    176         //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 
     174        const float projectedEyeSpaceDepth = invLen * length(translatedPos); 
     175         
    177176        const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 
    178         //const float depthDif = abs(projectedEyeSpaceDepth - oldEyeSpaceDepth ) / projectedEyeSpaceDepth; 
    179177 
    180178#else 
     
    182180        const float oldDepth = oldPixel.w; 
    183181        const float projectedDepth = projPos.z; 
    184         //const float projectedDepth = invW * worldPos.z; 
    185  
    186182        // vector from eye pos to old sample  
    187183        const float depthDif = abs(projectedDepth - oldDepth); 
     
    189185 
    190186        float notValid = 0.5f; 
    191  
    192         /* 
    193         for (int i = 0; i < NUM_SAMPLES; ++ i)  
     187        //float overallDepth = 0; 
     188        const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 
     189 
     190        if (squaredLen < 1e-8f) // object not dynamic 
    194191        { 
    195                 float sampleDif = ComputeDifference(samples[i], 
    196                                           oldTex, 
    197                                                           oldModelViewProj, 
    198                                                           colors, 
    199                                                           noiseTex, 
    200                                                           scaleFactor, 
    201                                                           bl, br, tl, tr,  
    202                                                           texcoord0, 
    203                                                           oldEyePos, 
    204                                                           oldbl, oldbr, oldtl, oldtr, 
    205                                                           eyeSpaceDepth); 
    206  
    207                 if (sampleDif >= 5e-2f) ++ notValid; 
    208         } 
    209         */ 
     192                for (int i = 0; i < NUM_SAMPLES; ++ i)  
     193                { 
     194                        float sampleDif = ComputeDifference(samples[i], 
     195                                                                                                oldTex, 
     196                                                                                                oldModelViewProj, 
     197                                                                                                colors, 
     198                                                                                                noiseTex, 
     199                                                                                                scaleFactor, 
     200                                                                                                bl, br, tl, tr,  
     201                                                                                                texcoord0, 
     202                                                                                                oldEyePos, 
     203                                                                                                oldbl, oldbr, oldtl, oldtr, 
     204                                                                                                eyeSpaceDepth 
     205                                                                                                ); 
     206                        //overallDepth += sampleDif; 
     207 
     208                        if (sampleDif >= MIN_DEPTH_DIFF) ++ notValid; 
     209                } 
     210        } 
     211 
    210212 
    211213        // the number of valid samples in this frame 
     
    243245        illum_col.w = projectedDepth; 
    244246#endif 
    245  
     247        //overallDepth = clamp(overallDepth*1e3, 0, 1); 
    246248        illum_col.z = invW; 
    247         //illum_col.x = length(diffVec*50.0f); 
     249        //illum_col.x = overallDepth; 
    248250 
    249251        return illum_col; 
     
    370372        // note: this should be done with the stencil buffer 
    371373        if (eyeSpaceDepth < 1e10f) 
     374        { 
    372375                ao = ssao(IN, colors, noiseTex, samples, normal,  
    373376                          eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir)); 
    374  
     377        } 
    375378 
    376379        //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
     
    409412        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    410413        {        
    411                 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 
     414                average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x; 
    412415                w += filterWeights[i]; 
    413416        } 
     
    434437        //      ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z); 
    435438 
    436         //OUT.illum_col = col * ao.x; 
     439        OUT.illum_col = col * ao.x; 
    437440        //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 
    438441        //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 
    439         OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
     442        //OUT.illum_col = float4(ao.x, 0, 0, col.w); 
    440443        //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    441444        //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg

    r3046 r3115  
    1010         
    1111        float4 color: COLOR; 
    12         //float4 color1: COLOR1; 
    13  
    1412        float4 texCoord: TEXCOORD0; 
    1513}; 
     
    2119        float4 texCoord: TEXCOORD0;     
    2220 
    23         float4 color: COLOR0;   
    24         //float4 color1: COLOR1;   
    25         float4 eyePos: TEXCOORD1; // eye position 
     21        float4 color: COLOR0;  
     22        // eye position 
     23        float4 eyePos: TEXCOORD1;  
    2624        float4 normal: TEXCOORD2; 
     25 
     26        float4 worldPos: TEXCOORD3; 
     27        float4 oldWorldPos: TEXCOORD4; 
    2728}; 
    2829 
     
    5455        const float3 l = normalize(lightDir); 
    5556 
    56         const float dif = max(.0f, dot(OUT.normal.xyz, l)); 
     57        const float diffuse = max(.0f, dot(OUT.normal.xyz, l)); 
    5758 
    5859        //OUT.color.xyz = IN.color.xyz * max(0, dot(OUT.normal.xyz, normalize(lightDir))); 
    59         OUT.color = glstate.material.ambient + glstate.material.front.diffuse * dif; 
     60        OUT.color = glstate.material.ambient + glstate.material.front.diffuse * diffuse; 
    6061        OUT.color.w = IN.color.w; 
    6162        return OUT; 
     
    7273                                         uniform float frequency, 
    7374                                         uniform float2 minMaxPos, 
    74                                          uniform float timer) 
     75                                         uniform float timer, 
     76                                         uniform float oldTimer 
     77                                         //uniform float4x4 modelMatrix, 
     78                                         //uniform float4x4 oldModelMatrix 
     79                                         ) 
    7580{ 
    7681        vtxout OUT; 
     
    8287        float factor = pos * pos * windStrength * sin(timer * frequency); 
    8388 
     89        const float4 offs = float4(factor * windDir, 0); 
     90 
    8491        // transform the vertex position into post projection space 
    8592        OUT.position = mul(glstate.matrix.mvp, IN.position); 
    8693        // displace the input position 
    87         OUT.position += float4(factor * windDir, 0); 
     94        OUT.position += offs; 
    8895 
    8996        // transform the vertex position into eye space 
    9097        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position); 
    91         OUT.eyePos += float4(factor * windDir, 0); 
     98        OUT.eyePos += offs; 
    9299 
    93100        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
    94101         
     102        // hack: no translational component anyway 
     103        OUT.oldWorldPos = float4(.0f); 
     104        OUT.worldPos = offs; 
     105 
    95106        return OUT; 
    96107} 
Note: See TracChangeset for help on using the changeset viewer.