Changeset 2865


Ignore:
Timestamp:
08/25/08 17:34:34 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
13 edited

Legend:

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

    r2864 r2865  
    1010winHeight=768 
    1111camPosition=483.398f 242.364f 186.078f 
    12 camDirection=-1 -1 0 
     12camDirection=1 0 0 
    1313useFullScreen=0 
     14useLODs=0 
    1415#modelPath=data/city/model/ 
    1516 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp

    r2861 r2865  
    2424 
    2525 
     26 
    2627static CGprogram sCgDeferredProgram; 
     28static CGprogram sCgAntiAliasingProgram; 
     29 
     30 
    2731static CGparameter sColorsTexParam; 
    2832static CGparameter sPositionsTexParam; 
    2933static CGparameter sNormalsTexParam; 
    3034 
     35static CGparameter sColorsTexAntiAliasingParam; 
     36static CGparameter sNormalsTexAntiAliasingParam; 
     37 
    3138 
    3239DeferredShader::DeferredShader(int w, int h): 
    3340mWidth(w), mHeight(h) 
    34 {} 
     41{ 
     42        mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     43        // the diffuse color buffer 
     44        mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 
     45} 
    3546 
    3647 
     
    6576                cerr << "deferred program failed to load" << endl; 
    6677 
     78        sCgAntiAliasingProgram =  
     79                cgCreateProgramFromFile(context,  
     80                                                                CG_SOURCE, 
     81                                                                "src/shaders/antialiasing.cg",  
     82                                                                RenderState::sCgFragmentProfile, 
     83                                                                "main", 
     84                                                                NULL); 
     85 
     86        if (sCgAntiAliasingProgram != NULL) 
     87        { 
     88                cgGLLoadProgram(sCgAntiAliasingProgram); 
     89 
     90                sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");   
     91                sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 
     92        } 
     93        else 
     94                cerr << "antialiasing program failed to load" << endl; 
     95 
    6796 
    6897        PrintGLerror("init"); 
     
    72101void DeferredShader::Render(FrameBufferObject *fbo) 
    73102{ 
    74         FrameBufferObject::Release(); 
    75  
     103        FirstPass(fbo); 
     104        AntiAliasing(fbo); 
     105} 
     106 
     107 
     108void DeferredShader::FirstPass(FrameBufferObject *fbo) 
     109{ 
    76110        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    77111        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    78112        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     113 
     114        // read the second buffer, write to the first buffer 
     115        mFbo->Bind(); 
    79116 
    80117        glPushAttrib(GL_VIEWPORT_BIT); 
     
    141178        glPopAttrib(); 
    142179 
     180        FrameBufferObject::Release(); 
     181 
    143182        PrintGLerror("deferred shading"); 
    144183} 
    145184 
    146185 
     186static void SetVertex(float x, float y, float x_offs, float y_offs) 
     187{ 
     188        glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center 
     189        glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top 
     190        glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom 
     191        glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top 
     192        glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom 
     193 
     194        glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right 
     195        glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom 
     196 
     197        glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 
     198} 
     199 
     200 
     201void DeferredShader::AntiAliasing(FrameBufferObject *fbo) 
     202{ 
     203        GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture(); 
     204        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     205 
     206        glPushAttrib(GL_VIEWPORT_BIT); 
     207        glViewport(0, 0, mWidth, mHeight); 
     208 
     209        glDisable(GL_ALPHA_TEST); 
     210        glDisable(GL_TEXTURE_2D); 
     211        glDisable(GL_LIGHTING); 
     212         
     213        glMatrixMode(GL_PROJECTION); 
     214        glPushMatrix(); 
     215        glLoadIdentity(); 
     216 
     217        glMatrixMode(GL_MODELVIEW); 
     218        glPushMatrix(); 
     219        glLoadIdentity(); 
     220 
     221        const float offs = 0.5f; 
     222         
     223        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     224        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     225 
     226        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     227 
     228        cgGLBindProgram(sCgAntiAliasingProgram); 
     229 
     230        cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex); 
     231        cgGLEnableTextureParameter(sColorsTexAntiAliasingParam); 
     232 
     233        cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 
     234        cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 
     235         
     236        glColor3f(1.0f, 1.0f, 1.0f); 
     237 
     238        float offs2 = 0.5f; 
     239 
     240        glBegin(GL_QUADS); 
     241 
     242        // the neighbouring texels 
     243        float x_offs = 1.0f / mWidth; 
     244        float y_offs = 1.0f / mHeight; 
     245 
     246        SetVertex(0, 0, x_offs, y_offs); 
     247        SetVertex(1, 0, x_offs, y_offs); 
     248        SetVertex(1, 1, x_offs, y_offs); 
     249        SetVertex(0, 1, x_offs, y_offs); 
     250 
     251        glEnd(); 
     252 
     253        cgGLDisableTextureParameter(sColorsTexAntiAliasingParam); 
     254        cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam); 
     255 
     256        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     257         
     258        glEnable(GL_LIGHTING); 
     259        glDisable(GL_TEXTURE_2D); 
     260         
     261        glMatrixMode(GL_PROJECTION); 
     262        glPopMatrix(); 
     263 
     264        glMatrixMode(GL_MODELVIEW); 
     265        glPopMatrix(); 
     266 
     267        glPopAttrib(); 
     268 
     269        PrintGLerror("deferred shading"); 
     270} 
     271 
     272 
    147273} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h

    r2861 r2865  
    3838protected: 
    3939 
     40        void FirstPass(FrameBufferObject *fbo); 
     41        void AntiAliasing(FrameBufferObject *fbo); 
     42 
    4043        int mWidth; 
    4144        int mHeight; 
     45 
     46        FrameBufferObject *mFbo; 
    4247}; 
    4348 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r2853 r2865  
    2323 
    2424        // generates poisson distribution on disc 
    25         float minDist = 2.0f / sqrt((float)mNumSamples); 
     25        float minDist = 4.0f / sqrt((float)mNumSamples); 
    2626 
    2727        //cout << "minDist before= " << minDist << endl; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r2853 r2865  
    1818{ 
    1919 
     20bool SceneEntity::sUseLODs = true; 
     21 
    2022 
    2123SceneEntity::SceneEntity(Transform3 *trafo):  
     
    3335void SceneEntity::UpdateLODs(const Vector3 &viewPoint) 
    3436{ 
     37        mCurrentLODLevel = 0; 
     38 
     39        if (!sUseLODs) return; 
     40 
    3541        const Vector3 pos = GetCenter(); 
    3642 
    3743        const float dist = SqrDistance(pos, viewPoint); 
    38  
    39         mCurrentLODLevel = 0; 
    4044 
    4145        // note: we assume that lods are ordered from smallest distance to largest 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h

    r2848 r2865  
    9090        */ 
    9191        Vector3 GetCenter() const; 
    92  
     92        /** If false, the highest (most detailed) LOD level is used for all entities. 
     93        */ 
     94        static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; } 
    9395 
    9496 
     
    119121        /// the center of gravity of this scene entity 
    120122        Vector3 mCenter; 
     123 
     124        static bool sUseLODs; 
    121125}; 
    122126 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp

    r2863 r2865  
    3030static CGparameter sNoiseMultiplierParam; 
    3131static CGparameter sExpFactorParam; 
     32static CGprogram sCgAntiAliasingProgram; 
     33 
     34static CGparameter sColorsTexAntiAliasingParam; 
     35static CGparameter sNormalsTexAntiAliasingParam; 
     36 
    3237 
    3338static GLuint noiseTex; 
     
    133138                cerr << "ssao program failed to load" << endl; 
    134139 
     140        sCgAntiAliasingProgram =  
     141                cgCreateProgramFromFile(context,  
     142                                                                CG_SOURCE, 
     143                                                                "src/shaders/antialiasing.cg",  
     144                                                                RenderState::sCgFragmentProfile, 
     145                                                                "main", 
     146                                                                NULL); 
     147 
     148        if (sCgAntiAliasingProgram != NULL) 
     149        { 
     150                cgGLLoadProgram(sCgAntiAliasingProgram); 
     151 
     152                sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");   
     153                sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 
     154        } 
     155        else 
     156                cerr << "antialiasing program failed to load" << endl; 
     157 
     158 
    135159        PrintGLerror("init"); 
    136160} 
     
    151175        ComputeSsao(fbo, expFactor); 
    152176        // the second pass just renders the combined solution 
    153         DisplayTexture(); 
     177        //DisplayTexture(); 
     178        AntiAliasing(fbo); 
    154179} 
    155180 
     
    213238 
    214239 
    215         GenerateSamples();  
     240        //GenerateSamples();  
    216241        cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
    217242 
     
    259284 
    260285 
    261 void SsaoShader::DisplayTexture() 
     286/*void SsaoShader::DisplayTexture() 
    262287{ 
    263288        glEnable(GL_TEXTURE_2D); 
     
    300325 
    301326        PrintGLerror("ssao second pass"); 
    302 } 
     327}*/ 
    303328 
    304329 
     
    370395 
    371396 
     397 
     398static void SetVertex(float x, float y, float x_offs, float y_offs) 
     399{ 
     400        glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center 
     401        glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top 
     402        glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom 
     403        glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top 
     404        glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom 
     405 
     406        glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right 
     407        glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom 
     408 
     409        glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 
     410} 
     411 
     412 
     413void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 
     414{ 
     415        GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
     416        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     417 
     418        glPushAttrib(GL_VIEWPORT_BIT); 
     419        glViewport(0, 0, mWidth, mHeight); 
     420 
     421        glDisable(GL_ALPHA_TEST); 
     422        glDisable(GL_TEXTURE_2D); 
     423        glDisable(GL_LIGHTING); 
     424         
     425        glMatrixMode(GL_PROJECTION); 
     426        glPushMatrix(); 
     427        glLoadIdentity(); 
     428 
     429        glMatrixMode(GL_MODELVIEW); 
     430        glPushMatrix(); 
     431        glLoadIdentity(); 
     432 
     433        const float offs = 0.5f; 
     434         
     435        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     436        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     437 
     438        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     439 
     440        cgGLBindProgram(sCgAntiAliasingProgram); 
     441 
     442        cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex); 
     443        cgGLEnableTextureParameter(sColorsTexAntiAliasingParam); 
     444 
     445        cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 
     446        cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 
     447         
     448        glColor3f(1.0f, 1.0f, 1.0f); 
     449 
     450        float offs2 = 0.5f; 
     451 
     452        glBegin(GL_QUADS); 
     453 
     454        // the neighbouring texels 
     455        float x_offs = 1.0f / mWidth; 
     456        float y_offs = 1.0f / mHeight; 
     457 
     458        SetVertex(0, 0, x_offs, y_offs); 
     459        SetVertex(1, 0, x_offs, y_offs); 
     460        SetVertex(1, 1, x_offs, y_offs); 
     461        SetVertex(0, 1, x_offs, y_offs); 
     462 
     463        glEnd(); 
     464 
     465        cgGLDisableTextureParameter(sColorsTexAntiAliasingParam); 
     466        cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam); 
     467 
     468        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     469         
     470        glEnable(GL_LIGHTING); 
     471        glDisable(GL_TEXTURE_2D); 
     472         
     473        glMatrixMode(GL_PROJECTION); 
     474        glPopMatrix(); 
     475 
     476        glMatrixMode(GL_MODELVIEW); 
     477        glPopMatrix(); 
     478 
     479        glPopAttrib(); 
     480 
     481        PrintGLerror("deferred shading"); 
     482} 
     483 
     484 
    372485} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h

    r2863 r2865  
    5050        void ComputeSsao(FrameBufferObject *fbo, float expFactor); 
    5151 
    52         void DisplayTexture(); 
     52        //void DisplayTexture(); 
     53        void AntiAliasing(FrameBufferObject *fbo); 
    5354 
    5455        void CreateNoiseTex2D(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp

    r2850 r2865  
    9292        } 
    9393 
    94         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage); 
    95          
    96         if (mUseMipMap) 
     94        if (!mUseMipMap) 
     95                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage); 
     96        else     
    9797                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, mImage); 
    9898 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2864 r2865  
    124124bool showHelp = false; 
    125125bool showStatistics = false; 
    126 bool showOptions = false; 
     126bool showOptions = true; 
    127127bool showBoundingVolumes = false; 
    128128bool visMode = false; 
     
    164164 
    165165bool useFullScreen = false; 
     166 
     167bool useLODs = true; 
     168 
    166169 
    167170static Matrix4x4 matProjectionView = IdentityMatrix(); 
     
    291294                env.GetVectorParam(string("camDirection"), camDir); 
    292295 
     296                env.GetBoolParam(string("useLODs"), useLODs); 
     297 
    293298                //env.GetStringParam(string("modelPath"), model_path); 
    294299                //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 
    295300 
     301                cout << "*********** parameters ***************" << endl; 
    296302                cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl;  
    297303                cout << "maxBatchSize: " << maxBatchSize << endl; 
     
    303309                cout << "winHeight: " << winHeight << endl; 
    304310                cout << "useFullScreen: " << useFullScreen << endl; 
     311                cout << "useLODs: " << useLODs << endl; 
    305312                cout << "camPosition: " << camPos << endl; 
    306313                cout << "expFactor: " << ssaoExpFactor << endl; 
     
    527534        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 
    528535        // the normals buffer 
    529         fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 
     536        //fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 
     537        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 
    530538 
    531539        PrintGLerror("fbo"); 
     
    10671075                if (ssaoExpFactor > 1.0f) ssaoExpFactor = 1.0f; 
    10681076                break; 
     1077        case '9': 
     1078                useLODs = !useLODs; 
     1079                SceneEntity::SetUseLODs(useLODs); 
     1080                break; 
    10691081        case 'o': 
    10701082        case 'O': 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg

    r2864 r2865  
    11struct v2p 
    22{ 
    3         float tc0: TEXCOORD0; // Center 
    4         float tc1: TEXCOORD1; // Center 
    5         float tc2: TEXCOORD2; // Center 
    6         float tc3: TEXCOORD3; // Center 
    7         float tc4: TEXCOORD4; // Center 
    8         float tc5: TEXCOORD5; // Center 
    9         float tc6: TEXCOORD6; // Center 
    10 } 
     3        float2 c:  TEXCOORD0; // center 
     4        float2 lt: TEXCOORD1; // left top 
     5        float2 rb: TEXCOORD2; // right bottom 
     6        float2 rt: TEXCOORD3; // right top 
     7        float2 lb: TEXCOORD4; // left bottom 
     8        float4 lr: TEXCOORD5; // left / right 
     9        float4 tb: TEXCOORD6; // top / bottom 
     10}; 
     11 
     12//uniform sampler2D s_distort; 
     13uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0); 
     14uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth 
     15uniform float4 e_kernel = float4(0.3f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth 
    1116 
    1217 
    13 uniform sampler2D s_distort; 
    14 uniform hlf4 e_barrier; 
    15 uniform half4 e_weights; 
    16 uniform half4 e_kernel; 
     18float4 main(v2p IN,  
     19                        uniform sampler2D colors, 
     20                        uniform sampler2D normals 
     21                        ): COLOR 
     22{ 
     23        // normal discontinuity filter 
     24        float3 nc = (float3)tex2D(normals, IN.c.xy); 
    1725 
    18 half4 main(v2p) : COLOR 
    19 { 
    20  
    21  
    22         // discontinuity filter 
    23         /*float nc = tex1D(s_normal, I.tc0); 
    24         float nd; 
    25  
    26         nd.x = dot(nc, float3(tex2D(s_normal, I.tc1)); 
    27         nd.y = dot(nc, float3(tex2D(s_normal, I.tc2)); 
    28         nd.z = dot(nc, float3(tex2D(s_normal, I.tc3)); 
    29         nd.w = dot(nc, float3(tex2D(s_normal, I.tc4)); 
     26        float4 nd; 
     27        nd.x = dot(nc, float3(tex2D(normals, IN.lt.xy))); 
     28        nd.y = dot(nc, float3(tex2D(normals, IN.rb.xy))); 
     29        nd.z = dot(nc, float3(tex2D(normals, IN.rt.xy))); 
     30        nd.w = dot(nc, float3(tex2D(normals, IN.lb.xy))); 
    3031 
    3132        nd -= e_barrier.x; 
    32         nd = max(0, nd); 
     33        nd = step(0, nd); 
    3334 
    3435        float ne = saturate(dot(nd, e_weights.x)); 
    3536 
    36         float 4 tc5r = = I.tc5.wzyx; 
    37         float 4 tc6r = = I.tc6.wzyx; 
    38 */ 
     37        // opposite coordinates 
     38        float4 lrr = IN.lr.wzyx; 
     39        float4 tbr = IN.tb.wzyx; 
    3940 
     41        // depth filter: compute gradient difference: 
     42        // (c - sample) + (c - opposite sample) 
     43 
     44        float4 dc = float4(tex2D(colors, IN.c).w); 
     45 
     46        float pos_lt = (float)tex2D(colors, IN.lt.xy).w; 
     47        float pos_rb = (float)tex2D(colors, IN.rb.xy).w; 
     48 
     49        float pos_lb = (float)tex2D(colors, IN.lb.xy).w; 
     50        float pos_rt = (float)tex2D(colors, IN.rt.xy).w; 
     51 
     52        float pos_l = (float)tex2D(colors, IN.lr.xy).w; 
     53        float pos_r = (float)tex2D(colors, lrr.xy).w; 
     54 
     55        float pos_t = (float)tex2D(colors, IN.tb.xy).w; 
     56        float pos_b = (float)tex2D(colors, tbr.xy).w; 
     57 
     58        float4 dd; 
     59 
     60        dd.x = pos_lt + pos_rb; 
     61        dd.y = pos_lb + pos_rt; 
     62        dd.z = pos_l + pos_r; 
     63        dd.w = pos_t + pos_b; 
     64 
     65        dd = abs(2.0f * dc - dd) - e_barrier.y; 
     66        dd = step(dd, 0); 
     67        float de = saturate(dot(dd, e_weights.y)); 
     68 
     69        // weight: 0 = no aa, 1 = full antialiasing 
     70        float w = (1.0f - de * ne) * e_kernel.x; 
     71 
     72        // smoothed color 
     73        // (a - c) * w + c = a * w + c * (1 - w) 
     74        float2 offset = IN.c.xy * (1.0f - w); 
     75 
     76        float4 s0 = tex2D(colors, offset + IN.lt.xy * w); 
     77        float4 s1 = tex2D(colors, offset + IN.rb.xy * w); 
     78        float4 s2 = tex2D(colors, offset + IN.rt.xy * w); 
     79        float4 s3 = tex2D(colors, offset + IN.lb.xy * w); 
     80 
     81        return (s0 + s1 + s2 + s3) / 4.0f; 
     82        //return float4(w); 
    4083} 
    41  
    42  
    43  
    44  
    45 struct fragment 
    46 { 
    47   float4 pos: WPOS; // normalized screen position 
    48   float4 texCoord: TEXCOORD0;  
    49 }; 
    50  
    51 struct pixel 
    52 { 
    53   float4 color: COLOR0; 
    54 }; 
    55  
    56  
    57 pixel main(fragment IN,  
    58            uniform sampler2D colorsTex1, 
    59            uniform sampler2D colorsTex2) 
    60 { 
    61   pixel OUT; 
    62    
    63   float4 col1 = tex2D(colorsTex1, IN.texCoord.xy); 
    64   float4 col2 = tex2D(colorsTex2, IN.texCoord.xy); 
    65    
    66   const float x = 0.5f; 
    67   OUT.color = col1 * x + col2 * (1.0f - x); 
    68  
    69   return OUT; 
    70 } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2863 r2865  
    77 
    88// rule of thumb: approx 1 / NUM_SAMPLES 
    9 //#define SAMPLE_INTENSITY 0.2 
    10 #define SAMPLE_INTENSITY 0.125f 
     9#define SAMPLE_INTENSITY 0.17 
     10//#define SAMPLE_INTENSITY 0.125f 
    1111 
    1212#define AREA_SIZE 9e-1f 
    1313//#define VIEW_CORRECTION_SCALE 0.3f 
    14 #define VIEW_CORRECTION_SCALE 1.0f 
     14#define VIEW_CORRECTION_SCALE 0.5f 
    1515#define DISTANCE_SCALE 1e-6f 
    1616 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2851 r2865  
    7373                          uniform float4 diffuse) 
    7474{ 
    75   pixel pix; 
    76        
    77   pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 
    78   pix.pos = IN.worldPos * maxDepth; 
    79   pix.norm.xyz = IN.normal * 0.5f + 0.5f; 
     75        pixel pix; 
    8076 
    81   // hack: squeeze some information about ambient into the texture 
    82   pix.norm.w = ambient.x; 
    83   // hack: store projection coordinate for scaling ssao 
    84   pix.pos.w = IN.projPos.w; 
     77        pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 
     78        pix.pos = IN.worldPos * maxDepth; 
     79        pix.norm.xyz = IN.normal * 0.5f + 0.5f; 
    8580 
    86   if (pix.col.w < 0.5f) 
    87           discard; 
     81        // hack: squeeze some information about ambient into the texture 
     82        pix.norm.w = ambient.x; 
     83        // hack: store projection coordinate for scaling ssao 
     84        pix.pos.w = IN.projPos.w; 
    8885 
    89   pix.col.w = IN.mypos.z / IN.mypos.w; 
     86        // account for alpha blending 
     87        if (pix.col.w < 0.5f) 
     88                discard; 
    9089 
    91   return pix; 
     90        // write the depth 
     91        pix.col.w = IN.mypos.z / IN.mypos.w; 
     92 
     93        return pix; 
    9294} 
    9395 
     
    98100           uniform float4 diffuse) 
    99101{ 
    100   pixel pix; 
    101        
    102   pix.col = diffuse; 
    103   pix.pos = IN.worldPos * maxDepth; 
    104   pix.norm.xyz = IN.normal * 0.5f + float3(0.5f); 
    105   // hack: squeeze some information about ambient into the texture 
    106   pix.norm.w = ambient.x; 
    107   pix.pos.w = IN.mypos.w; 
    108   pix.col.w = IN.mypos.z / IN.mypos.w; 
     102        pixel pix; 
    109103 
    110   return pix; 
     104        pix.col = diffuse; 
     105        pix.pos = IN.worldPos * maxDepth; 
     106        pix.norm.xyz = IN.normal * 0.5f + float3(0.5f); 
     107        // hack: squeeze some information about ambient into the texture 
     108        pix.norm.w = ambient.x; 
     109        pix.pos.w = IN.mypos.w; 
     110        pix.col.w = IN.mypos.z / IN.mypos.w; 
     111 
     112        return pix; 
    111113} 
Note: See TracChangeset for help on using the changeset viewer.