Changeset 3155 for GTP


Ignore:
Timestamp:
11/24/08 17:17:26 (16 years ago)
Author:
mattausch
Message:

improved valid sample detection not workign yet

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

Legend:

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

    r3154 r3155  
    176176 
    177177                ambient.x = ambient.y = ambient.z = 0.2f; 
    178                 //diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f; 
    179                 diffuse.x = diffuse.y = diffuse.z = 1.0f; 
     178                diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f; 
     179                //diffuse.x = diffuse.y = diffuse.z = 1.0f; 
    180180                spec.x = spec.y = spec.z = .0f; 
    181181                emm = spec; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp

    r3153 r3155  
    2323        } 
    2424         
    25         std::cin.get(); 
     25        //std::cin.get(); 
    2626        cout << "conversion successful" << endl; 
    2727 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3151 r3155  
    5858static ShaderProgram *sCgDownSampleProgram = NULL; 
    5959static ShaderProgram *sCgScaleDepthProgram = NULL; 
     60static ShaderProgram *sCgPrepareSsaoProgram = NULL; 
    6061 
    6162 
     
    291292        //-- the flip-flop fbos 
    292293 
    293         //const int dsw = w / 2; const int dsh = h / 2; 
    294         const int dsw = w; const int dsh = h; 
     294        const int dsw = w / 2; const int dsh = h / 2; 
     295        //const int dsw = w; const int dsh = h; 
    295296 
    296297        mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 
     
    373374        sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth"); 
    374375        sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum"); 
     376        sCgPrepareSsaoProgram = sm->CreateFragmentProgram("deferred", "PrepareSsao", "PrepareSsao"); 
    375377 
    376378 
     
    410412        //////////////// 
    411413 
    412         string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights", "bl", "br", "tl", "tr"}; 
     414        string combineSsaoParams[] =  
     415                {"colorsTex", "normalsTex", "ssaoTex", "filterOffs",  
     416                 "filterWeights", "bl", "br", "tl", "tr"}; 
    413417        sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9); 
    414418 
     
    439443        //////////////// 
    440444 
     445         
     446        string prepareSsaoParams[] =  
     447                {"colorsTex", "oldTex", "modelViewProj", "oldModelViewProj", "oldEyePos",  
     448                 "oldbl", "oldbr", "oldtl", "oldtr", "diffVals"}; 
     449 
     450        sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10); 
     451 
     452 
     453        //////////////// 
     454 
    441455 
    442456        const float filterWidth = 100.0f; 
    443         //const float filterWidth = 1000.0f; 
    444  
    445 #if 1 
     457 
    446458        PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 
    447459        poisson.Generate((float *)ssaoFilterOffsets); 
     
    461473                ssaoFilterOffsets[2 * i + 1] *= yoffs; 
    462474        } 
    463 #else 
    464         //ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES);  
    465         ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, filterWidth, NUM_SSAO_FILTERSAMPLES);  
    466         //cout<<"ssao filter size: " << NUM_SSAO_FILTERSAMPLES << endl; 
    467         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    468                 ssaoFilterWeights[i] = 1.0f; 
    469  
    470 #endif 
     475 
    471476 
    472477        ///////// 
     
    507512                // downsample fbo buffers 
    508513                // colors 
    509                 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram); 
     514                //DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram); 
     515                PrepareSsao(fbo); 
    510516                DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 
    511517                DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 
     
    601607         
    602608        if (mUseTemporalCoherence || mRegenerateSamples) 
    603         //if (mRegenerateSamples) 
    604609        { 
    605610                mRegenerateSamples = false; 
     
    946951 
    947952 
     953void DeferredRenderer::PrepareSsao(FrameBufferObject *fbo) 
     954{ 
     955        GLuint colorsTex, diffVals, oldTex; 
     956 
     957        colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
     958        //normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     959        diffVals = fbo->GetColorBuffer(2)->GetTexture(); 
     960        //diffVals = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 
     961 
     962        // flip flop between illumination buffers 
     963        oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
     964 
     965        int i = 0; 
     966 
     967        sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex); 
     968        //sCgSsaoProgram->SetTexture(i ++, normalsTex); 
     969        sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 
     970         
     971        sCgPrepareSsaoProgram->SetMatrix(i ++, mProjViewMatrix); 
     972        sCgPrepareSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix); 
     973 
     974        for (int j = 0; j < 4; ++ j, ++ i) 
     975                sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 
     976 
     977        Vector3 de; 
     978        de.x = mOldEyePos.x - mEyePos.x; 
     979        de.y = mOldEyePos.y - mEyePos.y;  
     980        de.z = mOldEyePos.z - mEyePos.z; 
     981 
     982        sCgPrepareSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z); 
     983 
     984        sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 
     985 
     986 
     987        glPushAttrib(GL_VIEWPORT_BIT); 
     988        glViewport(0, 0, mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); 
     989         
     990        mDownSampleFbo->Bind(); 
     991 
     992        glDrawBuffers(1, mrt + 0); 
     993 
     994        DrawQuad(sCgPrepareSsaoProgram); 
     995         
     996        glPopAttrib(); 
     997        PrintGLerror("prepareSsao"); 
     998} 
     999 
     1000 
     1001 
    9481002void DeferredRenderer::DownSample(FrameBufferObject *fbo,  
    9491003                                                                  int bufferIdx, 
     
    10091063 
    10101064 
    1011 /* 
    1012 void DeferredRenderer::BackProject(FrameBufferObject *fbo) 
    1013 { 
    1014         // back project new frame into old one and check 
    1015         // if pixel still valid. store this property with ssao texture or even  
    1016         // betteer with color / depth texture. This way 
    1017         // we can sample this property together with the color / depth 
    1018         // values and we do not require additional texture lookups 
    1019         fbo->Bind(); 
    1020  
    1021         GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    1022         //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    1023  
    1024         // overwrite old color texture 
    1025         //colorBufferIdx = 3 - colorBufferIdx; 
    1026         //glDrawBuffers(1, mrt + colorBufferIdx); 
    1027         //glDrawBuffers(1, mrt + colorBufferIdx); 
    1028  
    1029         sCgCombineSsaoProgram->SetTexture(0, colorsTex); 
    1030         //sCgCombineSsaoProgram->SetTexture(1, ssaoTex); 
    1031  
    1032         DrawQuad(sCgBackProjectProgram); 
    1033          
    1034         PrintGLerror("combine ssao"); 
    1035 } 
    1036 */ 
    1037  
    1038  
    10391065void DeferredRenderer::InitFrame() 
    10401066{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3148 r3155  
    107107        void FlipFbos(FrameBufferObject *fbo); 
    108108 
     109        void PrepareSsao(FrameBufferObject *fbo); 
     110 
     111 
    109112 
    110113        //////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3153 r3155  
    471471        //-- load some dynamic stuff 
    472472 
    473         resourceManager->mUseNormalMapping = true; 
    474         //resourceManager->mUseNormalMapping = false; 
    475  
    476         LoadModel("fisch.dem", dynamicObjects); 
    477         //LoadModel("hbuddha.dem", dynamicObjects); 
     473        //resourceManager->mUseNormalMapping = true; 
     474        resourceManager->mUseNormalMapping = false; 
     475 
     476        //LoadModel("fisch.dem", dynamicObjects); 
     477        LoadModel("hbuddha.dem", dynamicObjects); 
    478478        //LoadModel("venusm.dem", dynamicObjects); 
    479479        //LoadModel("camel.dem", dynamicObjects); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3154 r3155  
    1111// for quadratic falloff 
    1212//#define SAMPLE_INTENSITY 0.2f 
    13 //#define SAMPLE_INTENSITY 0.07f 
     13#define SAMPLE_INTENSITY 0.07f 
    1414 
    1515//#define SAMPLE_INTENSITY 0.075f 
    16 #define SAMPLE_INTENSITY 0.2f 
     16//#define SAMPLE_INTENSITY 0.2f 
    1717 
    1818#define SAMPLE_RADIUS 8e-1f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3149 r3155  
    7878        average /= max(total_w, 1e-1f); 
    7979 
    80         return saturate(average ); 
     80        return saturate(average); 
    8181} 
     82 
    8283 
    8384/** Function combining image and indirect illumination buffer using a  
     
    103104                const float scaleFactor = 1.0f; 
    104105                const float adaptFactor = 10.0f; 
    105                  
    106106                const float scale =     adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y); 
    107                          
    108                 ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale); 
     107 
     108                //ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale); 
    109109        } 
    110110 
    111111        OUT.illum_col.xyz = col.xyz * ao.x; 
     112         
     113        OUT.illum_col.xyz = float3(0, ao.x, 0); 
    112114 
    113115        //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3154 r3155  
    200200} 
    201201 
    202 #if 0 
    203 /** This shader computes the reprojection and stores reprojected color / depth values 
    204         as well as a boolean that  
    205 */ 
    206 pixel Reproject(fragment IN,  
    207                                 uniform sampler2D colors, 
    208                                 uniform sampler2D normals) 
    209 { 
    210         float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)); 
    211         const float3 normal = normalize(norm.xyz); 
    212  
    213         /// reconstruct position from the eye space depth 
    214         float3 viewDir = IN.view; 
    215         const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 
    216         const float3 eyeSpacePos = -viewDir * eyeDepth; 
    217         const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 
    218  
    219  
    220         //////////////// 
    221         //-- calculcate the current projected posiion (also used for next frame) 
    222          
    223         float4 currentPos = mul(modelViewProj, worldPos); 
    224          
    225         const float w = SAMPLE_RADIUS / currentPos.w; 
    226         currentPos /= currentPos.w; 
    227          
    228         const float precisionScale = 1e-3f; 
    229         const float currentDepth = currentPos.z * precisionScale; 
    230  
    231         const float2 ao = ssao(IN, colors, noiseTex, samples, normal,  
    232                                    eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 
    233  
    234  
    235         ///////////////// 
    236         //-- compute temporally smoothing 
    237  
    238  
    239         // reproject new frame into old one  
    240          
    241         // calculate projected depth 
    242         float4 projPos = mul(oldModelViewProj, worldPos); 
    243         projPos /= projPos.w; 
    244          
    245         // the current depth projected into the old frame 
    246         const float projDepth = projPos.z * precisionScale; 
    247         // fit from unit cube into 0 .. 1 
    248         const float2 tex = projPos.xy * 0.5f + 0.5f; 
    249         // retrieve the sample from the last frame 
    250         float4 oldCol = tex2D(oldTex, tex); 
    251  
    252         const float oldDepth = oldCol.z; 
    253         //const float depthDif = 1.0f - projDepth / oldDepth; 
    254         const float depthDif = projDepth - oldDepth; 
    255  
    256         //const float oldNumSamples = oldCol.y; 
    257         const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 
    258  
    259         float newWeight; 
    260  
    261         // the number of valid samples in this frame 
    262         //const float newNumSamples = ao.y; 
    263  
    264         if ((temporalCoherence > 0) 
    265                 && (tex.x >= 0.0f) && (tex.x < 1.0f) 
    266                 && (tex.y >= 0.0f) && (tex.y < 1.0f) 
    267                 && (abs(depthDif) < MIN_DEPTH_DIFF)  
    268                 && (abs(oldCol.x - ao.x) < 0.1f) 
    269                 // if visibility changed in the surrounding area we have to recompute 
    270                 //&& (oldNumSamples > 0.8f * newNumSamples) 
    271                 ) 
    272         { 
    273                 // increase the weight for convergence 
    274                 newWeight = oldWeight + 1.0f; 
    275                 OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
    276                 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 
    277         } 
    278         else 
    279         {        
    280                 OUT.illum_col.x = ao.x; 
    281                 newWeight = .0f; 
    282         } 
    283  
    284         OUT.illum_col.y = newWeight; 
    285         OUT.illum_col.z = currentDepth; 
    286  
    287         return OUT; 
    288 } 
    289  
    290 #endif 
    291  
    292202 
    293203float4 Output(fragment IN, uniform sampler2D colors): COLOR 
     
    304214        color.w /= length(IN.view); 
    305215         
     216        return color; 
     217} 
     218 
     219 
     220/** This shader computes the reprojection and checks 
     221        if the reprojected pixel from last frame is still 
     222        valid in the current frame 
     223        */ 
     224inline float PixelValid(sampler2D diffVals, 
     225                                                sampler2D oldTex, 
     226                                                float4 color, 
     227                                                float2 texCoord, 
     228                                                float3 viewDir, 
     229                                                float3 oldEyePos, 
     230                                                float4x4 modelViewProj, 
     231                                                float4x4 oldModelViewProj, 
     232                                                float3 oldbl, 
     233                                                float3 oldbr, 
     234                                                float3 oldtl, 
     235                                                float3 oldtr 
     236                                                ) 
     237{ 
     238        // reconstruct position from the eye space depth 
     239        const float eyeSpaceDepth = color.w; 
     240        const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f); 
     241 
     242        float3 diffVec = tex2Dlod(diffVals, float4(texCoord, 0, 0)).xyz; 
     243         
     244 
     245        //////////////// 
     246        //-- calculcate the current projected posiion (also used for next frame) 
     247         
     248        float4 projPos = mul(modelViewProj, worldPos); 
     249        const float invw = 1.0f / projPos.w; 
     250        projPos *= invw; 
     251 
     252        // compute position from old frame for dynamic objects + translational portion 
     253        //const float3 translatedPos = diffVec - oldEyePos + worldPos.xyz; 
     254        const float3 translatedPos = worldPos.xyz; 
     255 
     256 
     257        ///////////////// 
     258        //-- reproject into old frame and calculate texture position of sample in old frame 
     259 
     260        // note: the old model view matrix only holds the view orientation part 
     261        //float4 backProjPos = mul(oldModelViewProj, float4(translatedPos, 1.0f)); 
     262        float4 backProjPos = mul(modelViewProj, float4(translatedPos, 1.0f)); 
     263        backProjPos /= backProjPos.w; 
     264         
     265        // fit from unit cube into 0 .. 1 
     266        //const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f; 
     267        const float2 oldTexCoords = texCoord; 
     268        // retrieve the sample from the last frame 
     269        const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 
     270 
     271        // calculate eye space position of sample in old frame 
     272        const float oldEyeSpaceDepth = oldPixel.w; 
     273 
     274        // vector from eye pos to old sample  
     275        const float3 oldViewDir = viewDir;//Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 
     276        const float invLen = 1.0f / length(oldViewDir); 
     277        const float projectedEyeSpaceDepth = invLen * length(translatedPos); 
     278         
     279        const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 
     280 
     281        const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 
     282 
     283        //if (squaredLen < 1e-8f) // object not dynamic 
     284        //{} 
     285 
     286        float validPixel; 
     287 
     288        if (1 
     289                && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 
     290                && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 
     291                //&& (depthDif <= MIN_DEPTH_DIFF)  
     292                && (depthDif <= 9e-1f)  
     293                ) 
     294        { 
     295                validPixel = 0.0f;//5f; 
     296        } 
     297        else 
     298        {        
     299                validPixel = 1.5f; 
     300        } 
     301 
     302        return depthDif; 
     303        //return validPixel; 
     304} 
     305 
     306 
     307float4 PrepareSsao(fragment IN, 
     308                                   uniform sampler2D colorsTex, 
     309                                   uniform sampler2D oldTex, 
     310                                   uniform float4x4 modelViewProj, 
     311                                   uniform float4x4 oldModelViewProj, 
     312                                   uniform float3 oldEyePos, 
     313                                   uniform float3 oldbl, 
     314                                   uniform float3 oldbr, 
     315                                   uniform float3 oldtl, 
     316                                   uniform float3 oldtr, 
     317                                   uniform sampler2D diffVals 
     318                                   ): COLOR 
     319{    
     320        //const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 
     321        const float3 viewDir = IN.view; 
     322        float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 
     323 
     324        // store scaled view vector so wie don't have to normalize for e.g., ssao 
     325        color.w /= length(IN.view); 
     326        //color.w = 1; 
     327 
     328        // do reprojection and filter out the pixels that are not save 
     329        float pValid = PixelValid(diffVals, 
     330                oldTex, 
     331                color,  
     332                IN.texCoord, 
     333                viewDir, 
     334                oldEyePos, 
     335                modelViewProj, 
     336                oldModelViewProj, 
     337                oldbl, oldbr, oldtl, oldtr 
     338                ); 
     339 
     340        color.x = pValid; 
    306341        return color; 
    307342} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3151 r3155  
    5151 
    5252// reconstruct world space position 
    53 inline float3 ReconstructSamplePos(uniform sampler2D tex, 
     53inline float3 ReconstructSamplePos(float eyeSpaceDepth, 
    5454                                                                   float2 texcoord,  
    5555                                                                   float3 bl, float3 br, float3 tl, float3 tr) 
    5656{ 
    57         const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 
    58          
    5957        float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 
    6058        float3 samplePos = -viewVec * eyeSpaceDepth; 
     
    117115 
    118116/** This shader computes the reprojection and stores  
    119         reprojected color / depth values as well as a boolean that  
     117        the ssao value of the old pixel as well as the 
     118        weight of the pixel in the new frame. 
    120119*/ 
    121120inline float2 temporalSmoothing(float4 worldPos, 
     
    140139                                                                float3 oldtl, 
    141140                                                                float3 oldtr, 
    142                                                                 float3 diffVec 
     141                                                                float3 diffVec, 
     142                                                                float pixelValid 
    143143                                                                ) 
    144144{ 
     
    183183#endif 
    184184 
    185         float notValid = 0.5f; 
     185        //float pixelValid = 0.5f; 
    186186        float overallDepth = 0; 
    187187 
    188 #if 1 
     188#if 0 
    189189        const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 
    190190 
     
    222222                // if visibility changed in the surrounding area we have to recompute 
    223223                //&& (oldNumSamples > 0.8f * newNumSamples) 
    224                 //&& (notValid < 1.0f) 
     224                //&& (pixelValid < 1.0f) 
    225225                ) 
    226226        { 
    227227                // increase the weight for convergence 
    228228                newWeight = oldWeight + 1.0f; 
    229                 if (notValid > 1.0f) newWeight = 4.0f; 
    230                 //if (notValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f); 
     229                if (pixelValid > 1.0f) newWeight = 4.0f; 
     230                //if (pixelValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f); 
    231231        } 
    232232        else 
     
    234234                newWeight = 1.0f; 
    235235        } 
    236  
    237         //if (oldPixel.y >= 2000) 
    238         //      newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 
    239         //if (newWeight >= 2000) newWeight = 1000; 
    240         //newWeight -= step(512.0f, newWeight) * 256.0f; 
    241236 
    242237        return float2(oldPixel.x, newWeight); 
     
    288283 
    289284                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
    290                 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 
     285                float4 sampleColor = tex2Dlod(colors, float4(texcoord, 0, 0)); 
     286 
     287                const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 
    291288                const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 
     289 
     290                numSamples += sampleColor.x; 
    292291 
    293292 
     
    301300 
    302301                // angle between current normal and direction to sample controls AO intensity. 
    303                 //const float cosAngle = max(-dot(sampleNormal, normal), .0f); 
    304                 //const float cosAngle = .5f - dot(sampleNormal, normal) * 0.5f; 
    305302                float cosAngle = .5f + dot(sampleNormal, -normal) * 0.5f; 
    306  
    307                 float dirAngle = dot(dirSample, normal); 
    308  
    309                 cosAngle *= step(0.0f, dirAngle); 
    310  
    311                 //cosAngle *= step(0.5f, cosAngle); 
    312                 //const float cosAngle = .5f * dot(sampleNormal, normal) + 1.0f; 
     303                // use binary decision to cull samples that are behind current shading point 
     304                cosAngle *= step(0.0f, dot(dirSample, normal)); 
    313305         
    314306                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
     
    374366                const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 
    375367 
    376                 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
    377                 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 
     368                float4 sampleColor = tex2Dlod(colors, float4(texcoord, 0, 0)); 
     369                const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 
    378370                 
     371                numSamples += sampleColor.x; 
     372 
    379373 
    380374                //////////////// 
     
    454448 
    455449         
     450        float2 ao; 
     451 
     452        // note: this should be done with the stencil buffer 
     453        if (eyeSpaceDepth < 1e10f) 
     454        { 
     455                ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir)); 
     456                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals); 
     457        } 
     458        else 
     459        { 
     460                 ao = float2(1.0f, 0); 
     461        } 
     462 
    456463        ///////////////// 
    457464        //-- compute temporal reprojection 
     
    467474                                                                                        scaleFactor,  
    468475                                                                                        oldbl, oldbr, oldtl, oldtr, 
    469                                                                                         diffVec 
     476                                                                                        diffVec, 
     477                                                                                        ao.y 
    470478                                                                                        ); 
    471479 
     
    473481        const float newWeight = temporalVals.y; 
    474482 
    475         float2 ao; 
    476  
    477         // note: this should be done with the stencil buffer 
    478         if (eyeSpaceDepth < 1e10f) 
    479         { 
    480                 //ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir)); 
    481                 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals); 
    482         } 
    483         else 
    484         { 
    485                  ao = float2(1.0f, 0); 
    486         } 
    487  
    488         OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 
     483 
     484        OUT.illum_col.x = ao.y;//(ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 
    489485        OUT.illum_col.y = newWeight; 
    490486        OUT.illum_col.z = invw; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg

    r3116 r3155  
    7575                                         uniform float timer, 
    7676                                         uniform float oldTimer 
    77                                          //uniform float4x4 modelMatrix, 
    78                                          //uniform float4x4 oldModelMatrix 
    7977                                         ) 
    8078{ 
Note: See TracChangeset for help on using the changeset viewer.