Changeset 2887


Ignore:
Timestamp:
08/31/08 13:15:30 (16 years ago)
Author:
mattausch
Message:

made changes to view transformation but still not working

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

Legend:

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

    r2886 r2887  
    551551                                </File> 
    552552                                <File 
     553                                        RelativePath=".\src\Light.h" 
     554                                        > 
     555                                </File> 
     556                                <File 
    553557                                        RelativePath=".\src\LODInfo.h" 
    554558                                        > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r2868 r2887  
    1010winHeight=768 
    1111camPosition=483.398f 242.364f 186.078f 
    12 camDirection=1 0 0 
     12camDirection=-1 0 0 
    1313useFullScreen=0 
    1414useLODs=1 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2885 r2887  
    368368 
    369369        // store near plane 
    370         sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition()); 
     370        sNearPlane = Plane3(-mCamera->GetDirection(), mCamera->GetPosition()); 
    371371} 
    372372 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r2864 r2887  
    88 
    99using namespace std; 
     10 
     11// this is the start vector.  
     12// warning: our coordinate system has the negative z axis pointing up 
     13// which is different from the system used in opengl!! 
     14static Vector3 startVector = Vector3(0, 1, 0); 
    1015 
    1116 
     
    2025 
    2126        mPitch = mYaw = 0; 
    22         Precompute(Vector3(0, 1, 0)); 
     27        Precompute(startVector); 
     28 
     29        CalculateFromPitchAndYaw(); 
    2330} 
    2431 
     
    3643 
    3744        mPitch = mYaw = 0; 
    38         Precompute(Vector3(0, 1, 0)); 
     45        Precompute(startVector); 
     46 
     47        CalculateFromPitchAndYaw(); 
    3948} 
    4049 
     
    4958        mViewOrientation = mBaseOrientation; 
    5059} 
    51  
    5260 
    5361 
     
    173181        const float h_far = w_far / GetAspect(); 
    174182 
    175         const Vector3 view = GetDirection(); 
     183        const Vector3 view = -GetDirection(); 
    176184        const Vector3 fc = mPosition + view * z_far;  
    177185         
     
    225233        Normalize(dir); 
    226234 
    227         mPitch = atan2(dir.x, dir.z); 
    228         mYaw = atan2(dir.y, sqrt((dir.x * dir.x) + (dir.z * dir.z))); 
     235        //mPitch = atan2(dir.x, dir.z); 
     236        //mYaw = atan2(dir.y, sqrt((dir.x * dir.x) + (dir.z * dir.z))); 
     237 
     238        mPitch = -atan2(dir.x, dir.y); 
     239        mYaw = atan2(dir.z, sqrt((dir.x * dir.x) + (dir.y * dir.y))); 
    229240 
    230241        CalculateFromPitchAndYaw(); 
     
    246257Vector3 Camera::GetDirection() const 
    247258{  
    248         return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 
     259        return Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]); 
    249260} 
    250261 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2879 r2887  
    55#include "SceneQuery.h" 
    66#include "RenderTraverser.h" 
     7#include "FrameBufferObject.h" 
     8 
    79#include <IL/il.h> 
    810#include <assert.h> 
    9 #include "FrameBufferObject.h" 
     11 
    1012 
    1113 
     
    3335 
    3436 
    35 void startil() 
     37static void startil() 
    3638{ 
    3739        ilInit(); 
     
    4042 
    4143 
    42 void stopil() 
     44static void stopil() 
    4345{ 
    4446        ilShutDown(); 
     
    5153 
    5254 
    53 //void GrabDepthBuffer(float *data, RenderTexture *rt) 
    54 void GrabDepthBuffer(float *data, GLuint depthTexture) 
     55static void GrabDepthBuffer(float *data, GLuint depthTexture) 
    5556{ 
    5657        glEnable(GL_TEXTURE_2D); 
     
    6465 
    6566 
    66 void ExportDepthBuffer(float *data) 
     67static void ExportDepthBuffer(float *data) 
    6768{ 
    6869        startil(); 
     
    9293 
    9394 
    94 SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer):  
     95SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox,  
     96                                           RenderTraverser *renderer):  
    9597mSceneBox(sceneBox), mDepth(NULL) 
    9698{ 
     
    135137 
    136138        orthoCam->SetNear(0.0f); 
    137         orthoCam->Yaw(M_PI * 0.5f); 
    138  
     139        orthoCam->SetDirection(Vector3(0, 0, 1)); 
     140 
     141        cout << orthoCam->GetDirection() << endl; 
    139142        Vector3 pos = Vector3(mSceneBox.Center().x, mSceneBox.Center().y, mSceneBox.Max().z); 
    140143        orthoCam->SetPosition(pos); 
     
    147150 
    148151        glDrawBuffers(1, mrt); 
    149          
     152 
     153        glPushAttrib(GL_VIEWPORT_BIT); 
    150154        glViewport(0, 0, texWidth, texHeight); 
    151         glPushAttrib(GL_VIEWPORT_BIT); 
    152155 
    153156        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     
    186189 
    187190        GrabDepthBuffer(mDepth, fbo->GetDepthTex()); 
    188         //ExportDepthBuffer(mDepth); PrintGLerror("grab"); 
     191        ExportDepthBuffer(mDepth); PrintGLerror("grab"); 
    189192 
    190193        DEL_PTR(fbo); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp

    r2886 r2887  
    104104/** Generate poisson disc distributed sample points on the unit disc 
    105105*/ 
    106 static void GenerateSamples() 
    107 { 
    108 #if 0 
    109         static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 
    110         poisson.Generate((Sample2 *)samples); 
    111 #else 
    112          
    113         const float radius = 1.0f; 
    114         const float sigma = ComputeSigmaFromRadius(1.0f); 
    115          
    116         static HaltonSequence halton; 
    117  
    118         for (int i = 0; i < NUM_SAMPLES; ++ i) 
    119         { 
    120                 Sample2 s; 
    121                 Vector3 input; 
    122  
    123                 halton.GetNext(3, (float *)&input.x); 
    124  
    125                 PolarGaussianOnDisk(input,  // input (RND in interval [0-1)x[0-1)) 
    126                                                     sigma,  // standard deviation of gaussian distribution 
    127                                                         radius, // standard deviation of gaussian distribution 
    128                                                         s);     // result 
    129                 samples[i] = s; 
    130         } 
    131 #endif 
     106static void GenerateSamples(int sampling) 
     107{ 
     108        switch (sampling) 
     109        { 
     110        case SsaoShader::POISSON: 
     111                { 
     112                        static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 
     113                        poisson.Generate((Sample2 *)samples); 
     114                } 
     115                break; 
     116        case SsaoShader::GAUSS: 
     117                { 
     118                        const float radius = 1.0f; 
     119                        const float sigma = 0.25f;//ComputeSigmaFromRadius(1.0f); 
     120 
     121                        static HaltonSequence halton; 
     122 
     123                        for (int i = 0; i < NUM_SAMPLES; ++ i) 
     124                        { 
     125                                Sample2 s; 
     126                                Vector3 input; 
     127 
     128                                halton.GetNext(3, (float *)&input.x); 
     129 
     130                                //GaussianOn2D(cinput, // input (RND in interval [0-1)x[0-1)) 
     131                                //               sigma,            // standard deviation of gaussian distribution 
     132                                //                       outputVec)   // resulting vector according to gaussian distr. 
     133 
     134                                PolarGaussianOnDisk(input,  // input (RND in interval [0-1)x[0-1)) 
     135                                        sigma,  // standard deviation of gaussian distribution 
     136                                        radius, // standard deviation of gaussian distribution 
     137                                        s);     // result 
     138                                samples[i] = s; 
     139                        } 
     140                } 
     141                break; 
     142        default: 
     143                break; 
     144        } 
    132145} 
    133146 
     
    179192mScaleFactor(scaleFactor), 
    180193mUseTemporalCoherence(true), 
    181 mUseGlobIllum(false) 
     194mUseGlobIllum(false), 
     195mSampling(POISSON) 
    182196{ 
    183197        // create noise texture for ssao 
     
    286300 
    287301                // generate samples for ssao kernel 
    288                 GenerateSamples();  
     302                //GenerateSamples(mSampling);  
    289303 
    290304                sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples"); 
     
    292306                //cgCompileProgram(sCgSsaoProgram); 
    293307                 
    294                 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
     308                //cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
    295309        } 
    296310        else 
     
    326340 
    327341                // generate samples for ssao kernel 
    328                 GenerateSamples();  
    329                 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 
     342                //GenerateSamples();  
     343                //cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 
    330344 
    331345                cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f)); 
     
    515529                // in the first case, the sample patterns look nicer, but the kernel 
    516530                // needs longer to converge 
    517                 GenerateSamples();  
     531                GenerateSamples(mSampling);  
    518532                cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
    519533        } 
     
    755769                // in the first case, the sample patterns look nicer, but the kernel 
    756770                // needs longer to converge 
    757                 GenerateSamples();  
     771                GenerateSamples(mSampling);  
    758772                cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 
    759773        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h

    r2886 r2887  
    4747        void SetUseTemporalCoherence(bool temporal); 
    4848 
     49        enum SAMPLING_METHOD {POISSON, GAUSS}; 
     50 
     51        void SetSamplingMethod(int s) { mSampling = s;} 
     52 
    4953 
    5054protected: 
     
    8084        bool mUseGlobIllum; 
    8185        bool mUseTemporalCoherence; 
     86 
     87        int mSampling; 
    8288}; 
    8389 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2884 r2887  
    3535#include "SsaoShader.h" 
    3636#include "DeferredShader.h" 
     37#include "ShadowMapping.h" 
     38#include "Light.h" 
    3739 
    3840 
     
    170172bool useLODs = true; 
    171173 
     174int samplingMethod = SsaoShader::POISSON; 
    172175 
    173176static Matrix4x4 matProjectionView = IdentityMatrix(); 
    174177 
    175  
     178ShadowMapping *shadowMapping = NULL; 
     179Light *light = NULL; 
    176180 
    177181// function forward declarations 
     
    213217 
    214218 
     219 
    215220inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 
    216221inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 
     
    326331        camera->SetNear(nearDist); 
    327332         
     333        cout << "here2 " << Normalize(camDir) << endl; 
     334 
    328335        camera->SetDirection(camDir); 
     336        cout << "here3 " << camera->GetDirection() << endl; 
    329337        camera->SetPosition(camPos); 
    330338 
     
    425433        DeferredShader::Init(sCgContext); 
    426434        SsaoShader::Init(sCgContext); 
     435        ShadowMapping::Init(sCgContext); 
    427436 
    428437        //deferredShader = new DeferredShader(texWidth, texHeight); 
    429438        //ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
    430439 
     440 
    431441        // initialize the render traverser 
    432442        ResetTraverser(); 
     
    435445 
    436446        sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
     447 
     448        light = new Light(Vector3(0, 0, -1), RgbaColor(1, 1, 1, 1)); 
     449 
     450        shadowMapping = new ShadowMapping(bvh->GetBox(), 512); 
     451        shadowMapping->ComputeShadowMap(light, traverser); 
    437452 
    438453        // frame time is restarted every frame 
     
    845860                camera->Pitch(-KeyRotationAngle()); 
    846861        if (upKeyPressed) 
     862                KeyHorizontalMotion(-KeyShift()); 
     863        if (downKeyPressed) 
    847864                KeyHorizontalMotion(KeyShift()); 
    848         if (downKeyPressed) 
    849                 KeyHorizontalMotion(-KeyShift()); 
    850865        if (ascendKeyPressed) 
    851866                KeyVerticalMotion(KeyShift()); 
     
    862877        } 
    863878         
     879         
     880        //shadowMapping->ComputeShadowMap(light, traverser); 
     881 
     882 
     883 
    864884        // render without shading 
    865885        switch (renderType) 
     
    10981118                SceneEntity::SetUseLODs(useLODs); 
    10991119                break; 
     1120        case 'P': 
     1121        case 'p': 
     1122                if (samplingMethod == SsaoShader::GAUSS) 
     1123                        samplingMethod = SsaoShader::POISSON; 
     1124                else 
     1125                        samplingMethod = SsaoShader::GAUSS; 
     1126 
     1127                ssaoShader->SetSamplingMethod(samplingMethod); 
     1128 
     1129                break; 
    11001130        case 'g': 
    11011131        case 'G': 
     
    13451375        camera->Pitch(eyeXAngle); 
    13461376 
    1347         pos += horView * (yMotionBegin - y) * 0.2f; 
     1377        pos -= horView * (yMotionBegin - y) * 0.2f; 
    13481378         
    13491379        camera->SetPosition(pos); 
     
    13871417        rVec = rot * rVec; 
    13881418         
    1389         pos -= rVec * (x - horizontalMotionBegin) * 0.1f; 
     1419        pos += rVec * (x - horizontalMotionBegin) * 0.1f; 
    13901420        pos[2] += (verticalMotionBegin - y) * 0.1f; 
    13911421 
     
    14961526        glMultMatrixf((float *)rotZ.x); 
    14971527 
     1528        // inverse translation in order to fix current position 
    14981529        Vector3 pos = camera->GetPosition(); 
    14991530        glTranslatef(-pos.x, -pos.y, -pos.z); 
     
    15081539        glClear(GL_DEPTH_BUFFER_BIT); 
    15091540 
    1510  
    15111541        //////////// 
    15121542        //-- visualization of the occlusion culling 
    15131543 
    15141544        visualization->Render(); 
    1515          
     1545 
     1546        glColor3f(0.0f, 1.0f, 0.0f); 
     1547        glBegin(GL_LINES); 
     1548        glVertex3d(pos.x, pos.y, pos.z); 
     1549        glVertex3d(pos.x + 100, pos.y, pos.z); 
     1550        glEnd(); 
     1551 
     1552        glColor3f(0.0f, 0.0f, 1.0f); 
     1553        glBegin(GL_LINES); 
     1554        glVertex3d(pos.x, pos.y, pos.z); 
     1555        glVertex3d(pos.x, pos.y + 100, pos.z); 
     1556        glEnd(); 
    15161557         
    15171558        // reset previous settings 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r2886 r2887  
    22#define __SHADERENV_H 
    33 
    4 #define NUM_SAMPLES 8 
    5 //#define NUM_SAMPLES 16 
     4//#define NUM_SAMPLES 8 
     5#define NUM_SAMPLES 16 
    66 
    77// rule of thumb: approx 1 / NUM_SAMPLES 
    8 //#define SAMPLE_INTENSITY 0.15f 
    9 #define SAMPLE_INTENSITY 0.25f 
     8#define SAMPLE_INTENSITY 0.14f 
     9//#define SAMPLE_INTENSITY 0.28f 
    1010 
    1111#define AREA_SIZE 5e-1f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg

    r2884 r2887  
    8484        float4 s3 = tex2Dlod(colors, float4(offset + IN.lb.xy * w, 0, 0)); 
    8585 
    86         float4 sx = tex2D(colors, IN.c.xy); 
    87  
    88         //return (sx + sx) * 0.5f; 
     86        //float4 sx = tex2D(colors, IN.c.xy); 
    8987 
    9088        return (s0 + s1 + s2 + s3) * 0.25f; 
    91         //return (s0 + s1 + s2 + s3) * 0.25f; 
    92  
    9389        //return float4(w); 
    9490} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2884 r2887  
    2424{ 
    2525        float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
     26        //float4 lightDir = float4(0.0f, 1.0f, 0.0f, 0.0f); 
    2627        float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 
    2728 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2884 r2887  
    9696 
    9797                // if normal perpenticular to view dir, only half of the samples count 
    98                 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
    99  
    100                 total_color.w -= cos_angle * distance_intensity * view_correction; 
    101  
    102                 total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 
     98                //const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
     99                //total_color.w -= cos_angle * distance_intensity * view_correction; 
     100                //total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 
     101 
     102                total_color.w -= cos_angle * distance_intensity; 
     103                total_color.xyz += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; 
    103104        } 
    104105 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2886 r2887  
    8888                // if surface normal perpenticular to view dir, approx. half of the samples will not count 
    8989                // => compensate for this (on the other hand, projected sampling area could be larger!) 
    90                 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
     90                //const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
     91                //total_ao += cos_angle * distance_intensity * view_correction; 
    9192 
    92                 total_ao += cos_angle * distance_intensity * view_correction; 
     93                total_ao += cos_angle * distance_intensity; 
    9394        } 
    9495 
    95         return max(0.0f, 1.0f - total_ao); 
     96        //return max(0.0f, 1.0f - total_ao); 
     97        return saturate(dot(currentViewDir, currentNormal)); 
    9698} 
    9799 
     
    178180        float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 
    179181 
    180         OUT.illum_col = col * ao.x; 
    181         //OUT.illum_col = ao; 
     182        //OUT.illum_col = col * ao.x; 
     183        OUT.illum_col = ao; 
     184 
    182185        OUT.illum_col.w = ao.w; 
    183186 
Note: See TracChangeset for help on using the changeset viewer.