Ignore:
Timestamp:
10/19/08 23:42:15 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h

    r2986 r3045  
    4242{ 
    4343        friend class ShadowMap; 
     44 
    4445public: 
    4546         
     
    7677        */ 
    7778        void GetModelViewMatrix(Matrix4x4 &mat) const; 
    78  
     79        /** Returns the view orientation (the model view matrix without the translation) 
     80        */ 
    7981        void GetViewOrientationMatrix(Matrix4x4 &mat) const; 
    8082        /** Calculates a frustum from the projection and the modelview matrix. 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp

    r3042 r3045  
    44#include "glInterface.h" 
    55#include "RenderState.h" 
    6 #include "ShaderProgram.h" 
     6 
    77 
    88using namespace std; 
     
    2424        mCullFaceEnabled = true; 
    2525         
    26         mGPUVertexParameters = NULL; 
     26        mVertexProgramParameters.Reset(); 
     27        mFragmentProgramParameters.Reset(); 
     28         
    2729        mVertexProgram = NULL; 
    28          
    29         mGPUFragmentParameters = NULL; 
    3030        mFragmentProgram = NULL; 
    3131} 
     
    4242 
    4343 
    44 Technique::~Technique() 
    45 { 
    46         //DEL_PTR(mGPUFragmentParameters); 
    47         //DEL_PTR(mGPUVertexParameters); 
    48 } 
    49  
    50  
    5144Technique::Technique(const RgbaColor &color): 
    5245mDiffuseColor(color), 
     
    5649{ 
    5750        InitMaterial(); 
     51} 
     52 
     53 
     54Technique::Technique(const Technique &tech) 
     55{ 
     56        mAmbientColor = tech.mAmbientColor; 
     57        mDiffuseColor = tech.mDiffuseColor; 
     58        mSpecularColor = tech.mSpecularColor; 
     59        mEmmisiveColor = tech.mEmmisiveColor; 
     60 
     61        mVertexProgram = tech.mVertexProgram; 
     62        mFragmentProgram = tech.mFragmentProgram; 
     63 
     64        mAlphaTestEnabled = tech.mAlphaTestEnabled; 
     65        mCullFaceEnabled =tech.mCullFaceEnabled; 
     66 
     67        mTexture = tech.mTexture; 
     68 
     69        mVertexProgramParameters = tech.mVertexProgramParameters; 
     70        mFragmentProgramParameters = tech.mFragmentProgramParameters; 
     71} 
     72 
     73 
     74Technique::~Technique() 
     75{ 
    5876} 
    5977 
     
    7492        mFragmentProgram = p;  
    7593 
    76         mGPUFragmentParameters->Reset(); 
    77         mGPUFragmentParameters->SetProgram(p); 
     94        mFragmentProgramParameters.Reset(); 
     95        mFragmentProgramParameters.SetProgram(p); 
    7896} 
    7997         
     
    83101        mVertexProgram = p;  
    84102 
    85         mGPUVertexParameters->Reset(); 
    86         mGPUVertexParameters->SetProgram(p); 
     103        mVertexProgramParameters.Reset(); 
     104        mVertexProgramParameters.SetProgram(p); 
    87105} 
     106 
     107 
     108/***********************************************/ 
     109/*        class Material implementation        */ 
     110/***********************************************/ 
    88111 
    89112 
    90113void Material::Render(RenderState *state) 
    91114{ 
    92         mTechniques[0]->Render(state); 
     115        if (state->GetRenderPassType() == RenderState::DEFERRED) 
     116                mTechniques[1]->Render(state); 
     117        else 
     118                mTechniques[0]->Render(state); 
    93119} 
    94120 
     
    126152 
    127153 
     154void Material::AddTechnique(Technique *tech) 
     155{ 
     156        mTechniques.push_back(tech); 
    128157} 
     158 
     159 
     160} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h

    r3042 r3045  
    44#include "glInterface.h" 
    55#include "common.h" 
     6#include "ShaderProgram.h" 
    67 
    78 
     
    2223public: 
    2324 
    24         float r, g, b, a; 
    25  
    2625        RgbaColor(): r(1), g(1), b(1), a(1) 
    2726        {} 
     
    3130 
    3231        friend RgbaColor RandomColor(float a = 0.0f, float b = 1.0f); 
     32 
     33 
     34        ///////////////////// 
     35 
     36        float r, g, b, a; 
    3337}; 
    3438 
     
    5054        */ 
    5155        Technique(); 
     56 
     57        Technique(const Technique &tech); 
    5258 
    5359        ~Technique(); 
     
    8894        ShaderProgram *GetVertexProgram() { return mVertexProgram; } 
    8995 
    90         void SetFragmentProgramParameters(GPUProgramParameters *p) { mGPUFragmentParameters = p; } 
    91         void SetVertexProgramParameters(GPUProgramParameters *p) { mGPUVertexParameters = p; } 
     96        //void SetFragmentProgramParameters(const GPUProgramParameters &p) { mGPUFragmentParameters = p; } 
     97        //void SetVertexProgramParameters(const GPUProgramParameters &p) { mGPUVertexParameters = p; } 
    9298 
    93         GPUProgramParameters *GetFragmentProgramParameters() { return mGPUFragmentParameters; } 
    94         GPUProgramParameters *GetVertexProgramParameters() { return mGPUVertexParameters; } 
     99        /** Each technique has a distict set of parameters. 
     100        */ 
     101        GPUProgramParameters * const GetFragmentProgramParameters() { return &mFragmentProgramParameters; } 
     102        GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; } 
    95103 
    96104 
     
    109117        Texture *mTexture; 
    110118 
    111         GPUProgramParameters *mGPUVertexParameters; 
    112         GPUProgramParameters *mGPUFragmentParameters; 
     119        GPUProgramParameters mVertexProgramParameters; 
     120        GPUProgramParameters mFragmentProgramParameters; 
    113121 
    114122        ShaderProgram *mFragmentProgram; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3042 r3045  
    165165                        { 
    166166                                Shape *shape = *it; 
     167 
    167168                                Material *mat = shape->GetMaterial(); 
    168                                 Technique *tech = mat->GetDefaultTechnique(); 
    169                                  
    170                                 tech->SetVertexProgram(sTreeAnimation); 
    171  
    172                                 GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters(); 
    173  
    174                                 vtxParams->SetTimerParam(0); 
    175                                 // wind direction 
    176                                 static Vector3 windDir = Normalize(Vector3(0.8f, 0.2f, 0.0f)); 
    177                                 vtxParams->SetValue3f(1, windDir.x, windDir.y, windDir.z); 
    178                                 // amplitude 
    179                                 vtxParams->SetValue1f(2, 0.3f); 
    180  
    181                                 AxisAlignedBox3 box = sceneGeom->GetBoundingBox(); 
    182                                 vtxParams->SetValue2f(3, box.Min().z, box.Max().z); 
    183                                 // frequency 
    184                                 vtxParams->SetValue1f(4, 0.1f); 
     169 
     170                                // add the vertex animation program 
     171                                for (int i = 0; i < 2; ++ i) 
     172                                { 
     173                                        Technique *tech = mat->GetTechnique(i); 
     174                                        tech->SetVertexProgram(sTreeAnimation); 
     175 
     176                                        GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters(); 
     177 
     178                                        vtxParams->SetTimerParam(0); 
     179                                        // wind direction 
     180                                        static Vector3 windDir = Normalize(Vector3(0.8f, 0.2f, 0.0f)); 
     181                                        vtxParams->SetValue3f(1, windDir.x, windDir.y, windDir.z); 
     182                                        // amplitude 
     183                                        vtxParams->SetValue1f(2, 0.3f); 
     184 
     185                                        AxisAlignedBox3 box = sceneGeom->GetBoundingBox(); 
     186                                        vtxParams->SetValue2f(3, box.Min().z, box.Max().z); 
     187                                        // frequency 
     188                                        vtxParams->SetValue1f(4, 0.1f); 
     189                                } 
    185190                        } 
    186191                } 
     
    279284        } 
    280285 
    281         if (tech->GetTexture()) 
    282         { 
    283                 tech->mFragmentProgram = mMrtDefaultFragmentTexProgram; 
    284  
    285                 tech->mGPUFragmentParameters = CreateGPUProgramParameters(tech->mFragmentProgram); 
    286                 tech->mGPUFragmentParameters->SetTexture(0, tech->GetTexture()->GetId()); 
     286 
     287        /////////////// 
     288        //-- add technique for deferred shading 
     289 
     290        Technique *deferred = new Technique(*tech); 
     291 
     292        if (deferred->GetTexture()) 
     293        { 
     294                deferred->SetFragmentProgram(mMrtDefaultFragmentTexProgram); 
     295                deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 
     296                deferred->GetFragmentProgramParameters()->SetTexture(1, tech->GetTexture()->GetId()); 
    287297        }        
    288298        else 
    289299        { 
    290                 tech->mFragmentProgram = mMrtDefaultFragmentProgram; 
    291                 tech->mGPUFragmentParameters = CreateGPUProgramParameters(tech->mFragmentProgram); 
    292         } 
    293  
    294         tech->mVertexProgram = mMrtDefaultVertexProgram; 
    295         tech->mGPUVertexParameters = CreateGPUProgramParameters(tech->mVertexProgram); 
    296          
     300                deferred->SetFragmentProgram(mMrtDefaultFragmentProgram); 
     301                deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 
     302        } 
     303 
     304        deferred->SetVertexProgram(mMrtDefaultVertexProgram); 
     305         
     306        mat->AddTechnique(deferred); 
     307 
    297308        return mat; 
    298309} 
     
    393404 
    394405 
    395 GPUProgramParameters *ResourceManager::CreateGPUProgramParameters(ShaderProgram *p) 
    396 { 
    397         GPUProgramParameters *gpuParams = new GPUProgramParameters(p); 
    398         mGPUParameters.push_back(gpuParams); 
    399  
    400         return gpuParams; 
    401 } 
    402  
    403  
    404 ShaderProgram *ResourceManager::CreateFragmentProgram(const std::string &filename, const std::string &funcName) 
     406 
     407ShaderProgram *ResourceManager::CreateFragmentProgram(const std::string &filename,  
     408                                                                                                          const std::string &funcName) 
    405409{ 
    406410        const string fullName = "src/shaders/" + filename + ".cg"; 
     
    460464        mMrtDefaultFragmentProgram = CreateFragmentProgram("mrt", "frag"); 
    461465        mMrtDefaultFragmentTexProgram = CreateFragmentProgram("mrt", "fragtex"); 
    462         mMrtDefaultFragmentTexProgram->AddParameter("tex", 0); 
    463  
    464         sTreeAnimation = CreateVertexProgram("treeanimation", "animateVtx"); 
     466 
     467        // provide the current view matrix 
     468        mMrtDefaultFragmentProgram->AddParameter("viewMatrix", 0); 
     469        mMrtDefaultFragmentTexProgram->AddParameter("viewMatrix", 0); 
     470 
     471        // add a texture parameter 
     472        mMrtDefaultFragmentTexProgram->AddParameter("tex", 1); 
     473 
     474        sTreeAnimation = CreateVertexProgram("treeanimation", "animateVtxMrt"); 
    465475 
    466476        sTreeAnimation->AddParameter("timer", 0); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h

    r3038 r3045  
    2424class Transform3; 
    2525class ShaderProgram; 
    26 class GPUProgramParameters; 
    2726 
    2827 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp

    r3043 r3045  
    22#include "Matrix4x4.h" 
    33#include "Timer/PerfTimer.h" 
     4#include "Vector3.h" 
     5#include "Camera.h" 
    46 
    57 
     
    911{  
    1012 
     13////////// 
     14//-- changing shader parameters 
    1115static float sCurrentTimer = 0; 
    12  
    13  
    14 GPUProgramParameters::GPUProgramParameters(ShaderProgram *p) 
    15 : mProgram(p), mTimer(-1) 
     16static Matrix4x4 sCurrentViewMatrix = IdentityMatrix(); 
     17static Vector3 sCurrentViewVector = Vector3::UNIT_Y(); 
     18 
     19 
     20GPUProgramParameters::GPUProgramParameters(ShaderProgram *p):  
     21mProgram(p),  
     22mTimerParam(-1), 
     23mViewVectorParam(-1), 
     24mViewMatrixParam(-1) 
     25{ 
     26} 
     27 
     28 
     29GPUProgramParameters::GPUProgramParameters():  
     30mProgram(NULL), 
     31mTimerParam(-1), 
     32mViewVectorParam(-1), 
     33mViewMatrixParam(-1) 
    1634{ 
    1735} 
     
    2543        mArrays.clear(); 
    2644 
    27         mTimer = -1; 
     45        mTimerParam = -1; 
     46        mViewVectorParam = -1; 
     47        mViewMatrixParam = -1; 
    2848} 
    2949 
     
    107127void GPUProgramParameters::SetTimerParam(int idx) 
    108128{ 
    109         mTimer = idx; 
     129        mTimerParam = idx; 
     130} 
     131 
     132 
     133void GPUProgramParameters::SetViewMatrixParam(int idx) 
     134{ 
     135        mViewMatrixParam = idx; 
     136} 
     137 
     138 
     139void GPUProgramParameters::SetViewVectorParam(int idx) 
     140{ 
     141        mViewVectorParam = idx; 
    110142} 
    111143 
     
    161193void GPUProgramParameters::UpdateParameters() 
    162194{ 
     195        if (!mProgram) return; 
     196 
    163197        for (int i = 0; i < (int)mFloats.size(); ++ i) 
    164198        { 
     
    221255        } 
    222256 
    223         if (mTimer >= 0) 
    224         { 
    225                 static PerfTimer mytimer; 
    226                 mProgram->SetValue1f(mTimer, sCurrentTimer); 
    227         } 
    228 } 
    229  
    230  
    231 void GPUProgramParameters::InitFrame() 
     257        if (mTimerParam >= 0) 
     258                mProgram->SetValue1f(mTimerParam, sCurrentTimer); 
     259 
     260        if (mViewVectorParam >= 0) 
     261                mProgram->SetValue3f(mViewVectorParam, sCurrentViewVector.x, sCurrentViewVector.y, sCurrentViewVector.z); 
     262 
     263        if (mViewMatrixParam >= 0) 
     264                mProgram->SetMatrix(mViewMatrixParam, sCurrentViewMatrix); 
     265} 
     266 
     267 
     268void GPUProgramParameters::InitFrame(Camera *cam) 
    232269{ 
    233270        static PerfTimer mytimer; 
    234271        sCurrentTimer = mytimer.Elapsedms(false) * M_PI / 180.0f; 
     272 
     273        cam->GetModelViewMatrix(sCurrentViewMatrix); 
     274        sCurrentViewVector = cam->GetDirection(); 
    235275} 
    236276 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h

    r3043 r3045  
    3232{ 
    3333public: 
     34        /** Default construction. 
     35        */ 
     36        GPUProgramParameters(); 
    3437 
    3538        /** Constructor which initialized this parameter set for a given program. 
     
    5457        void SetArray3f(int idx, float *vals, int numElements); 
    5558 
    56         void SetTimerParam(int idx); 
    57  
    5859        /** Sets the texture parameter. 
    5960        */ 
     
    6364        void SetMatrix(int idx, Matrix4x4 *mat); 
    6465 
     66        //////////// 
     67        //-- The following parameters are updated and set automatically once per frame. 
     68 
     69        /** This parameter is connected to a timer that is updated once per frame. 
     70        */ 
     71        void SetTimerParam(int idx); 
     72        /** This parameter is connected to the current view matrix that is updated 
     73                once per frame. 
     74        */ 
     75        void SetViewMatrixParam(int idx); 
     76        /** This parameter is connected to the current view vector that is updated 
     77                once per frame. 
     78        */ 
     79        void SetViewVectorParam(int idx); 
     80 
     81         
    6582 
    6683        /////////// 
     
    84101        */ 
    85102        void UpdateParameters(); 
    86  
    87  
    88         static void InitFrame(); 
     103        /** Function should be called once per frame to update frame related parameters. 
     104        */ 
     105        static void InitFrame(Camera *cam); 
     106 
    89107 
    90108protected: 
     
    142160        }; 
    143161 
    144  
     162        /// the program this parameter set is connected to 
    145163        ShaderProgram *mProgram; 
    146164 
    147         int mTimer; 
     165        int mTimerParam; 
     166        int mViewVectorParam; 
     167        int mViewMatrixParam; 
     168 
    148169        std::vector<FloatParam> mFloats; 
    149170        std::vector<IntParam> mTextures; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r3043 r3045  
    8080        Material *mat = shape->GetMaterial(); 
    8181 
    82         mat->GetDefaultTechnique()->SetFragmentProgram(mSkyFragProgram); 
    83         mat->GetDefaultTechnique()->SetVertexProgram(mSkyVtxProgram); 
     82        mat->GetTechnique(0)->SetFragmentProgram(mSkyFragProgram); 
     83        mat->GetTechnique(0)->SetVertexProgram(mSkyVtxProgram); 
     84 
     85        mat->GetTechnique(1)->SetFragmentProgram(mSkyFragProgram); 
     86        mat->GetTechnique(1)->SetVertexProgram(mSkyVtxProgram); 
    8487} 
    8588 
     
    115118         
    116119        Material *mat = mSkyDome->GetShape(0)->GetMaterial(); 
    117         Technique *tech = mat->GetDefaultTechnique(); 
     120 
     121        Technique *tech; 
     122 
     123        if (state->GetRenderPassType() == RenderState::DEFERRED) 
     124                tech = mat->GetTechnique(1); 
     125        else 
     126                tech = mat->GetTechnique(0); 
    118127 
    119128        GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters(); 
     
    140149                vtxParams->SetValue1f(8, 8e-5f); 
    141150        } 
    142 /* 
    143         tech->GetVertexProgramParameters()->UpdateParameters(); 
    144         tech->GetVertexProgram()->Bind(); 
    145  
    146         tech->GetFragmentProgramParameters()->UpdateParameters(); 
    147         tech->GetFragmentProgram()->Bind(); 
    148 */ 
     151 
    149152        // render sky dome 
    150153        mSkyDome->Render(state); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3044 r3045  
    868868        } 
    869869         
    870         GPUProgramParameters::InitFrame(); 
    871  
    872870 
    873871        if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView)) 
     
    883881        // bring eye modelview matrix up-to-date 
    884882        SetupEyeView(); 
     883 
     884        // set GPU related parameters 
     885        GPUProgramParameters::InitFrame(camera); 
     886 
    885887 
    886888        // hack 
     
    18571859void RenderSky() 
    18581860{ 
    1859         //loader->EnableVertexProfile(); 
    1860         //loader->EnableFragmentProfile(); 
    1861  
    18621861        if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 
    18631862                state.SetRenderPassType(RenderState::DEFERRED); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3041 r3045  
    33{ 
    44  float4 position: POSITION; 
    5   float3 normal: NORMAL; 
     5  float4 normal: NORMAL; 
    66  float4 color: COLOR0; 
    77  float4 texCoord: TEXCOORD0; 
     
    1717        float4 color: COLOR0;   
    1818        float4 eyePos: TEXCOORD1; // eye position 
    19         float3 normal: TEXCOORD2; 
     19        float4 normal: TEXCOORD2; 
    2020}; 
    2121 
     
    3030        float4 winPos: WPOS; 
    3131        float4 eyePos: TEXCOORD1; // eye position 
    32         float3 normal: TEXCOORD2; 
     32        float4 normal: TEXCOORD2; 
    3333}; 
    3434 
     
    5656        OUT.position = mul(glstate.matrix.mvp, IN.position); 
    5757 
    58         OUT.normal = IN.normal; 
     58        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
    5959 
    6060        return OUT; 
     
    6363 
    6464pixel fragtex(fragin IN,  
    65                           uniform sampler2D tex 
     65                          uniform sampler2D tex, 
     66                          uniform float4x4 viewMatrix 
    6667                          ) 
    6768{ 
     
    7677        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 
    7778        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;  
    78         // save world space normal in rt 
    79         pix.norm = IN.normal; 
     79        // save world space normal in rt => transform back into world space by 
     80        // multiplying with inverse view. since transforming normal with T means to  
     81        // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 
     82        pix.norm = mul(transpose(viewMatrix), IN.normal); 
    8083        // compute eye linear depth 
    8184        pix.col.w = length(IN.eyePos.xyz); 
     
    8790 
    8891 
    89 pixel frag(fragin IN) 
     92pixel frag(fragin IN,  uniform float4x4 viewMatrix) 
    9093{ 
    9194        pixel pix; 
    9295        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 
    9396        pix.col = glstate.material.diffuse + glstate.material.emission; 
    94         // save world space normal in rt 
    95         pix.norm = IN.normal; 
     97        // save world space normal in rt => transform back into world space by 
     98        // multiplying with inverse view. since transforming normal with T means to  
     99        // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 
     100        pix.norm = mul(transpose(viewMatrix), IN.normal); 
    96101        // eye space depth 
    97102        pix.col.w = length(IN.eyePos.xyz); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg

    r3044 r3045  
    1 //-------------------------------------------------------------------------------------- 
    2 // Input and Output structs 
    3 //-------------------------------------------------------------------------------------- 
     1/***********************************************/ 
     2/*     Vertex shaders for tree animation       */ 
     3/***********************************************/ 
    44 
    55 
     
    77{ 
    88        float4 position: POSITION; 
    9         float3 normal: NORMAL; 
     9        float4 normal: NORMAL; 
     10         
    1011        float4 color: COLOR; 
     12        //float4 color1: COLOR1; 
     13 
    1114        float4 texCoord: TEXCOORD0; 
    1215}; 
     
    1922 
    2023        float4 color: COLOR0;   
     24        //float4 color1: COLOR1;   
    2125        float4 eyePos: TEXCOORD1; // eye position 
    2226        float3 normal: TEXCOORD2; 
     
    2428 
    2529 
    26 //-------------------------------------------------------------------------------------- 
    27 // Vertex Shaders 
    28 //-------------------------------------------------------------------------------------- 
    29  
    30  
     30/** Vertex shader which conducts an simple tree animation 
     31        that bends the tree depending quadratically on the height 
     32*/ 
    3133vtxout animateVtx(vtxin IN, 
    3234                                  uniform float3 windDir, 
     
    3436                                  uniform float frequency, 
    3537                                  uniform float2 minMaxPos, 
    36                                   uniform float timer) 
     38                                  uniform float timer, 
     39                                  uniform float3 lightDir) 
    3740{ 
    3841        vtxout OUT; 
    3942 
    40         OUT.color = float4(0);//IN.color; 
     43/* 
     44// Transform vertex position into homogenous clip-space. 
     45OUT.HPosition = mul(ModelViewProj, IN.Position); 
     46// Transform normal from model-space to view-space. 
     47float3 normalVec = normalize(mul(ModelViewIT, 
     48IN.Normal).xyz); 
     49// Store normalized light vector. 
     50float3 lightVec = normalize(LightVec.xyz); 
     51// Calculate half angle vector. 
     52float3 eyeVec = float3(0.0, 0.0, 1.0); 
     53float3 halfVec = normalize(lightVec + eyeVec); 
     54// Calculate diffuse component. 
     55float diffuse = dot(normalVec, lightVec); 
     56// Calculate specular component. 
     57float specular = dot(normalVec, halfVec); 
     58// Use the lit function to compute lighting vector from 
     59// diffuse and specular values. 
     60float4 lighting = lit(diffuse, specular, 32); 
     61// Blue diffuse material 
     62float3 diffuseMaterial = float3(0.0, 0.0, 1.0); 
     63// White specular material 
     64float3 specularMaterial = float3(1.0, 1.0, 1.0); 
     65// Combine diffuse and specular contributions and 
     66// output final vertex color. 
     67OUT.Color.rgb = lighting.y * diffuseMaterial + 
     68lighting.z * specularMaterial; 
     69OUT.Color.a = 1.0; 
     70return OUT; 
     71} 
     72*/ 
    4173        OUT.texCoord = IN.texCoord; 
    4274                 
    4375        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); 
     76        float factor = pos * pos * windStrength * sin(timer * frequency); 
    4477 
     78        // transform the vertex position into post projection space 
     79        OUT.position = mul(glstate.matrix.mvp, IN.position); 
     80        // displace the input position 
     81        OUT.position += float4(factor * windDir, 0); 
     82 
     83        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
     84 
     85        Out.color = IN.color * max(0, dot(OUT.normal, lightDir)); 
     86        //OUT.color1 = IN.color1; 
     87 
     88        return OUT; 
     89} 
     90 
     91/** vertex shader which conducts an simple tree animation 
     92        that bends the tree depending quadratically on the height 
     93        This version of the shader is used for deferred shading and thus only  
     94        displaces the vertices and outputs the color, put does not do any shading. 
     95*/ 
     96vtxout animateVtxMrt(vtxin IN, 
     97                                         uniform float3 windDir, 
     98                                         uniform float windStrength, 
     99                                         uniform float frequency, 
     100                                         uniform float2 minMaxPos, 
     101                                         uniform float timer) 
     102{ 
     103        vtxout OUT; 
     104 
     105        OUT.color = IN.color; 
     106        //OUT.color1 = IN.color1; 
     107 
     108        OUT.texCoord = IN.texCoord; 
     109                 
     110        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); 
    45111        float factor = pos * pos * windStrength * sin(timer * frequency); 
    46112 
     
    54120        OUT.eyePos += float4(factor * windDir, 0); 
    55121 
    56         OUT.normal = IN.normal; 
    57  
     122        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
     123         
    58124        return OUT; 
    59125} 
Note: See TracChangeset for help on using the changeset viewer.