Changeset 3113
- Timestamp:
- 11/10/08 02:39:15 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3112 r3113 340 340 "samples", "bl", "br", "tl", "tr", 341 341 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 342 "oldtl", "oldtr", "attribsTex" , "inverseModelTrafos"};343 sCgSsaoProgram->AddParameters(ssaoParams, 0, 1 9);342 "oldtl", "oldtr", "attribsTex"}; 343 sCgSsaoProgram->AddParameters(ssaoParams, 0, 18); 344 344 345 345 string giParams[] = … … 574 574 trafos[i+16] = ((const float *)identity.x)[i]; 575 575 576 sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2);576 //sCgSsaoProgram->SetMatrixArray(i ++, trafos, 2); 577 577 //sCgSsaoProgram->SetMatrix(i ++, IdentityMatrix()); 578 578 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3071 r3113 127 127 } 128 128 129 static ShaderProgram *sTreeAnimationProgram = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation"); 130 static ShaderProgram *sTreeAnimationProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt"); 129 130 static ShaderProgram *sTreeAnimationProgram = 131 ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation"); 132 static ShaderProgram *sTreeAnimationProgramMrt = 133 ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt"); 134 131 135 132 136 /////////// … … 168 172 /// use a timer to simulate the moving of the tree in the wind 169 173 vtxParams->SetTimerParam(0); 174 170 175 // wind direction 171 176 static Vector3 windDir = Normalize(Vector3(0.8f, 0.2f, 0.0f)); … … 298 303 299 304 deferred->SetVertexProgram(sDefaultVertexProgramMrt); 305 306 static Matrix4x4 identity = IdentityMatrix(); 307 308 // default values: these are only updated for dynamic objects 309 deferred->GetVertexProgramParameters()->SetMatrix(1, identity); 310 deferred->GetVertexProgramParameters()->SetMatrix(2, identity); 311 300 312 mat->AddTechnique(deferred); 301 313 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r3110 r3113 164 164 { 165 165 if (mTransform->IsIdentity()) return mCenter; 166 167 166 return mTransform->GetMatrix() * mCenter; 168 167 } … … 171 170 void SceneEntity::Prepare(RenderState *state) 172 171 { 173 int id[] = {(mId / (255 * 255)) % 255, (mId / 255) % 255, mId % 255, 0};172 /*int id[] = {(mId / (255 * 255)) % 255, (mId / 255) % 255, mId % 255, 0}; 174 173 175 174 GLfloat fogColor[4] = {(float)id[0] / 255.0f, (float)id[1] / 255.0f, (float)id[2] / 255.0f, .0f}; 176 glFogfv(GL_FOG_COLOR, fogColor); 175 glFogfv(GL_FOG_COLOR, fogColor);*/ 177 176 178 177 mTransform->Load(state); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp
r3112 r3113 4 4 #include "ShaderProgram.h" 5 5 #include "ShaderManager.h" 6 #include "Matrix4x4.h" 6 7 #include <Cg/cg.h> 7 8 #include <Cg/cgGL.h> … … 45 46 if(lastError) 46 47 { 48 printf("Cg error, exiting...\n"); 49 47 50 Debug << "\n" << cgGetErrorString(lastError) << endl; 48 51 Debug << "\n" << cgGetLastListing(sCgContext) << endl; 49 /*printf("%s\n\n", cgGetErrorString(lastError)); 52 53 printf("%s\n\n", cgGetErrorString(lastError)); 50 54 printf("%s\n", cgGetLastListing(sCgContext)); 51 */52 printf("Cg error, exiting...\n");53 54 55 55 56 exit(0); … … 85 86 fragmentProgMrtTex = CreateFragmentProgram("mrt", "fragtex", "defaultFragmentTexMrt"); 86 87 87 // provide the current view matrix 88 // provide the current view matrix: 89 // this is an automatic parameter that is updated each frame 88 90 fragmentProgMrt->AddParameter("viewMatrix", 0); 89 91 fragmentProgMrtTex->AddParameter("viewMatrix", 0); 92 93 vertexProgMrt->AddParameter("viewMatrix", 0); 94 95 // these parameters are used for ssao 96 vertexProgMrt->AddParameter("modelMatrix", 1); 97 vertexProgMrt->AddParameter("oldModelMatrix", 2); 98 90 99 91 100 // add a texture parameter -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
r3112 r3113 138 138 139 139 140 void GPUProgramParameters::SetMatrix(int idx, Matrix4x4 *mat)140 void GPUProgramParameters::SetMatrix(int idx, const Matrix4x4 &mat) 141 141 { 142 142 if (mMatrices.size() < idx + 1) … … 207 207 208 208 209 void GPUProgramParameters::SetMatrix(const string &name, Matrix4x4 *mat)209 void GPUProgramParameters::SetMatrix(const string &name, const Matrix4x4 &mat) 210 210 { 211 211 SetMatrix(mProgram->GetParamIdxByName(name), mat); … … 263 263 const MatrixParam &p = mMatrices[i]; 264 264 265 if (p.mValid) 266 mProgram->SetMatrix(i, *p.mValue); 265 if (p.mValid) mProgram->SetMatrix(i, p.mValue); 267 266 } 268 267 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3112 r3113 4 4 #include "common.h" 5 5 #include "glInterface.h" 6 6 #include "Matrix4x4.h" 7 7 #include <Cg/cg.h> 8 8 #include <Cg/cgGL.h> … … 17 17 class Vector3; 18 18 class Camera; 19 class Matrix4x4;20 19 class ShadowMap; 21 20 class DirectionalLight; … … 56 55 void SetArray2f(int idx, float *vals, int numElements); 57 56 void SetArray3f(int idx, float *vals, int numElements); 58 /** Sets thetexture parameter.57 /** Sets a texture parameter. 59 58 */ 60 59 void SetTexture(int idx, unsigned int tex); 61 /** Sets thematrix parameter.62 */ 63 void SetMatrix(int idx, Matrix4x4 *mat);60 /** Sets a matrix parameter. 61 */ 62 void SetMatrix(int idx, const Matrix4x4 &mat); 64 63 /** Sets an array of matrices 65 64 */ 66 65 void SetMatrixArray(int idx, float *vals, int numElements); 66 67 67 68 68 //////////// … … 104 104 /** Sets the matrix parameter. 105 105 */ 106 void SetMatrix(const std::string &name, Matrix4x4 *mat);106 void SetMatrix(const std::string &name, const Matrix4x4 &mat); 107 107 /** Sets an array of matrices 108 108 */ 109 109 void SetMatrixArray(const std::string &name, float *vals, int numElements); 110 111 110 /** Feeds the shader program with the parameter values. 112 111 */ … … 146 145 struct MatrixParam 147 146 { 148 MatrixParam(): mValue( NULL), mValid(false) {}149 150 MatrixParam( Matrix4x4 *mat): mValue(mat), mValid(true)147 MatrixParam(): mValue(IdentityMatrix()), mValid(false) {} 148 149 MatrixParam(const Matrix4x4 &mat): mValue(mat), mValid(true) 151 150 {} 152 151 153 152 bool mValid; 154 Matrix4x4 *mValue;153 Matrix4x4 mValue; 155 154 }; 156 155 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
r3070 r3113 33 33 */ 34 34 inline Matrix4x4 GetMatrix() const { return mMatrix; } 35 /** Returns pointer to trafo matrix 36 */ 37 inline const Matrix4x4 *GetPMatrix() const { return &mMatrix; } 35 38 /** See Get 36 39 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3112 r3113 54 54 #include "ShaderManager.h" 55 55 #include "MotionPath.h" 56 56 #include "ShaderProgram.h" 57 #include "Shape.h" 57 58 58 59 … … 573 574 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 574 575 // a rgb buffer which could hold material properties 575 fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 576 //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 577 // holding the difference vector to the old frame 578 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 576 579 // another color buffer 577 580 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); … … 899 902 void MainLoop() 900 903 { 901 static Matrix4x4 invTrafo = IdentityMatrix(); 904 GPUProgramParameters *vtxParams = 905 buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); 906 907 static Matrix4x4 oldTrafo; 908 909 oldTrafo = buddha->GetTransform()->GetMatrix(); 910 vtxParams->SetMatrix(2, oldTrafo); 902 911 903 912 Vector3 buddhaPos = motionPath->GetCurrentPosition(); 904 913 Matrix4x4 trafo = TranslationMatrix(buddhaPos); 914 905 915 buddha->GetTransform()->SetMatrix(trafo); 916 917 vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix()); 918 906 919 907 920 ///////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3110 r3113 18 18 float4 eyePos: TEXCOORD1; // eye position 19 19 float4 normal: TEXCOORD2; 20 float4 worldPos: TEXCOORD3; 21 float4 oldWorldPos: TEXCOORD4; 20 22 }; 21 23 … … 25 27 { 26 28 float4 color: COLOR0; 27 //float4 position: POSITION;28 29 float4 texCoord: TEXCOORD0; 29 30 … … 31 32 float4 eyePos: TEXCOORD1; // eye position 32 33 float4 normal: TEXCOORD2; 34 float4 worldPos: TEXCOORD3; 35 float4 oldWorldPos: TEXCOORD4; 33 36 }; 34 37 … … 38 41 float4 col: COLOR0; 39 42 float3 norm: COLOR1; 40 float3 id: COLOR2;43 float3 offsVec: COLOR2; 41 44 }; 42 45 … … 44 47 #pragma position_invariant vtx 45 48 46 vtxout vtx(vtxin IN) 49 vtxout vtx(vtxin IN, 50 uniform float4x4 viewMatrix, 51 uniform float4x4 modelMatrix, 52 uniform float4x4 oldModelMatrix) 47 53 { 48 54 vtxout OUT; … … 56 62 OUT.position = mul(glstate.matrix.mvp, IN.position); 57 63 64 // the normal has to be correctly transformed with the inverse transpose 58 65 OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 59 66 67 // transform the old vertex position into world space 68 OUT.worldPos = mul(modelMatrix, IN.position); 69 // transform the old vertex position into world space 70 OUT.oldWorldPos = mul(oldModelMatrix, IN.position); 71 60 72 return OUT; 61 73 } … … 79 91 // save world space normal in rt => transform back into world space by 80 92 // 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); 93 // multiply with the inverse transpose of T, we multiple with 94 // Transp(Inv(Inv(view))) = Transp(view) 95 pix.norm = mul(transpose(viewMatrix), IN.normal).xyz; 83 96 // compute eye linear depth 84 97 pix.col.w = length(IN.eyePos.xyz); 98 85 99 // the scene entity id 86 pix.id = glstate.fog.color.xyz; 87 //pix.id = float3(1,1,1); 100 //pix.id = glstate.fog.color.xyz; 101 // the offset to the world pos from old frame 102 pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; 88 103 89 104 return pix; … … 99 114 // multiplying with inverse view. since transforming normal with T means to 100 115 // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 101 pix.norm = mul(transpose(viewMatrix), IN.normal) ;116 pix.norm = mul(transpose(viewMatrix), IN.normal).xyz; 102 117 // eye space depth 103 118 pix.col.w = length(IN.eyePos.xyz); 104 119 // the scene entity id 105 pix.id = glstate.fog.color.xyz; 106 120 //pix.id = glstate.fog.color.xyz; 121 // the offset to the world pos from old frame 122 pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; 123 107 124 return pix; 108 125 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3112 r3113 124 124 float2 texcoord0, 125 125 float3 oldEyePos, 126 uniformsampler2D oldTex,127 uniformfloat4x4 oldModelViewProj,128 uniformfloat temporalCoherence,129 uniformsampler2D colors,130 uniformfloat3 bl,131 uniformfloat3 br,132 uniformfloat3 tl,133 uniformfloat3 tr,126 sampler2D oldTex, 127 float4x4 oldModelViewProj, 128 float temporalCoherence, 129 sampler2D colors, 130 float3 bl, 131 float3 br, 132 float3 tl, 133 float3 tr, 134 134 float3 projPos, 135 135 float invW, 136 float4x4 inverseModelTrafos[2], 137 float id, 138 uniform sampler2D noiseTex, 139 uniform float2 samples[NUM_SAMPLES], 136 sampler2D noiseTex, 137 float2 samples[NUM_SAMPLES], 140 138 float scaleFactor, 141 uniform float3 oldbl, 142 uniform float3 oldbr, 143 uniform float3 oldtl, 144 uniform float3 oldtr 139 float3 oldbl, 140 float3 oldbr, 141 float3 oldtl, 142 float3 oldtr, 143 float3 diffVec 145 144 ) 146 145 { 147 146 float4 illum_col; 148 147 149 150 //////////// 151 //-- dynamic objects 152 /*float4x4 dummy; 153 uniform mat4 ident = float4x4(1); 154 x = dot(vec, ident[n]); 155 */ 156 float4x4 dummyTrafo = inverseModelTrafos[(int)id]; 157 //float4x4 trafo = (id < 10.0f) ? oldModelViewProj : mul(oldModelViewProj, inverseModelTrafo); 158 float4x4 trafo = mul(oldModelViewProj, dummyTrafo); 159 160 // compute translational portion 161 const float3 translatedPt = worldPos.xyz - oldEyePos; 148 // compute position from old frame for dynamic objects + translational portion 149 const float3 translatedPt = worldPos.xyz - oldEyePos + diffVec; 162 150 163 151 … … 166 154 167 155 // note: the old model view matrix only holds the view orientation part 168 float4 backProjPos = mul( trafo, float4(translatedPt, 1.0f));156 float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f)); 169 157 backProjPos /= backProjPos.w; 170 158 … … 256 244 257 245 illum_col.z = invW; 258 //illum_col. y = depthDif;246 //illum_col.x = length(diffVec*50.0f); 259 247 260 248 return illum_col; … … 356 344 uniform float3 oldtl, 357 345 uniform float3 oldtr, 358 uniform sampler2D attribsTex, 359 uniform float4x4 inverseModelTrafos[2] 346 uniform sampler2D attribsTex 360 347 ) 361 348 { … … 386 373 387 374 375 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 376 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 377 388 378 ///////////////// 389 //-- compute temporally smoothing 390 391 float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 379 //-- compute temporal reprojection 392 380 393 381 OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos, … … 397 385 projPos.xyz, 398 386 invw, 399 inverseModelTrafos,400 id.z,401 387 noiseTex, 402 388 samples, 403 389 scaleFactor, 404 oldbl, oldbr, oldtl, oldtr); 390 oldbl, oldbr, oldtl, oldtr, 391 diffVec); 405 392 406 393 //OUT.illum_col.xyz = id;
Note: See TracChangeset
for help on using the changeset viewer.