Changeset 2952


Ignore:
Timestamp:
09/16/08 16:03:01 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
11 edited

Legend:

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

    r2945 r2952  
    1111camPosition=483.398f 242.364f 186.078f 
    1212camDirection=1 0 0 
     13lightDir=-0.8f 1.0f -0.7f 
    1314useFullScreen=0 
    1415useLODs=1 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r2946 r2952  
    88#include "Halton.h" 
    99#include "ShadowMapping.h" 
     10#include "Light.h" 
    1011 
    1112 
     
    9192static CGparameter sNoiseTexShadowParam; 
    9293static CGparameter sSamplesShadowParam;  
     94 
     95static CGparameter sLightDirParam; 
     96static CGparameter sLightDirShadowParam; 
    9397 
    9498 
     
    245249        if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram); 
    246250 
    247         //DEL_PTR(mNewFbo); 
    248         //DEL_PTR(mOldFbo); 
    249251        DEL_PTR(mFbo); 
    250252 
     
    277279                sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors");   
    278280                sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 
     281                sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 
    279282        } 
    280283        else 
     
    427430                sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture"); 
    428431                sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 
     432                sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 
    429433 
    430434                PoissonDiscSampleGenerator2 poisson(16, 1.0f); 
     
    444448                                                          const Matrix4x4 &projViewMatrix, 
    445449                                                          float tempCohFactor, 
     450                                                          DirectionalLight *light, 
    446451                                                          ShadowMap *shadowMap) 
    447452{ 
     
    477482 
    478483        if (shadowMap) 
    479                 FirstPassShadow(fbo, shadowMap); 
     484                FirstPassShadow(fbo, light, shadowMap); 
    480485        else 
    481                 FirstPass(fbo); 
     486                FirstPass(fbo, light); 
    482487 
    483488        switch (mShadingMethod) 
     
    691696 
    692697 
    693 void DeferredRenderer::FirstPass(FrameBufferObject *fbo) 
     698void DeferredRenderer::FirstPass(FrameBufferObject *fbo, DirectionalLight *light) 
    694699{ 
    695700        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
     
    717722        cgGLEnableTextureParameter(sNormalsTexDeferredParam); 
    718723         
     724        Vector3 lightDir = -light->GetDirection(); 
     725        cgGLSetParameter3f(sLightDirParam, lightDir.x, lightDir.y, lightDir.z); 
     726 
    719727        glColor3f(1.0f, 1.0f, 1.0f); 
    720728 
     
    952960 
    953961 
    954 void DeferredRenderer::FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap) 
     962void DeferredRenderer::FirstPassShadow(FrameBufferObject *fbo,  
     963                                                                           DirectionalLight *light,  
     964                                                                           ShadowMap *shadowMap) 
    955965{ 
    956966        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
     
    9951005        cgGLEnableTextureParameter(sNoiseTexShadowParam); 
    9961006 
     1007        Vector3 lightDir = -light->GetDirection(); 
     1008        cgGLSetParameter3f(sLightDirShadowParam, lightDir.x, lightDir.y, lightDir.z); 
     1009 
    9971010 
    9981011        glColor3f(1.0f, 1.0f, 1.0f); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r2944 r2952  
    1 #ifndef _DeferredRenderer_H__ 
    2 #define _DeferredRenderer_H__ 
     1#ifndef _DEFERREDRENDERER_H__ 
     2#define _DEFERREDRENDERER_H__ 
    33 
    44#include "common.h" 
     
    1717class Matrix4x4; 
    1818class ShadowMap; 
     19class DirectionalLight; 
    1920 
    2021 
     
    2930                         
    3031                The parameter scaleFactor must be reciprocal value of the  
    31                 scale factor used for creating the positions texture. It is used recover the  
     32                scale factor used for creating the world space position texture. It is used recover the  
    3233                exact scene size that was scaled in order to improve floating point precision. 
    3334        */ 
     
    4243                                const Matrix4x4 &projViewMatrix,  
    4344                                float tempCohFactor,  
     45                                DirectionalLight *light, 
    4446                                ShadowMap *shadowMap = NULL); 
    4547 
     
    6971        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix); 
    7072 
    71         void FirstPass(FrameBufferObject *fbo); 
     73        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light); 
    7274 
    73         void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap); 
     75        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap); 
    7476 
    7577        void CombineSsao(FrameBufferObject *fbo); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Light.h

    r2891 r2952  
    1212/** Class representing a directional light source 
    1313*/ 
    14 class Light 
     14class DirectionalLight 
    1515{ 
    1616public: 
    1717         
    18         Light(const Vector3 &dir, const RgbaColor &col): mDirection(dir), mColor(col) {} 
     18        DirectionalLight(const Vector3 &dir, const RgbaColor &col): mColor(col) { mDirection = Normalize(dir); } 
    1919 
    2020        Vector3 GetDirection() const { return mDirection; } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2951 r2952  
    137137 
    138138 
    139 ShadowMap::ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 
     139ShadowMap::ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 
    140140mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light) 
    141141{ 
     
    456456        const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 
    457457 
    458         //do Light Space Perspective shadow mapping 
     458        //do DirectionalLight Space Perspective shadow mapping 
    459459        //rotate the lightspace so that the projected light view always points upwards 
    460460        //calculate a frame matrix that uses the projViewDir[lightspace] as up vector 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2947 r2952  
    1919class Vector3; 
    2020class Camera; 
    21 class Light; 
     21class DirectionalLight; 
    2222 
    2323/** This class implements a the computation of single shadow map 
     
    3030                The shadow map has resolution size * size. 
    3131        */ 
    32         ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam); 
     32        ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam); 
    3333 
    3434        ~ShadowMap(); 
     
    115115        Matrix4x4 mTextureMatrix; 
    116116        /// the used light 
    117         Light *mLight; 
     117        DirectionalLight *mLight; 
    118118        /// the scene camera 
    119119        Camera *mCamera; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r2951 r2952  
    88 
    99CGparameter Transform3::sModelMatrixParam; 
     10 
    1011 
    1112Transform3::Transform3(Matrix4x4 *trafo): mMatrix(trafo) 
     
    2324{ 
    2425        if (!mMatrix) return; 
    25  
     26         
    2627        if (state->GetRenderType() == RenderState::DEFERRED) 
    2728        { 
    2829                cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix->x); 
    2930        } 
    30 //      else 
    31 //      { 
    32                 glPushMatrix(); 
    33                 glMultMatrixf((float *)mMatrix->x); 
    34 //      } 
     31 
     32        glPushMatrix(); 
     33        glMultMatrixf((float *)mMatrix->x); 
    3534} 
    3635 
     
    4544                cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); 
    4645        } 
    47 //      else 
    48 //      { 
    49                 glPopMatrix(); 
    50 //      } 
     46 
     47        glPopMatrix(); 
    5148} 
    5249 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h

    r2840 r2952  
    33 
    44#include "glInterface.h" 
     5#include "common.h" 
    56#include <Cg/cg.h> 
    67#include <Cg/cgGL.h> 
    7 #include "common.h" 
     8 
    89 
    910namespace CHCDemoEngine  
     
    3738        static CGparameter sModelMatrixParam; 
    3839 
    39  
    4040protected: 
    4141 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2951 r2952  
    184184 
    185185ShadowMap *shadowMap = NULL; 
    186 Light *light = NULL; 
     186DirectionalLight *light = NULL; 
    187187DeferredRenderer *ssaoShader = NULL; 
     188 
    188189 
    189190 
     
    242243static CGprogram sCgMrtVertexProgram = NULL; 
    243244 
    244 static CGparameter sModelViewProjMatrixParam; 
    245245static CGparameter sMaxDepthParam; 
    246246static CGparameter sMaxDepthParamTex; 
    247  
    248247static Matrix4x4 oldViewProjMatrix; 
    249248 
     
    284283        Vector3 camPos(.0f, .0f, .0f); 
    285284        Vector3 camDir(.0f, 1.0f, .0f); 
     285        Vector3 lightDir(-0.8f, 1.0f, -0.7f); 
    286286 
    287287        cout << "=== reading environment file ===" << endl << endl; 
     
    308308                env.GetVectorParam(string("camPosition"), camPos); 
    309309                env.GetVectorParam(string("camDirection"), camDir); 
     310                env.GetVectorParam(string("lightDirection"), lightDir); 
    310311 
    311312                env.GetBoolParam(string("useLODs"), useLODs); 
     
    345346 
    346347        visCamera = new Camera(winWidth, winHeight, fov); 
    347  
    348348        visCamera->SetNear(0.0f); 
    349349        visCamera->Yaw(.5 * M_PI); 
     350 
     351        // create a new light 
     352        light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1)); 
     353 
    350354 
    351355        renderQueue = new RenderQueue(&state, camera); 
     
    449453        sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
    450454 
    451         //Vector3 lightDir = Normalize(Vector3(0.2, -0.8, -1)); 
    452         Vector3 lightDir = Normalize(-Vector3(0.8f, -1.0f, 0.7f)); 
    453          
    454         light = new Light(lightDir, RgbaColor(1, 1, 1, 1)); 
    455  
    456  
    457455        // frame time is restarted every frame 
    458456        frameTimer.Start(); 
     
    495493                cgGLLoadProgram(sCgMrtVertexProgram); 
    496494 
    497                 Transform3::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelMatrix"); 
    498                 sModelViewProjMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj"); 
     495                //sInvViewProjParam = cgGetNamedParameter(sCgMrtVertexProgram, "InvViewProj"); 
     496                Transform3::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelView"); 
    499497        } 
    500498 
     
    757755        glLightfv(GL_LIGHT0, GL_SPECULAR, specular); 
    758756 
    759         GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f}; 
     757        Vector3 lightDir = -light->GetDirection(); 
     758        GLfloat position[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f}; 
    760759        glLightfv(GL_LIGHT0, GL_POSITION, position); 
    761760 
     
    802801        glMatrixMode(GL_PROJECTION); 
    803802        glLoadIdentity(); 
    804  
    805803        gluPerspective(fov, winAspectRatio, nearDist, farDist); 
    806804 
     
    823821        if ((renderType == RenderState::DEFERRED) || (renderType == RenderState::DEPTH_PASS_DEFERRED)) 
    824822        { 
    825                 // set modelview matrix for shaders 
    826                 cgGLSetStateMatrixParameter(sModelViewProjMatrixParam,  
    827                                                                         CG_GL_MODELVIEW_PROJECTION_MATRIX,  
    828                                                                         CG_GL_MATRIX_IDENTITY); 
    829  
    830                 static Matrix4x4 identity = IdentityMatrix(); 
    831                 cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)identity.x); 
    832         }                
     823                cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)IdentityMatrix().x); 
     824        } 
    833825} 
    834826 
     
    10121004 
    10131005        // set up lights 
    1014         GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f}; 
    1015         glLightfv(GL_LIGHT0, GL_POSITION, position); 
    1016  
    1017 #if 0 
    1018         GLfloat position1[] = {-0.5f, 0.5f, 0.4f, 0.0f}; 
    1019         glLightfv(GL_LIGHT1, GL_POSITION, position1); 
    1020 #endif 
     1006        Vector3 lightDir = -light->GetDirection(); 
     1007        GLfloat lightPos[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f}; 
     1008        glLightfv(GL_LIGHT0, GL_POSITION, lightPos); 
     1009 
     1010        // second light 
     1011        //GLfloat lightPos1[] = {-0.5f, 0.5f, 0.4f, 0.0f}; 
     1012        //glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); 
     1013 
    10211014 
    10221015        if (renderLightView) 
     
    10901083 
    10911084                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
    1092                 ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, sm); 
     1085                ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, sm); 
    10931086        } 
    10941087 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2945 r2952  
    3333                         uniform float4 position, 
    3434                         uniform float3 normal, 
    35                          uniform float amb) 
    36 { 
    37         const float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
    38         const float3 light = normalize(lightDir.xyz); 
    39         const float diffuseLight = saturate(dot(normal, light)); 
     35                         uniform float amb, 
     36                         float3 lightDir) 
     37{ 
     38        const float diffuseLight = saturate(dot(normal, lightDir)); 
    4039         
    4140        /* 
     
    6059                   uniform sampler2D colors, 
    6160                   uniform sampler2D positions, 
    62                    uniform sampler2D normals     
     61                   uniform sampler2D normals, 
     62                   uniform float3 lightDir 
    6363                   ) 
    6464{ 
     
    7474        float3 normal = normalize(norm.xyz); 
    7575 
    76         float4 col = shade(IN, color, position, normal, amb); 
     76        float4 col = shade(IN, color, position, normal, amb, lightDir); 
    7777         
    7878        //OUT.color = float4(1.0f); 
     
    8888                                         uniform float w, 
    8989                                         uniform float2 lightSpacePos, 
    90                                          float depth, 
     90                                         uniform float depth, 
    9191                                         uniform float2 samples[NUM_SAMPLES], 
    9292                                         uniform sampler2D noiseTexture 
     
    132132                                  uniform float4x4 shadowMatrix, 
    133133                                  uniform float maxDepth, 
    134                                   uniform float sampleWidth 
     134                                  uniform float sampleWidth, 
     135                                  uniform float3 lightDir 
    135136                                  ) 
    136137{ 
     
    219220                                  uniform float sampleWidth, 
    220221                                  uniform sampler2D noiseTexture, 
    221                                   uniform float2 samples[NUM_SAMPLES] 
     222                                  uniform float2 samples[NUM_SAMPLES], 
     223                                  uniform float3 lightDir 
    222224                                  ) 
    223225{ 
     
    229231         
    230232        const float3 normal = normalize(norm.xyz); 
    231         const float3 lightDir = normalize(float3(0.8f, -1.0f, 0.7f)); 
    232  
     233         
    233234        // hack: an emmisive color term 
    234235        float emmisive = norm.w; 
     
    240241        // calc diffuse illumination + shadow term 
    241242        if ((emmisive < 0.95f) // hack: prevent shadowing the sky        
    242                 && (angle > 1e-3f) 
     243                && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 
    243244                ) 
    244245        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2951 r2952  
    4848vtxout vtx(vtxin IN,  
    4949                   const uniform float4x4 ModelViewProj, 
    50                    uniform float4x4 ModelMatrix) 
     50                   uniform float4x4 ModelView) 
    5151{ 
    52    vtxout OUT; 
    53    
    54    // transform the vertex position into eye space 
    55    OUT.color = IN.color; 
     52        vtxout OUT; 
    5653 
    57    OUT.texCoord = IN.texCoord; 
    58    OUT.worldPos = mul(ModelMatrix, IN.position); 
     54        // transform the vertex position into eye space 
     55        OUT.color = IN.color; 
    5956 
    60    // transform the vertex position into eye space 
    61    //OUT.position = mul(ModelViewProj, OUT.worldPos); 
    62    OUT.position = mul(glstate.matrix.mvp, IN.position); 
     57        OUT.texCoord = IN.texCoord; 
    6358 
    64    OUT.normal = IN.normal; 
     59        // transform the vertex position into eye space 
     60        OUT.position = mul(glstate.matrix.mvp, IN.position); 
     61        //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); 
     62        OUT.worldPos = mul(ModelView, IN.position); 
    6563 
    66    OUT.mypos = OUT.position; 
     64        OUT.normal = IN.normal; 
    6765 
    68    return OUT; 
     66        OUT.mypos = OUT.position; 
     67 
     68        return OUT; 
    6969} 
    7070 
Note: See TracChangeset for help on using the changeset viewer.