Changeset 3146 for GTP/trunk/App/Demos
- Timestamp:
- 11/20/08 10:12:28 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r3128 r3146 7 7 8 8 using namespace std; 9 10 //#define USE_TEXTURE 9 11 10 12 … … 18 20 ) 19 21 { 20 vector< char *> substrings;22 vector<string> triples; 21 23 22 24 char *next_token; … … 25 27 char *pch = strtok_s(str + 1, " ", &next_token); 26 28 27 while (pch != NULL) 28 { 29 substrings.push_back(pch); 29 while (pch) 30 { 31 string s(pch); 32 //s += "\n", 33 triples.push_back(s); 34 30 35 pch = strtok_s(NULL, " ", &next_token); 31 36 } … … 35 40 vector<int> tIndices; 36 41 37 for (size_t i = 0; i < substrings.size(); ++ i) 38 { 42 char seps[] = " /\t\n"; 43 44 for (size_t i = 0; i < triples.size(); ++ i) 45 { 46 static int dummy = 0; 47 48 size_t found; 49 found = triples[i].find_first_of(seps); 50 size_t prevfound = 0; 39 51 // vertex, normal, texture indices 40 char *str = strtok_s(substrings[i], "/", &next_token); 41 int index = (int)strtol(str, NULL, 10) - 1; 52 string str = triples[i].substr(prevfound, found); 53 54 int index = (int)strtol(str.c_str(), NULL, 10) - 1; 42 55 43 56 int tIndex = index; 44 int nIndex = index; 45 46 str = strtok_s(substrings[i], "/", &next_token); 47 48 if (str != NULL) 49 { 50 int idx = (int)strtol(str, NULL, 10) - 1; 51 if (idx) tIndex = idx; 52 } 53 str = strtok_s(substrings[i], "/", &next_token); 54 55 if (str != NULL) 56 { 57 int idx = (int)strtol(str, NULL, 10) - 1; 58 if (idx) nIndex = idx; 57 int nIndex = index; 58 59 prevfound = found; 60 found = triples[i].find_first_of(seps, found + 1); 61 62 if (found != string::npos) 63 { 64 str = triples[i].substr(prevfound, found); 65 66 int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 67 if (idx > 0) tIndex = idx; 68 } 69 70 if ((found + 1) < triples[i].size()) 71 { 72 str = triples[i].substr(found + 1); 73 74 int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 75 if (idx > 0) nIndex = idx; 59 76 } 60 77 … … 84 101 faceVertices.push_back(vertices[indices[idx3]]); 85 102 103 86 104 if (!normals.empty()) 87 105 { 106 //if (dummy < 3) cout << nIndices[idx1] << " " << nIndices[idx2] << " " << nIndices[idx3] << endl; 88 107 faceNormals.push_back(normals[nIndices[idx1]]); 89 108 faceNormals.push_back(normals[nIndices[idx2]]); … … 92 111 else 93 112 { 94 // no face normals? 95 const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]); 113 // no face normals? => create normals 114 const SimpleTri tri(vertices[indices[idx1]], 115 vertices[indices[idx2]], 116 vertices[indices[idx3]]); 96 117 const SimpleVec n = tri.GetNormal(); 97 118 … … 101 122 } 102 123 124 ++ dummy; 103 125 if (!texcoords.empty()) 104 126 { … … 150 172 for (int i = 0; i < numElements; ++ i) 151 173 { 152 #if 0174 #if 1 153 175 // convert to our camera system: change y and z 154 176 geom->mVertices[i].x = faceVertices[i].x; … … 159 181 geom->mNormals[i].y = -faceNormals[i].z; 160 182 geom->mNormals[i].z = faceNormals[i].y; 183 161 184 #else 162 185 geom->mVertices[i].x = faceVertices[i].x; … … 169 192 170 193 #endif 171 geom->mVertices[i].x += 470.398f;172 geom->mVertices[i].y += 240.364f;173 geom->mVertices[i].z += 182.5f;174 194 175 195 if (i < geom->mTexcoordCount) … … 236 256 237 257 int line = 0; 238 239 258 const int len = 10000; 240 259 char str[len]; … … 242 261 while (fgets(str, len, file) != NULL) 243 262 { 244 // if (1)//(line % 100) == 0) 245 // cout << "read line " << line << " " << str; 246 switch (str[0]) 263 switch (str[0]) 247 264 { 248 265 case 'v': // vertex or normal … … 262 279 default: 263 280 sscanf(str + 1, "%f %f %f", &x, &y, &z); 264 vertices.push_back(SimpleVec(x, y, z)); 281 const float scale = 5e-3f; 282 vertices.push_back(SimpleVec(x * scale, y * scale, z* scale)); 265 283 //cout <<"v " << x << " " << y << " "<< z << " "; 266 284 } … … 305 323 break; 306 324 default: 325 // throw away line 307 326 break; 308 327 } … … 346 365 //-- texture 347 366 348 //int texId = -1; 367 #ifdef USE_TEXTURE 349 368 int texId = 0; 369 #else 370 int texId = -1; 371 #endif 372 350 373 str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 351 374 352 375 bool alphaTestEnabled = false; 353 bool cullFaceEnabled = false;354 //bool cullFaceEnabled = true;376 //bool cullFaceEnabled = false; 377 bool cullFaceEnabled = true; 355 378 356 379 str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); … … 368 391 ambient.x = ambient.y = ambient.z = 0.2f; 369 392 diffuse.x = diffuse.y = diffuse.z = 1.0f; 370 spec.x = spec.y = spec.z= .0f;393 spec.x = spec.y = spec.z = .0f; 371 394 emm = spec; 372 395 … … 391 414 //-- write textures 392 415 416 #ifdef USE_TEXTURE 393 417 int textureCount = 1; 394 //int textureCount = 0; 395 418 #else 419 int textureCount = 0; 420 #endif 396 421 ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); 397 422 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp
r3076 r3146 22 22 exit(0); 23 23 } 24 24 //std::cin.get(); 25 25 cout << "conversion successful" << endl; 26 26 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
r3128 r3146 147 147 148 148 bool alphaTestEnabled = false; 149 bool cullFaceEnabled = false;150 //bool cullFaceEnabled = true;149 //bool cullFaceEnabled = false; 150 bool cullFaceEnabled = true; 151 151 152 152 str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3127 r3146 267 267 } 268 268 269 if ( frag != mCurrentFragmentProgram)269 if (1)//frag != mCurrentFragmentProgram) 270 270 { 271 271 mCurrentFragmentProgram = frag; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3145 r3146 114 114 // create shape 115 115 Shape *shape = new Shape(geom, mat); 116 117 116 mShapes.push_back(shape); 118 117 … … 226 225 } 227 226 228 227 // mtt todo_ split that up 229 228 void ResourceManager::LoadShapes(igzstream &str) 230 229 { … … 295 294 if (mUseNormalMapping) 296 295 { 297 deferred->SetFragmentProgram(sNormalMapping VertexProgramMrt);296 deferred->SetFragmentProgram(sNormalMappingFragmentProgramMrt); 298 297 deferred->SetVertexProgram(sNormalMappingVertexProgramMrt); 299 298 } … … 310 309 deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0); 311 310 312 313 311 deferred->GetVertexProgramParameters()->SetModelMatrixParam(1); 314 312 deferred->GetVertexProgramParameters()->SetOldModelMatrixParam(2); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp
r3144 r3146 130 130 131 131 132 // provide the current view matrix: 133 // this is an automatic parameter that is updated each frame 134 normalMappingFragmentMrt->AddParameter("viewMatrix", 0); 135 136 // vertex program 137 normalMappingVertexMrt->AddParameter("viewMatrix", 0); 138 // needed for for ssao 139 normalMappingVertexMrt->AddParameter("modelMatrix", 1); 140 normalMappingVertexMrt->AddParameter("oldModelMatrix", 2); 141 142 132 143 cout << "cg initialization successful" << endl; 133 144 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3144 r3146 471 471 //-- load some dynamic stuff 472 472 473 resourceManager->mUseNormalMapping = true;473 //resourceManager->mUseNormalMapping = true; 474 474 //resourceManager->mUseNormalMapping = false; 475 475 476 LoadModel("fisch.dem", dynamicObjects);476 //LoadModel("fisch.dem", dynamicObjects); 477 477 //LoadModel("hbuddha.dem", dynamicObjects); 478 //LoadModel("venusm.dem", dynamicObjects); 479 //LoadModel("objects.dem", dynamicObjects); 480 //LoadModel("toyplane2.dem", dynamicObjects); 481 LoadModel("elephal.dem", dynamicObjects); 478 482 479 483 resourceManager->mUseNormalMapping = false; … … 481 485 buddha = dynamicObjects.back(); 482 486 487 cout << "here3 " << buddha->GetWorldCenter() << " " << buddha->GetBoundingBox().Center() << endl; 488 483 489 const Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 484 490 … … 804 810 ambient[2] = sunAmbient.z; 805 811 806 // no tone mapping => scale807 if (0)//!useToneMapping)808 {809 float maxComponent = sunDiffuse.MaxComponent();810 sunDiffuse /= maxComponent;811 }812 813 812 diffuse[0] = sunDiffuse.x; 814 813 diffuse[1] = sunDiffuse.y; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r3137 r3146 49 49 const float ne = nd.x * nd.y *nd.z * nd.w * weights.x; 50 50 51 #if 1 51 52 52 //////////// 53 53 // depth filter => compute gradient difference … … 65 65 for (int i = 0; i < 4; ++ i) 66 66 { 67 dd[i] = float4(depthVals[i * 2] + depthVals[i * 2 + 1]);67 dd[i] = depthVals[i * 2] + depthVals[i * 2 + 1]; 68 68 } 69 69 … … 89 89 float4 s2 = tex2Dlod(colors, float4(width + rt * w, 0, 0)); 90 90 float4 s3 = tex2Dlod(colors, float4(width + lb * w, 0, 0)); 91 #endif 91 92 92 93 93 //float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; … … 96 96 //float4 col = float4(de.x, de.x, de.x, 0); 97 97 //float4 col = float4(w, w, w, 0); 98 //float4 col = centerColor; 98 //float4 col = float4(centerNormal * 0.5f + float3(0.5f), 0); 99 //float4 col = float4(centerNormal, 0); 99 100 // push through the current depth 100 101 col.w = centerDepth.x; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg
r3144 r3146 86 86 87 87 88 /************************************************************** /89 /* Shader computing the MRT output for normal mapped geoemtry*/90 /************************************************************** /88 /******************************************************************/ 89 /* Shader computing the MRT output for normal mapped geometry */ 90 /******************************************************************/ 91 91 92 92 … … 126 126 // compute tangent space - world space transform which is the transpose, 127 127 // as it is the inverse of a rotation matrix 128 float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent , IN.bitangent, IN.normal));128 float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz)); 129 129 const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz; 130 130 pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm); … … 136 136 pixel frag(fragin IN, 137 137 uniform float4x4 viewMatrix, 138 uniform sampler2D normalMap: TEXUNIT 1)138 uniform sampler2D normalMap: TEXUNIT0) 139 139 { 140 140 pixel pix; 141 141 // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 142 142 pix.color = glstate.material.diffuse + glstate.material.emission; 143 // save world space normal in rt => transform back into world space by 144 // multiplying with inverse view. since transforming normal with T means to 145 // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 146 pix.normal = mul(transpose(viewMatrix), IN.normal).xyz; 143 147 144 // eye space depth 148 145 pix.color.w = length(IN.eyePos.xyz); … … 165 162 const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz; 166 163 pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm); 167 164 pix.normal = tangentSpaceNorm; 168 165 return pix; 169 166 }
Note: See TracChangeset
for help on using the changeset viewer.