- Timestamp:
- 10/20/08 01:26:12 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3045 r3046 42 42 static CGprofile sCgFragmentProfile; 43 43 static CGprofile sCgVertexProfile; 44 static ShaderProgram *sTreeAnimation; 44 45 static ShaderProgram *sTreeAnimationProgramMrt; 46 static ShaderProgram *sTreeAnimationProgram; 47 45 48 46 49 // only instance of the resource manager … … 153 156 154 157 /////////// 155 //-- hack: tree animation158 //-- hack: add tree animation 156 159 157 160 if (numLODs > 1) 158 161 { 159 for (int i = 0; i < min(numLODs, 2); ++ i) 162 //for (int i = 0; i < min(numLODs, 2); ++ i) 163 for (int i = 0; i < numLODs; ++ i) 160 164 { 161 165 ShapeContainer::iterator sstart, send; … … 172 176 { 173 177 Technique *tech = mat->GetTechnique(i); 174 tech->SetVertexProgram(sTreeAnimation);175 178 176 179 GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters(); 177 180 181 if (i == 0) 182 { 183 tech->SetVertexProgram(sTreeAnimationProgram); 184 vtxParams->SetLightDirParam(5); 185 } 186 else 187 { 188 tech->SetVertexProgram(sTreeAnimationProgramMrt); 189 } 190 191 /// use a timer to simulate the moving of the tree in the wind 178 192 vtxParams->SetTimerParam(0); 179 193 // wind direction … … 352 366 353 367 354 void ResourceManager::LoadSceneEntities(igzstream &str, SceneEntityContainer &entities) 368 void ResourceManager::LoadSceneEntities(igzstream &str, 369 SceneEntityContainer &entities) 355 370 { 356 371 int entityCount; … … 373 388 374 389 375 bool ResourceManager::Load(const std::string &filename, SceneEntityContainer &entities) 390 bool ResourceManager::Load(const std::string &filename, 391 SceneEntityContainer &entities) 376 392 { 377 393 igzstream istr(filename.c_str()); … … 468 484 mMrtDefaultFragmentProgram->AddParameter("viewMatrix", 0); 469 485 mMrtDefaultFragmentTexProgram->AddParameter("viewMatrix", 0); 470 471 486 // add a texture parameter 472 487 mMrtDefaultFragmentTexProgram->AddParameter("tex", 1); 473 488 474 sTreeAnimation = CreateVertexProgram("treeanimation", "animateVtxMrt"); 475 476 sTreeAnimation->AddParameter("timer", 0); 477 sTreeAnimation->AddParameter("windDir", 1); 478 sTreeAnimation->AddParameter("windStrength", 2); 479 sTreeAnimation->AddParameter("minMaxPos", 3); 480 sTreeAnimation->AddParameter("frequency", 4); 489 490 //////////// 491 //-- hack: apply hardcoded tree animation (should be provided with a material script!) 492 493 sTreeAnimationProgram = CreateVertexProgram("treeanimation", "animateVtx"); 494 sTreeAnimationProgramMrt = CreateVertexProgram("treeanimation", "animateVtxMrt"); 495 496 sTreeAnimationProgram->AddParameter("timer", 0); 497 sTreeAnimationProgram->AddParameter("windDir", 1); 498 sTreeAnimationProgram->AddParameter("windStrength", 2); 499 sTreeAnimationProgram->AddParameter("minMaxPos", 3); 500 sTreeAnimationProgram->AddParameter("frequency", 4); 501 sTreeAnimationProgram->AddParameter("lightDir", 5); 502 503 sTreeAnimationProgramMrt->AddParameter("timer", 0); 504 sTreeAnimationProgramMrt->AddParameter("windDir", 1); 505 sTreeAnimationProgramMrt->AddParameter("windStrength", 2); 506 sTreeAnimationProgramMrt->AddParameter("minMaxPos", 3); 507 sTreeAnimationProgramMrt->AddParameter("frequency", 4); 481 508 482 509 cout << "cg initialization successful" << endl; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
r3045 r3046 4 4 #include "Vector3.h" 5 5 #include "Camera.h" 6 #include "Light.h" 6 7 7 8 … … 13 14 ////////// 14 15 //-- changing shader parameters 16 15 17 static float sCurrentTimer = 0; 16 18 static Matrix4x4 sCurrentViewMatrix = IdentityMatrix(); 17 static Vector3 sCurrentViewVector = Vector3::UNIT_Y(); 19 static Vector3 sCurrentViewDir = Vector3::UNIT_Y(); 20 static Vector3 sCurrentLightDir = Vector3::UNIT_Y(); 21 22 23 /*********************************************************/ 24 /* GPUProgramParameters implementation */ 25 /*********************************************************/ 18 26 19 27 … … 21 29 mProgram(p), 22 30 mTimerParam(-1), 23 mViewVectorParam(-1), 24 mViewMatrixParam(-1) 31 mViewDirParam(-1), 32 mViewMatrixParam(-1), 33 mLightDirParam(-1) 25 34 { 26 35 } … … 30 39 mProgram(NULL), 31 40 mTimerParam(-1), 32 mViewVectorParam(-1), 33 mViewMatrixParam(-1) 41 mViewDirParam(-1), 42 mViewMatrixParam(-1), 43 mLightDirParam(-1) 34 44 { 35 45 } … … 44 54 45 55 mTimerParam = -1; 46 mViewVectorParam = -1; 56 mViewDirParam = -1; 57 mLightDirParam = -1; 47 58 mViewMatrixParam = -1; 48 59 } … … 137 148 138 149 139 void GPUProgramParameters::SetViewVectorParam(int idx) 140 { 141 mViewVectorParam = idx; 150 void GPUProgramParameters::SetViewDirParam(int idx) 151 { 152 mViewDirParam = idx; 153 } 154 155 156 void GPUProgramParameters::SetLightDirParam(int idx) 157 { 158 mLightDirParam = idx; 142 159 } 143 160 … … 258 275 mProgram->SetValue1f(mTimerParam, sCurrentTimer); 259 276 260 if (mViewVectorParam >= 0) 261 mProgram->SetValue3f(mViewVectorParam, sCurrentViewVector.x, sCurrentViewVector.y, sCurrentViewVector.z); 262 277 if (mViewDirParam >= 0) 278 mProgram->SetValue3f(mViewDirParam, sCurrentViewDir.x, sCurrentViewDir.y, sCurrentViewDir.z); 279 if (mLightDirParam >= 0) 280 mProgram->SetValue3f(mLightDirParam, sCurrentLightDir.x, sCurrentLightDir.y, sCurrentLightDir.z); 263 281 if (mViewMatrixParam >= 0) 264 282 mProgram->SetMatrix(mViewMatrixParam, sCurrentViewMatrix); … … 266 284 267 285 268 void GPUProgramParameters::InitFrame(Camera *cam )286 void GPUProgramParameters::InitFrame(Camera *cam, DirectionalLight *light) 269 287 { 270 288 static PerfTimer mytimer; … … 272 290 273 291 cam->GetModelViewMatrix(sCurrentViewMatrix); 274 sCurrentViewVector = cam->GetDirection(); 292 sCurrentViewDir = cam->GetDirection(); 293 294 Matrix4x4 vo; 295 // transform to view space 296 cam->GetViewOrientationMatrix(vo); 297 //sCurrentLightDir = /*vo **/ -light->GetDirection(); 298 sCurrentLightDir = vo * -light->GetDirection(); 275 299 } 276 300 … … 318 342 319 343 320 /*void ShaderProgram::Release()344 void ShaderProgram::Release() 321 345 { 322 346 CGParameterArray::const_iterator it, it_end = mTextureParams.end(); … … 325 349 for (it = mTextureParams.begin(); it != it_end; ++ it) 326 350 cgGLDisableTextureParameter(*it); 327 } */351 } 328 352 329 353 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3045 r3046 70 70 */ 71 71 void SetTimerParam(int idx); 72 /** This parameter is connected to the current view matrix that is updated73 once per frame.72 /** This parameter is connected to the current view matrix 73 that is updated once per frame. 74 74 */ 75 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); 76 /** This parameter is connected to the current view direction 77 that is updated once per frame. 78 */ 79 void SetViewDirParam(int idx); 80 /** This parameter is connected to the current light direction 81 that is updated once per frame. 82 */ 83 void SetLightDirParam(int idx); 80 84 81 85 … … 103 107 /** Function should be called once per frame to update frame related parameters. 104 108 */ 105 static void InitFrame(Camera *cam );109 static void InitFrame(Camera *cam, DirectionalLight *light); 106 110 107 111 … … 164 168 165 169 int mTimerParam; 166 int mViewVectorParam; 170 int mViewDirParam; 171 int mLightDirParam; 167 172 int mViewMatrixParam; 168 173 … … 222 227 void SetArray2f(const std::string &name, float *vals, int numElements); 223 228 void SetArray3f(const std::string &name, float *vals, int numElements); 224 /// Sets a matrix parameter 229 /** Sets a matrix parameter 230 */ 225 231 void SetMatrix(const std::string &name, const Matrix4x4 &mat); 226 232 /** Sets the texture parameter. 227 233 */ 228 234 void SetTexture(const std::string &name, unsigned int tex); 229 230 235 /** Binds the program. 231 236 */ … … 234 239 */ 235 240 inline bool IsValid() const { return mProgram != NULL; } 236 /** Enable / disable a texture parameter. 237 */ 238 //void EnableTexture(const std::string &name); 239 //void DisableTexture(const std::string &name); 240 241 /** Releases all texture resources. 242 */ 243 void Release(); 241 244 242 245 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3045 r3046 714 714 715 715 716 const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && useHDR; 716 const bool useToneMapping = 717 ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || 718 (renderMethod == RENDER_DEFERRED)) && useHDR; 719 717 720 718 721 Vector3 sunAmbient; … … 883 886 884 887 // set GPU related parameters 885 GPUProgramParameters::InitFrame(camera );888 GPUProgramParameters::InitFrame(camera, light); 886 889 887 890 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3045 r3046 90 90 91 91 92 pixel frag(fragin IN, 92 pixel frag(fragin IN, uniform float4x4 viewMatrix) 93 93 { 94 94 pixel pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
r3045 r3046 24 24 //float4 color1: COLOR1; 25 25 float4 eyePos: TEXCOORD1; // eye position 26 float 3normal: TEXCOORD2;26 float4 normal: TEXCOORD2; 27 27 }; 28 28 … … 40 40 { 41 41 vtxout OUT; 42 43 /*44 // Transform vertex position into homogenous clip-space.45 OUT.HPosition = mul(ModelViewProj, IN.Position);46 // Transform normal from model-space to view-space.47 float3 normalVec = normalize(mul(ModelViewIT,48 IN.Normal).xyz);49 // Store normalized light vector.50 float3 lightVec = normalize(LightVec.xyz);51 // Calculate half angle vector.52 float3 eyeVec = float3(0.0, 0.0, 1.0);53 float3 halfVec = normalize(lightVec + eyeVec);54 // Calculate diffuse component.55 float diffuse = dot(normalVec, lightVec);56 // Calculate specular component.57 float specular = dot(normalVec, halfVec);58 // Use the lit function to compute lighting vector from59 // diffuse and specular values.60 float4 lighting = lit(diffuse, specular, 32);61 // Blue diffuse material62 float3 diffuseMaterial = float3(0.0, 0.0, 1.0);63 // White specular material64 float3 specularMaterial = float3(1.0, 1.0, 1.0);65 // Combine diffuse and specular contributions and66 // output final vertex color.67 OUT.Color.rgb = lighting.y * diffuseMaterial +68 lighting.z * specularMaterial;69 OUT.Color.a = 1.0;70 return OUT;71 }72 */73 42 OUT.texCoord = IN.texCoord; 74 43 … … 81 50 OUT.position += float4(factor * windDir, 0); 82 51 83 OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 52 OUT.normal = normalize(mul(glstate.matrix.invtrans.modelview[0], IN.normal)); 53 //const float3 l = normalize(mul(glstate.matrix.modelview[0], float4(lightDir, 0))).xyz; 54 const float3 l = normalize(lightDir); 84 55 85 Out.color = IN.color * max(0, dot(OUT.normal, lightDir)); 86 //OUT.color1 = IN.color1; 56 const float dif = max(.0f, dot(OUT.normal.xyz, l)); 87 57 58 //OUT.color.xyz = IN.color.xyz * max(0, dot(OUT.normal.xyz, normalize(lightDir))); 59 OUT.color = glstate.material.ambient + glstate.material.front.diffuse * dif; 60 OUT.color.w = IN.color.w; 88 61 return OUT; 89 62 } 90 63 91 /** vertex shader which conducts an simple tree animation92 that bends the tree depending quadratically on the height 64 /** vertex shader which provides an simple tree animation 65 that bends the tree depending quadratically on the height using vertex displacement. 93 66 This version of the shader is used for deferred shading and thus only 94 67 displaces the vertices and outputs the color, put does not do any shading. … … 104 77 105 78 OUT.color = IN.color; 106 //OUT.color1 = IN.color1;107 108 79 OUT.texCoord = IN.texCoord; 109 80
Note: See TracChangeset
for help on using the changeset viewer.