Ignore:
Timestamp:
10/19/08 00:29:45 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
8 edited

Legend:

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

    r3039 r3041  
    4242static CGprofile sCgFragmentProfile; 
    4343static CGprofile sCgVertexProfile;  
    44  
     44static ShaderProgram *sTreeAnimation; 
    4545 
    4646// only instance of the resource manager 
     
    141141                        // create shape 
    142142                        Shape *shape = new Shape(geom, mat, sceneGeom); 
    143                          
     143 
    144144                        mShapes.push_back(shape); 
    145145 
     
    150150                mLODs.push_back(lodLevel); 
    151151                sceneGeom->AddLODLevel(lodLevel); 
     152        } 
     153 
     154        /////////// 
     155        //-- hack: tree animation 
     156 
     157        if (numLODs > 1) 
     158        { 
     159                for (int i = 0; i < min(numLODs, 2); ++ i) 
     160                { 
     161                        ShapeContainer::iterator sstart, send; 
     162                        sceneGeom->GetLODLevel(i, sstart, send); 
     163 
     164                        for (ShapeContainer::iterator it = sstart; it != send; ++ it) 
     165                        { 
     166                                Shape *shape = *it; 
     167                                Material *mat = shape->GetMaterial(); 
     168                                mat->SetVertexProgram(sTreeAnimation); 
     169 
     170                                GPUProgramParameters *vtxParams = mat->GetVertexProgramParameters(); 
     171 
     172                                vtxParams->SetTimerParam(0); 
     173                                // wind direction 
     174                                static Vector3 windDir = Normalize(Vector3(0.8f, 0.2f, 0.0f)); 
     175                                vtxParams->SetValue3f(1, windDir.x, windDir.y, windDir.z); 
     176                                // amplitude 
     177                                vtxParams->SetValue1f(2, 0.3f); 
     178 
     179                                AxisAlignedBox3 box = sceneGeom->GetBoundingBox(); 
     180                                vtxParams->SetValue2f(3, box.Min().z, box.Max().z); 
     181                                // frequency 
     182                                vtxParams->SetValue1f(4, 0.1f); 
     183                        } 
     184                } 
    152185        } 
    153186 
     
    256289        mat->mVertexProgram = mMrtDefaultVertexProgram; 
    257290        mat->mGPUVertexParameters = CreateGPUProgramParameters(mat->mVertexProgram); 
    258  
     291         
    259292        return mat; 
    260293} 
     
    424457        mMrtDefaultFragmentTexProgram->AddParameter("tex", 0); 
    425458 
     459        sTreeAnimation = CreateVertexProgram("treeanimation", "animateVtx"); 
     460 
     461        sTreeAnimation->AddParameter("timer", 0); 
     462        sTreeAnimation->AddParameter("windDir", 1); 
     463        sTreeAnimation->AddParameter("windStrength", 2); 
     464        sTreeAnimation->AddParameter("minMaxPos", 3); 
     465        sTreeAnimation->AddParameter("frequency", 4); 
     466 
    426467        cout << "cg initialization successful" << endl; 
    427468} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp

    r3036 r3041  
    11#include "ShaderProgram.h" 
    22#include "Matrix4x4.h" 
     3#include "Timer/PerfTimer.h" 
    34 
    45 
     
    1011 
    1112GPUProgramParameters::GPUProgramParameters(ShaderProgram *p) 
    12 : mProgram(p) 
     13: mProgram(p), mTimer(-1) 
    1314{ 
    1415} 
     
    2122        mMatrices.clear(); 
    2223        mArrays.clear(); 
     24 
     25        mTimer = -1; 
    2326} 
    2427 
     
    97100 
    98101        mMatrices[idx] = MatrixParam(mat); 
     102} 
     103 
     104 
     105void GPUProgramParameters::SetTimerParam(int idx) 
     106{ 
     107        mTimer = idx; 
    99108} 
    100109 
     
    208217                        mProgram->SetArray1f(i, p.mValues, p.mNumEntries); 
    209218                } 
     219        } 
     220 
     221        if (mTimer >= 0) 
     222        { 
     223                static PerfTimer mytimer; 
     224                mProgram->SetValue1f(mTimer, mytimer.Elapsedms(false) * M_PI / 180.0f); 
    210225        } 
    211226} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h

    r3038 r3041  
    5353        void SetArray2f(int idx, float *vals, int numElements); 
    5454        void SetArray3f(int idx, float *vals, int numElements); 
     55 
     56        void SetTimerParam(int idx); 
    5557 
    5658        /** Sets the texture parameter. 
     
    142144        ShaderProgram *mProgram; 
    143145 
     146        int mTimer; 
    144147        std::vector<FloatParam> mFloats; 
    145148        std::vector<IntParam> mTextures; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r3039 r3041  
    141141        mSkyDome->GetShape(0)->GetMaterial()->GetVertexProgram()->Bind(); 
    142142 
     143        mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgramParameters()->UpdateParameters(); 
     144        mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgram()->Bind(); 
     145 
    143146        // Render sky dome. 
    144147        mSkyDome->Render(state); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3040 r3041  
    477477        skyDome = sceneEntities.back(); 
    478478 
    479         //InitCg(); 
    480         ShaderProgram *treeAnimation = loader->CreateVertexProgram("treeanimation", "animateVtx"); 
    481479        const float turbitiy = 5.0f; 
    482480        preetham = new SkyPreetham(turbitiy, skyDome); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3034 r3041  
    88}; 
    99 
     10 
    1011// vtx output 
    1112struct vtxout 
    1213{ 
    13   float4 position: POSITION; // eye space 
    14   float4 texCoord: TEXCOORD0;     
     14        float4 position: POSITION; 
     15        float4 texCoord: TEXCOORD0;     
    1516 
    16   float4 color: COLOR0;   
    17   float4 eyePos: TEXCOORD1; // eye position 
    18   float3 normal: TEXCOORD2; 
     17        float4 color: COLOR0;   
     18        float4 eyePos: TEXCOORD1; // eye position 
     19        float3 normal: TEXCOORD2; 
    1920}; 
    2021 
     
    6061} 
    6162 
    62 //#pragma position_invariant fragtex 
    6363 
    6464pixel fragtex(fragin IN,  
     
    7878        // save world space normal in rt 
    7979        pix.norm = IN.normal; 
    80  
     80        // compute eye linear depth 
     81        pix.col.w = length(IN.eyePos.xyz); 
    8182        // hack: squeeze some information about ambient into the texture 
    8283        //pix.col.w = glstate.material.emission.x; 
    83  
    84         // compute eye linear depth 
    85         pix.col.w = length(IN.eyePos.xyz); 
    8684 
    8785        return pix; 
     
    9290{ 
    9391        pixel pix; 
    94  
    9592        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 
    9693        pix.col = glstate.material.diffuse + glstate.material.emission; 
    97  
     94        // save world space normal in rt 
    9895        pix.norm = IN.normal; 
    99  
     96        // eye space depth 
    10097        pix.col.w = length(IN.eyePos.xyz); 
    101  
    10298        // hack: squeeze some information about the ambient term into the target 
    10399        //pix.col.w = glstate.material.emission.x; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg

    r3040 r3041  
    1 //-------------------------------------------------------------------------------------- 
    2 // Input and Output structs 
    3 //-------------------------------------------------------------------------------------- 
    4  
    5  
    6  
    71struct vtxin 
    82{ 
     
    1711struct vtxout 
    1812{ 
    19         float4 position: POSITION; // eye space 
     13        float4 color: COLOR0;   
     14        float4 position: POSITION;  
     15 
    2016        float4 texCoord: TEXCOORD0;     
    21  
    22         float4 color: COLOR0;   
    23         float4 worldPos: TEXCOORD1; // world position 
    24         float3 normal: TEXCOORD2; 
    25         float4 mypos: TEXCOORD3; 
    26         float4 hdrColor: TEXCOORD4; 
     17        float3 normal: TEXCOORD1; 
     18        float4 hdrColor: TEXCOORD2; 
    2719}; 
    2820 
     
    3224{ 
    3325        float4 color: COLOR0;   
    34         float4 position: POSITION; // eye space 
     26        //float4 projPos: WPOS; 
     27        //float4 position: POSITION; 
     28 
    3529        float4 texCoord: TEXCOORD0;     
    36  
    37         float4 projPos: WPOS; 
    38         float3 normal: TEXCOORD2; 
    39         float4 hdrColor: TEXCOORD4; 
     30        float3 normal: TEXCOORD1; 
     31        float4 hdrColor: TEXCOORD2; 
    4032}; 
    4133 
    4234 
    43 struct fragout 
     35struct pixel 
    4436{ 
    4537        float4 col: COLOR0; 
    46         float4 norm: COLOR1; 
     38        float3 norm: COLOR1; 
    4739        float3 pos: COLOR2; 
    4840}; 
     
    10496 
    10597 
    106 fragout frag_skydome(fragin IN) 
     98pixel frag_skydome(fragin IN) 
    10799{ 
    108         fragout pix; 
     100        pixel pix; 
    109101 
    110102        pix.col = IN.hdrColor; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg

    r3040 r3041  
    88        float4 position: POSITION; 
    99        float3 normal: NORMAL; 
    10         float3 color: COLOR; 
    11         float2 texcoord: TEXCOORD0; 
     10        float4 color: COLOR; 
     11        float4 texCoord: TEXCOORD0; 
    1212}; 
    13  
    1413 
    1514// vtx output 
    1615struct vtxout 
    1716{ 
    18         float4 position: POSITION; // eye space 
     17        float4 position: POSITION; 
    1918        float4 texCoord: TEXCOORD0;     
    2019 
    2120        float4 color: COLOR0;   
     21        float4 eyePos: TEXCOORD1; // eye position 
    2222        float3 normal: TEXCOORD2; 
    23         float4 eyePos: TEXCOORD3; 
    2423}; 
    25  
    2624 
    2725 
     
    3432                                  uniform float3 windDir, 
    3533                                  uniform float windStrength, 
    36                                   uniform float2 minmaxPos, 
     34                                  uniform float frequency, 
     35                                  uniform float2 minMaxPos, 
    3736                                  uniform float timer) 
    3837{ 
    3938        vtxout OUT; 
    4039 
    41         OUT.color = IN.color; 
     40        OUT.color = float4(0);//IN.color; 
    4241        OUT.texCoord = IN.texCoord; 
     42                 
     43        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); 
     44 
     45        float factor = pos * windStrength * sin(timer * frequency); 
     46 
     47        // transform the vertex position into post projection space 
     48        OUT.position = mul(glstate.matrix.mvp, IN.position); 
     49        // displace the input position 
     50        OUT.position += float4(factor * windDir, 0); 
     51 
    4352        // transform the vertex position into eye space 
    4453        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position); 
    45          
    46         const float pos = (minmaxPos.x - IN.position.y / (minmaxPos.x - minmaxPos.y); 
    47  
    48         float factor = windStrength * sin(timer); 
    49  
    50         // displace the input position 
    51         float4 newPos = IN.position + float4(factor * windDir, 0.0f); 
    52         // transform the vertex position into post projection space 
    53         OUT.position = mul(glstate.matrix.mvp, IN.position); 
     54        OUT.eyePos += float4(factor * windDir, 0); 
    5455 
    5556        OUT.normal = IN.normal; 
Note: See TracChangeset for help on using the changeset viewer.