Changeset 3089 for GTP/trunk/App/Demos
- Timestamp:
- 11/03/08 01:57:25 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r3076 r3089 169 169 170 170 #endif 171 geom->mVertices[i].x += 470.398f; 172 geom->mVertices[i].y += 240.364f; 173 geom->mVertices[i].z += 182.5f; 174 171 175 if (i < geom->mTexcoordCount) 172 176 { … … 238 242 while (fgets(str, len, file) != NULL) 239 243 { 240 if (1)//(line % 100) == 0)241 cout << "read line " << line << " " << str;244 // if (1)//(line % 100) == 0) 245 // cout << "read line " << line << " " << str; 242 246 switch (str[0]) 243 247 { … … 342 346 //-- texture 343 347 344 int texId = -1;345 //int texId = 0;348 //int texId = -1; 349 int texId = 0; 346 350 str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 347 351 … … 386 390 //-- write textures 387 391 388 //int textureCount = 1;389 int textureCount = 0;392 int textureCount = 1; 393 //int textureCount = 0; 390 394 391 395 ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); … … 401 405 ofile.write(texName.c_str(), sizeof(char) * texnameSize); 402 406 403 int boundS = 1; 404 int boundT = 1; 407 int boundS = 1, boundT = 1; 405 408 406 409 ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int)); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3088 r3089 143 143 p->Bind(); 144 144 145 // interpolate the view vector 145 146 Vector3 bl = mCornersView[0]; 146 147 Vector3 br = mCornersView[1]; … … 153 154 glBegin(GL_QUADS); 154 155 155 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f);156 /*glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 156 157 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 157 158 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs, offs, -0.5f); 158 159 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs, offs, -0.5f); 160 161 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex2f(-offs, -offs); 162 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex2f(offs, -offs); 163 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex2f(offs, offs); 164 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex2f(-offs, offs); 165 */ 166 glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex2f(0, 0); 167 glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex2f(1, 0); 168 glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex2f(1, 1); 169 glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex2f(0, 1); 159 170 160 171 glEnd(); … … 427 438 mIllumFboIndex = 2 - mIllumFboIndex; 428 439 429 440 // enable fragment shading 430 441 ShaderManager::GetSingleton()->EnableFragmentProfile(); 431 442 … … 436 447 glDisable(GL_DEPTH_TEST); 437 448 438 glPushAttrib(GL_VIEWPORT_BIT); 439 glViewport(0, 0, mWidth, mHeight); 449 glPolygonMode(GL_FRONT, GL_FILL); 440 450 441 451 glMatrixMode(GL_PROJECTION); … … 444 454 445 455 const float offs = 0.5f; 446 glOrtho(-offs, offs, -offs, offs, 0, 1); 456 //glOrtho(-offs, offs, -offs, offs, 0, 1); 457 //glOrtho(0, 1, 0, 1, 0, 1); 458 gluOrtho2D(0, 1, 0, 1); 459 447 460 448 461 glMatrixMode(GL_MODELVIEW); 449 462 glPushMatrix(); 450 463 glLoadIdentity(); 464 465 466 glPushAttrib(GL_VIEWPORT_BIT); 467 glViewport(0, 0, mWidth, mHeight); 451 468 452 469 if (shadowMap) … … 497 514 glPopMatrix(); 498 515 516 // viewport 499 517 glPopAttrib(); 500 518 … … 591 609 glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom 592 610 593 glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 611 //glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 612 glVertex2f(x, y); 594 613 } 595 614 … … 608 627 609 628 sCgAntiAliasingProgram->Bind(); 610 611 glColor3f(1.0f, 1.0f, 1.0f);612 629 613 630 glBegin(GL_QUADS); … … 762 779 poisson.Generate((float *)filterOffsets); 763 780 764 const float filterWidth = 10.0f; 781 //const float filterWidth = 10.0f; 782 const float filterWidth = 7.0f; 765 783 const float xoffs = filterWidth / fbo->GetWidth(); 766 784 const float yoffs = filterWidth / fbo->GetHeight(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r3085 r3089 37 37 38 38 const Vector3 pos = GetWorldCenter(); 39 40 39 const float dist = SqrDistance(pos, viewPoint); 41 40 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r3062 r3089 176 176 glLoadIdentity(); 177 177 178 glOrtho( +xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z);178 glOrtho(xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z); 179 179 180 180 glMatrixMode(GL_MODELVIEW); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r3074 r3089 22 22 void Transform3::Load(RenderState *state) 23 23 { 24 if (mIsIdentity) return; 25 26 glPushMatrix(); 27 glMultMatrixf((float *)mMatrix.x); 24 if (!mIsIdentity) 25 { 26 glPushMatrix(); 27 glMultMatrixf((float *)mMatrix.x); 28 } 28 29 } 29 30 … … 31 32 void Transform3::Unload(RenderState *state) 32 33 { 33 if (mIsIdentity) return; 34 glPopMatrix(); 34 if (!mIsIdentity) 35 { 36 glPopMatrix(); 37 } 35 38 } 36 39 … … 40 43 mIsIdentity = false; 41 44 mMatrix = mMatrix * trafo; 42 //mMatrix = trafo * mMatrix;43 45 } 44 46 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3085 r3089 459 459 460 460 LoadModel("hbuddha.dem", dynamicObjects); 461 //LoadModel("hbuddha2.dem", dynamicObjects); 461 462 buddha = dynamicObjects.back(); 462 463 463 464 const Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 465 464 466 Matrix4x4 transl = TranslationMatrix(sceneCenter); 465 467 buddha->GetTransform()->SetMatrix(transl); … … 938 940 939 941 glEnable(GL_MULTISAMPLE_ARB); 940 941 942 state.SetRenderTechnique(FORWARD); 942 glEnable(GL_LIGHTING);943 //glEnable(GL_LIGHTING); 943 944 944 945 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 950 951 glDisable(GL_MULTISAMPLE_ARB); 951 952 state.SetUseAlphaToCoverage(false); 952 953 953 state.SetRenderTechnique(DEPTH_PASS); 954 954 … … 967 967 968 968 glEnable(GL_MULTISAMPLE_ARB); 969 970 969 state.SetRenderTechnique(DEPTH_PASS); 971 970 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3088 r3089 6 6 //-- ssao + gi parameters 7 7 8 //#define NUM_SAMPLES 89 #define NUM_SAMPLES 168 #define NUM_SAMPLES 8 9 //#define NUM_SAMPLES 16 10 10 11 11 // for quadratic falloff … … 43 43 44 44 #define MIN_DEPTH_DIFF 1e-2f 45 #define PRECISION_SCALE 1e- 1f45 #define PRECISION_SCALE 1e-2f 46 46 47 47 // burnout -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3087 r3089 33 33 uniform float4 color, 34 34 uniform float3 normal, 35 uniform float emmisive,36 35 float3 lightDir) 37 36 { … … 49 48 // hack: prevent shading the sky 50 49 if (color.w > 1e19f) outColor = color; 51 //if (emmisive > 1.5f) outColor = color;52 50 else outColor = (ambient + diffuse) * color; 53 51 … … 70 68 float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 71 69 72 73 // an ambient color term74 float amb = color.w;75 70 float3 normal = normalize(norm.xyz); 76 float4 col = shade(IN, color, normal, amb,lightDir);71 float4 col = shade(IN, color, normal, lightDir); 77 72 78 73 OUT.color = col; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r3084 r3089 42 42 43 43 44 #pragma position_invariant vtx44 //#pragma position_invariant vtx 45 45 46 46 vtxout vtx(vtxin IN) … … 61 61 } 62 62 63 #pragma position_invariant fragtex64 63 65 64 pixel fragtex(fragin IN, … … 91 90 92 91 93 #pragma position_invariant frag94 95 92 pixel frag(fragin IN, uniform float4x4 viewMatrix) 96 93 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3088 r3089 54 54 float3 bl, float3 br, float3 tl, float3 tr) 55 55 { 56 const float eyeSpaceDepth = tex2D (tex, texcoord).w;56 const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 57 57 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 58 58 float3 samplePos = -viewVec * eyeSpaceDepth; … … 80 80 uniform float3 oldbr, 81 81 uniform float3 oldtl, 82 uniform float3 oldtr 83 // float dummy382 uniform float3 oldtr, 83 float3 worldPos 84 84 ) 85 85 { … … 87 87 88 88 const float2 offsetTransformed = myreflect(offset, mynoise); 89 const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 89 float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 90 //texCoord.x += 0.5f / 1024.0f; texCoord.y += 0.5f / 768.0f; 90 91 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos; 91 92 … … 95 96 96 97 // fit from unit cube into 0 .. 1 97 const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; 98 98 float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; 99 99 // retrieve the sample from the last frame 100 float4 oldCol = tex2D (oldTex, oldTexCoords);101 102 float oldEyeSpaceDepth = oldCol.w; // dummy3;100 float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 101 102 float oldEyeSpaceDepth = oldCol.w; 103 103 float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 104 104 float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 105 105 106 106 float dDiff = length(oldSamplePos - samplePos.xyz); 107 108 if (length(worldPos.xyz - samplePos.xyz) > 5.0f) 109 dDiff = .0f; 107 110 108 111 return dDiff; … … 150 153 151 154 // retrieve the sample from the last frame 152 //float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 153 float4 oldCol = tex2D(oldTex, oldTexCoords); 154 155 //eyeSpaceDepth = 1e6f; 156 157 //const float dummy3 = 1e-4f; 158 //const float oldEyeSpaceDepth = 1e5f * dummy3; 159 //const float oldEyeSpaceDepth = oldCol.z / dummy3; 155 float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 156 //float4 oldCol = tex2D(oldTex, oldTexCoords); 157 160 158 const float oldEyeSpaceDepth = oldCol.w; 161 162 159 //oldTexCoords.x += 0.5f / 1024.0f; oldTexCoords.y += 0.5f / 768.0f; 163 160 … … 166 163 float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 167 164 168 //const float oldDepth = oldCol.z;169 165 const float depthDif = length(oldSamplePos - worldPos.xyz); 170 //eyeSpaceDepth *= dummy3; 171 172 //const float depthDif = abs(oldEyeSpaceDepth - eyeSpaceDepth);// * 1e4f; 173 //const float depthDif = abs(oldEyeSpaceDepth - dummy2) * 1e3f; 174 175 //const float oldNumSamples = oldCol.y; 176 const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence); 177 float newWeight; 178 179 bool isValid = true; 166 167 float notValid = 0.5f; 180 168 181 169 for (int i = 0; i < NUM_SAMPLES; ++ i) 182 170 { 183 float sampleDif 171 float sampleDif = ComputeDifference(samples[i], 184 172 oldTex, 185 173 oldModelViewProj, … … 191 179 eyePos, 192 180 oldEyePos, 193 oldbl, oldbr, oldtl, oldtr 194 //,dummy3195 ); 196 197 //if (sampleDif > 1e-1f) isValid = false;198 } 199 181 oldbl, oldbr, oldtl, oldtr, 182 worldPos.xyz); 183 184 if (sampleDif >= 1e-1f) ++ notValid; 185 } 186 187 //if (notValid < 1.0f) temporalCoherence = 4.0f; 200 188 // the number of valid samples in this frame 201 189 //const float newNumSamples = ao.y; 190 191 //const float oldNumSamples = oldCol.y; 192 const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence); 193 float newWeight; 202 194 203 195 if ((temporalCoherence > 1e-6f) … … 207 199 // if visibility changed in the surrounding area we have to recompute 208 200 //&& (oldNumSamples > 0.8f * newNumSamples) 209 && isValid201 //&& (notValid < 1.0f) 210 202 ) 211 203 { … … 213 205 newWeight = oldWeight + 1.0f; 214 206 illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 215 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0;207 if (notValid > 1.0f) newWeight = 2; 216 208 } 217 209 else … … 221 213 } 222 214 223 //illum_col.x = depthDif;224 225 //isValid = 0.0f;226 //illum_col.y = isValid / 16.0f;227 215 illum_col.y = newWeight; 228 216 illum_col.w = eyeSpaceDepth; 229 //illum_col.z = dummy2; 230 217 231 218 return illum_col; 232 219 } … … 291 278 // the distance_scale offset is used to avoid singularity that occurs at global illumination when 292 279 // the distance to a sample approaches zero 280 const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample); 293 281 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 294 const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);295 282 296 283 #if 1 … … 338 325 // reconstruct position from the eye space depth 339 326 const float3 viewDir = IN.view; 340 const float eyeSpaceDepth = tex2D (colors, IN.texCoord).w;327 const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 341 328 const float3 eyeSpacePos = -viewDir * eyeSpaceDepth; 342 329 const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); … … 399 386 float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 400 387 401 //if (ao.y < 10.0f) 402 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 403 404 //OUT.illum_col = col * ao.x; 405 OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 388 if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 389 390 OUT.illum_col = col * ao.x; 391 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 406 392 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 407 393 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
Note: See TracChangeset
for help on using the changeset viewer.