Changeset 3115 for GTP/trunk/App/Demos
- Timestamp:
- 11/10/08 18:43:06 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3066 r3115 12 12 camPosition=483.398f 242.364f 186.078f 13 13 camDirection=1 0 0 14 lightDirection=-0.8f 1.0f -0.7f 14 #lightDirection=-0.8f 1.0f -0.7f 15 lightDirection=-0.3f 0.2f -0.7f 15 16 #lightDirection=0.0f 0.0f -1.0f 16 17 useFullScreen=0 … … 24 25 25 26 # ssao temporal coherence factor 26 tempCohFactor= 50.0f27 27 tempCohFactor=100.0f 28 # tone mapping 28 29 useHDR=0 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3113 r3115 259 259 //-- the flip-flop fbos 260 260 261 const int dsw = w / 2; 262 const int dsh = h / 2; 263 264 //const int dsw = w; 265 //const int dsh = h; 261 const int dsw = w / 2; const int dsh = h / 2; 262 //const int dsw = w; const int dsh = h; 266 263 267 264 mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3114 r3115 168 168 { 169 169 tech->SetVertexProgram(sTreeAnimationProgramMrt); 170 vtxParams->SetOldTimerParam(5); 170 171 } 171 172 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
r3114 r3115 17 17 18 18 static float sCurrentTimer = 0; 19 static float sOldTimer = 0; 19 20 static Matrix4x4 sCurrentViewMatrix = IdentityMatrix(); 20 21 static Vector3 sCurrentViewDir = Vector3::UNIT_Y(); … … 158 159 { 159 160 mTimerParam = idx; 161 } 162 163 164 void GPUProgramParameters::SetOldTimerParam(int idx) 165 { 166 mOldTimerParam = idx; 160 167 } 161 168 … … 318 325 if (mTimerParam >= 0) 319 326 mProgram->SetValue1f(mTimerParam, sCurrentTimer); 320 327 if (mOldTimerParam >= 0) 328 mProgram->SetValue1f(mOldTimerParam, sOldTimer); 321 329 if (mViewDirParam >= 0) 322 330 mProgram->SetValue3f(mViewDirParam, sCurrentViewDir.x, sCurrentViewDir.y, sCurrentViewDir.z); … … 339 347 { 340 348 static PerfTimer mytimer; 349 sOldTimer = sCurrentTimer; 341 350 sCurrentTimer = mytimer.Elapsedms(false) * M_PI / 180.0f; 342 351 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3114 r3115 72 72 */ 73 73 void SetTimerParam(int idx); 74 75 void SetOldTimerParam(int idx); 74 76 /** This parameter is connected to the current view matrix 75 77 that is updated once per frame. … … 195 197 196 198 int mTimerParam; 199 int mOldTimerParam; 197 200 int mViewDirParam; 198 201 int mLightDirParam; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r3114 r3115 41 41 mIsIdentity = false; 42 42 mOldMatrix = mMatrix; 43 mMatrix = mMatrix * trafo;43 mMatrix = trafo * mMatrix; 44 44 } 45 45 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3114 r3115 905 905 buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); 906 906 907 static Matrix4x4 oldTrafo; 908 909 oldTrafo = buddha->GetTransform()->GetMatrix(); 910 //vtxParams->SetMatrix(2, oldTrafo); 911 907 Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix(); 912 908 Vector3 buddhaPos = motionPath->GetCurrentPosition(); 913 909 Matrix4x4 trafo = TranslationMatrix(buddhaPos); … … 915 911 buddha->GetTransform()->SetMatrix(trafo); 916 912 917 //vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix()); 913 Matrix4x4 rotMatrix = RotationZMatrix(M_PI * 1e-3f); 914 915 dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 918 916 919 917 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3108 r3115 21 21 22 22 //#define ILLUM_INTENSITY 8e-2f 23 #define ILLUM_INTENSITY 2e-2f23 #define ILLUM_INTENSITY 5e-3f 24 24 25 25 #define VIEW_CORRECTION_SCALE 1.0f … … 29 29 //-- reprojection 30 30 31 #define MIN_DEPTH_DIFF 5e-2f31 #define MIN_DEPTH_DIFF 2e-2f 32 32 #define PRECISION_SCALE 1e-1f 33 33 … … 58 58 59 59 //#define NUM_SSAO_FILTERSAMPLES 28 60 #define NUM_SSAO_FILTERSAMPLES 40 60 //#define NUM_SSAO_FILTERSAMPLES 40 61 #define NUM_SSAO_FILTERSAMPLES 100 61 62 62 63 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3114 r3115 66 66 67 67 inline float ComputeDifference(float2 offset, 68 uniformsampler2D oldTex,69 const uniformfloat4x4 oldModelViewProj,70 uniformsampler2D colors,71 uniformsampler2D noiseTex,72 uniformfloat scaleFactor,73 uniformfloat3 bl,74 uniformfloat3 br,75 uniformfloat3 tl,76 uniformfloat3 tr,68 sampler2D oldTex, 69 float4x4 oldModelViewProj, 70 sampler2D colors, 71 sampler2D noiseTex, 72 float scaleFactor, 73 float3 bl, 74 float3 br, 75 float3 tl, 76 float3 tr, 77 77 float2 texcoord0, 78 78 float3 oldEyePos, 79 uniformfloat3 oldbl,80 uniformfloat3 oldbr,81 uniformfloat3 oldtl,82 uniformfloat3 oldtr,79 float3 oldbl, 80 float3 oldbr, 81 float3 oldtl, 82 float3 oldtr, 83 83 float eyeSpaceDepth 84 84 ) 85 85 { 86 const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy;86 const float2 mynoise = tex2Dlod(noiseTex, float4(texcoord0, 0, 0)).xy; 87 87 88 88 const float2 offsetTransformed = myreflect(offset, mynoise); … … 93 93 const float3 viewVec = Interpol(texCoord, bl, br, tl, tr); 94 94 const float3 samplePos = -viewVec * sampleEyeSpaceDepth; 95 96 95 const float3 translatedPos = samplePos - oldEyePos; 96 97 97 // reproject into old frame and calculate projected depth 98 98 float4 projPos = mul(oldModelViewProj, float4(translatedPos, 1.0f)); 99 99 projPos /= projPos.w; 100 101 100 // fit from unit cube into 0 .. 1 102 101 const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; … … 105 104 106 105 const float oldEyeSpaceDepth = oldPixel.w; 106 107 // projected linear depth 107 108 const float3 oldViewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 108 109 109 const float invlen = 1.0f / length(oldViewVec); 110 const float projectedEyeSpaceDepth = length(translatedPos) * invlen;111 112 float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 113 0 : abs(oldEyeSpaceDepth -projectedEyeSpaceDepth);110 const float projectedEyeSpaceDepth = invlen * length(translatedPos); 111 112 float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 0 : 113 abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 114 114 115 115 return depthDif; … … 117 117 118 118 119 /** This shader computes the reprojection and stores reprojected color / depth values120 as well as a boolean that119 /** This shader computes the reprojection and stores 120 reprojected color / depth values as well as a boolean that 121 121 */ 122 122 inline float4 temporalSmoothing(float4 worldPos, … … 148 148 149 149 // compute position from old frame for dynamic objects + translational portion 150 const float3 translatedP t= worldPos.xyz - oldEyePos + diffVec;150 const float3 translatedPos = worldPos.xyz - oldEyePos + diffVec; 151 151 152 152 … … 155 155 156 156 // note: the old model view matrix only holds the view orientation part 157 float4 backProjPos = mul(oldModelViewProj, float4(translatedP t, 1.0f));157 float4 backProjPos = mul(oldModelViewProj, float4(translatedPos, 1.0f)); 158 158 backProjPos /= backProjPos.w; 159 159 … … 172 172 const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 173 173 const float invLen = 1.0f / length(viewVec); 174 const float projectedEyeSpaceDepth = invLen * length(translatedPt); 175 176 //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 174 const float projectedEyeSpaceDepth = invLen * length(translatedPos); 175 177 176 const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 178 //const float depthDif = abs(projectedEyeSpaceDepth - oldEyeSpaceDepth ) / projectedEyeSpaceDepth;179 177 180 178 #else … … 182 180 const float oldDepth = oldPixel.w; 183 181 const float projectedDepth = projPos.z; 184 //const float projectedDepth = invW * worldPos.z;185 186 182 // vector from eye pos to old sample 187 183 const float depthDif = abs(projectedDepth - oldDepth); … … 189 185 190 186 float notValid = 0.5f; 191 192 /* 193 for (int i = 0; i < NUM_SAMPLES; ++ i) 187 //float overallDepth = 0; 188 const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 189 190 if (squaredLen < 1e-8f) // object not dynamic 194 191 { 195 float sampleDif = ComputeDifference(samples[i], 196 oldTex, 197 oldModelViewProj, 198 colors, 199 noiseTex, 200 scaleFactor, 201 bl, br, tl, tr, 202 texcoord0, 203 oldEyePos, 204 oldbl, oldbr, oldtl, oldtr, 205 eyeSpaceDepth); 206 207 if (sampleDif >= 5e-2f) ++ notValid; 208 } 209 */ 192 for (int i = 0; i < NUM_SAMPLES; ++ i) 193 { 194 float sampleDif = ComputeDifference(samples[i], 195 oldTex, 196 oldModelViewProj, 197 colors, 198 noiseTex, 199 scaleFactor, 200 bl, br, tl, tr, 201 texcoord0, 202 oldEyePos, 203 oldbl, oldbr, oldtl, oldtr, 204 eyeSpaceDepth 205 ); 206 //overallDepth += sampleDif; 207 208 if (sampleDif >= MIN_DEPTH_DIFF) ++ notValid; 209 } 210 } 211 210 212 211 213 // the number of valid samples in this frame … … 243 245 illum_col.w = projectedDepth; 244 246 #endif 245 247 //overallDepth = clamp(overallDepth*1e3, 0, 1); 246 248 illum_col.z = invW; 247 //illum_col.x = length(diffVec*50.0f);249 //illum_col.x = overallDepth; 248 250 249 251 return illum_col; … … 370 372 // note: this should be done with the stencil buffer 371 373 if (eyeSpaceDepth < 1e10f) 374 { 372 375 ao = ssao(IN, colors, noiseTex, samples, normal, 373 376 eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir)); 374 377 } 375 378 376 379 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; … … 409 412 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 410 413 { 411 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale , 0, 0)).x;414 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x; 412 415 w += filterWeights[i]; 413 416 } … … 434 437 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z); 435 438 436 //OUT.illum_col = col * ao.x;439 OUT.illum_col = col * ao.x; 437 440 //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 438 441 //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 439 OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);442 //OUT.illum_col = float4(ao.x, 0, 0, col.w); 440 443 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 441 444 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
r3046 r3115 10 10 11 11 float4 color: COLOR; 12 //float4 color1: COLOR1;13 14 12 float4 texCoord: TEXCOORD0; 15 13 }; … … 21 19 float4 texCoord: TEXCOORD0; 22 20 23 float4 color: COLOR0; 24 // float4 color1: COLOR1;25 float4 eyePos: TEXCOORD1; // eye position21 float4 color: COLOR0; 22 // eye position 23 float4 eyePos: TEXCOORD1; 26 24 float4 normal: TEXCOORD2; 25 26 float4 worldPos: TEXCOORD3; 27 float4 oldWorldPos: TEXCOORD4; 27 28 }; 28 29 … … 54 55 const float3 l = normalize(lightDir); 55 56 56 const float dif = max(.0f, dot(OUT.normal.xyz, l));57 const float diffuse = max(.0f, dot(OUT.normal.xyz, l)); 57 58 58 59 //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 = glstate.material.ambient + glstate.material.front.diffuse * diffuse; 60 61 OUT.color.w = IN.color.w; 61 62 return OUT; … … 72 73 uniform float frequency, 73 74 uniform float2 minMaxPos, 74 uniform float timer) 75 uniform float timer, 76 uniform float oldTimer 77 //uniform float4x4 modelMatrix, 78 //uniform float4x4 oldModelMatrix 79 ) 75 80 { 76 81 vtxout OUT; … … 82 87 float factor = pos * pos * windStrength * sin(timer * frequency); 83 88 89 const float4 offs = float4(factor * windDir, 0); 90 84 91 // transform the vertex position into post projection space 85 92 OUT.position = mul(glstate.matrix.mvp, IN.position); 86 93 // displace the input position 87 OUT.position += float4(factor * windDir, 0);94 OUT.position += offs; 88 95 89 96 // transform the vertex position into eye space 90 97 OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position); 91 OUT.eyePos += float4(factor * windDir, 0);98 OUT.eyePos += offs; 92 99 93 100 OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 94 101 102 // hack: no translational component anyway 103 OUT.oldWorldPos = float4(.0f); 104 OUT.worldPos = offs; 105 95 106 return OUT; 96 107 }
Note: See TracChangeset
for help on using the changeset viewer.