Changeset 3041
- Timestamp:
- 10/19/08 00:29:45 (16 years ago)
- 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 42 42 static CGprofile sCgFragmentProfile; 43 43 static CGprofile sCgVertexProfile; 44 44 static ShaderProgram *sTreeAnimation; 45 45 46 46 // only instance of the resource manager … … 141 141 // create shape 142 142 Shape *shape = new Shape(geom, mat, sceneGeom); 143 143 144 144 mShapes.push_back(shape); 145 145 … … 150 150 mLODs.push_back(lodLevel); 151 151 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 } 152 185 } 153 186 … … 256 289 mat->mVertexProgram = mMrtDefaultVertexProgram; 257 290 mat->mGPUVertexParameters = CreateGPUProgramParameters(mat->mVertexProgram); 258 291 259 292 return mat; 260 293 } … … 424 457 mMrtDefaultFragmentTexProgram->AddParameter("tex", 0); 425 458 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 426 467 cout << "cg initialization successful" << endl; 427 468 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
r3036 r3041 1 1 #include "ShaderProgram.h" 2 2 #include "Matrix4x4.h" 3 #include "Timer/PerfTimer.h" 3 4 4 5 … … 10 11 11 12 GPUProgramParameters::GPUProgramParameters(ShaderProgram *p) 12 : mProgram(p) 13 : mProgram(p), mTimer(-1) 13 14 { 14 15 } … … 21 22 mMatrices.clear(); 22 23 mArrays.clear(); 24 25 mTimer = -1; 23 26 } 24 27 … … 97 100 98 101 mMatrices[idx] = MatrixParam(mat); 102 } 103 104 105 void GPUProgramParameters::SetTimerParam(int idx) 106 { 107 mTimer = idx; 99 108 } 100 109 … … 208 217 mProgram->SetArray1f(i, p.mValues, p.mNumEntries); 209 218 } 219 } 220 221 if (mTimer >= 0) 222 { 223 static PerfTimer mytimer; 224 mProgram->SetValue1f(mTimer, mytimer.Elapsedms(false) * M_PI / 180.0f); 210 225 } 211 226 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3038 r3041 53 53 void SetArray2f(int idx, float *vals, int numElements); 54 54 void SetArray3f(int idx, float *vals, int numElements); 55 56 void SetTimerParam(int idx); 55 57 56 58 /** Sets the texture parameter. … … 142 144 ShaderProgram *mProgram; 143 145 146 int mTimer; 144 147 std::vector<FloatParam> mFloats; 145 148 std::vector<IntParam> mTextures; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r3039 r3041 141 141 mSkyDome->GetShape(0)->GetMaterial()->GetVertexProgram()->Bind(); 142 142 143 mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgramParameters()->UpdateParameters(); 144 mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgram()->Bind(); 145 143 146 // Render sky dome. 144 147 mSkyDome->Render(state); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3040 r3041 477 477 skyDome = sceneEntities.back(); 478 478 479 //InitCg();480 ShaderProgram *treeAnimation = loader->CreateVertexProgram("treeanimation", "animateVtx");481 479 const float turbitiy = 5.0f; 482 480 preetham = new SkyPreetham(turbitiy, skyDome); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3034 r3041 8 8 }; 9 9 10 10 11 // vtx output 11 12 struct vtxout 12 13 { 13 float4 position: POSITION; // eye space 14 14 float4 position: POSITION; 15 float4 texCoord: TEXCOORD0; 15 16 16 17 18 17 float4 color: COLOR0; 18 float4 eyePos: TEXCOORD1; // eye position 19 float3 normal: TEXCOORD2; 19 20 }; 20 21 … … 60 61 } 61 62 62 //#pragma position_invariant fragtex63 63 64 64 pixel fragtex(fragin IN, … … 78 78 // save world space normal in rt 79 79 pix.norm = IN.normal; 80 80 // compute eye linear depth 81 pix.col.w = length(IN.eyePos.xyz); 81 82 // hack: squeeze some information about ambient into the texture 82 83 //pix.col.w = glstate.material.emission.x; 83 84 // compute eye linear depth85 pix.col.w = length(IN.eyePos.xyz);86 84 87 85 return pix; … … 92 90 { 93 91 pixel pix; 94 95 92 // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 96 93 pix.col = glstate.material.diffuse + glstate.material.emission; 97 94 // save world space normal in rt 98 95 pix.norm = IN.normal; 99 96 // eye space depth 100 97 pix.col.w = length(IN.eyePos.xyz); 101 102 98 // hack: squeeze some information about the ambient term into the target 103 99 //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 structs3 //--------------------------------------------------------------------------------------4 5 6 7 1 struct vtxin 8 2 { … … 17 11 struct vtxout 18 12 { 19 float4 position: POSITION; // eye space 13 float4 color: COLOR0; 14 float4 position: POSITION; 15 20 16 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; 27 19 }; 28 20 … … 32 24 { 33 25 float4 color: COLOR0; 34 float4 position: POSITION; // eye space 26 //float4 projPos: WPOS; 27 //float4 position: POSITION; 28 35 29 float4 texCoord: TEXCOORD0; 36 37 float4 projPos: WPOS; 38 float3 normal: TEXCOORD2; 39 float4 hdrColor: TEXCOORD4; 30 float3 normal: TEXCOORD1; 31 float4 hdrColor: TEXCOORD2; 40 32 }; 41 33 42 34 43 struct fragout35 struct pixel 44 36 { 45 37 float4 col: COLOR0; 46 float 4norm: COLOR1;38 float3 norm: COLOR1; 47 39 float3 pos: COLOR2; 48 40 }; … … 104 96 105 97 106 fragoutfrag_skydome(fragin IN)98 pixel frag_skydome(fragin IN) 107 99 { 108 fragoutpix;100 pixel pix; 109 101 110 102 pix.col = IN.hdrColor; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
r3040 r3041 8 8 float4 position: POSITION; 9 9 float3 normal: NORMAL; 10 float 3color: COLOR;11 float 2 texcoord: TEXCOORD0;10 float4 color: COLOR; 11 float4 texCoord: TEXCOORD0; 12 12 }; 13 14 13 15 14 // vtx output 16 15 struct vtxout 17 16 { 18 float4 position: POSITION; // eye space17 float4 position: POSITION; 19 18 float4 texCoord: TEXCOORD0; 20 19 21 20 float4 color: COLOR0; 21 float4 eyePos: TEXCOORD1; // eye position 22 22 float3 normal: TEXCOORD2; 23 float4 eyePos: TEXCOORD3;24 23 }; 25 26 24 27 25 … … 34 32 uniform float3 windDir, 35 33 uniform float windStrength, 36 uniform float2 minmaxPos, 34 uniform float frequency, 35 uniform float2 minMaxPos, 37 36 uniform float timer) 38 37 { 39 38 vtxout OUT; 40 39 41 OUT.color = IN.color;40 OUT.color = float4(0);//IN.color; 42 41 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 43 52 // transform the vertex position into eye space 44 53 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); 54 55 55 56 OUT.normal = IN.normal;
Note: See TracChangeset
for help on using the changeset viewer.