Changeset 3235
- Timestamp:
- 12/26/08 02:44:45 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 11 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj
r3107 r3235 98 98 <Configuration 99 99 Name="Release|Win32" 100 OutputDirectory="$(SolutionDir)\ Converter\$(ConfigurationName)"101 IntermediateDirectory="$(ConfigurationName)\ Converter"100 OutputDirectory="$(SolutionDir)\$(ProjectName)\$(ConfigurationName)" 101 IntermediateDirectory="$(ConfigurationName)\$(ProjectName)" 102 102 ConfigurationType="1" 103 103 CharacterSet="1" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
r3212 r3235 17 17 {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023} 18 18 EndProjectSection 19 EndProject 20 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VisibilitySolutionConverter", "VisibilitySolutionConverter.vcproj", "{A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}" 19 21 EndProject 20 22 Global … … 44 46 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win32 45 47 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win32 48 {A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Debug|Win32.ActiveCfg = Debug|Win32 49 {A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Debug|Win32.Build.0 = Debug|Win32 50 {A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Release|Win32.ActiveCfg = Release|Win32 51 {A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Release|Win32.Build.0 = Release|Win32 46 52 EndGlobalSection 47 53 GlobalSection(SolutionProperties) = preSolution -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter.vcproj
r3220 r3235 98 98 <Configuration 99 99 Name="Release|Win32" 100 OutputDirectory="$(SolutionDir)$\ VboFormatConverter\(ConfigurationName)"101 IntermediateDirectory="$(ConfigurationName)\ VboFormatConverter"100 OutputDirectory="$(SolutionDir)$\$(ProjectName)\(ConfigurationName)" 101 IntermediateDirectory="$(ConfigurationName)\$(ProjectName)" 102 102 ConfigurationType="1" 103 103 CharacterSet="1" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
r3234 r3235 1 #include " ObjConverter.h"1 #include "VisibilitySolutionConverter.h" 2 2 #include "SimpleTri.h" 3 3 #include "SimpleVec.h" … … 8 8 using namespace std; 9 9 10 //#define USE_TEXTURE 10 // MAGIC of all bin exports 11 #ifndef MAGIC 12 #define MAGIC 0x827923 13 #endif 14 15 #define BVH_VERSION 2.1 11 16 12 17 … … 14 19 const VertexArray &vertices, 15 20 const VertexArray &normals, 16 const vector<pair<float, float> > &tex coords,21 const vector<pair<float, float> > &texCoords, 17 22 VertexArray &faceVertices, 18 23 VertexArray &faceNormals, 19 vector<Tex coord> &faceTexcoords24 vector<TexCoord> &faceTexCoords 20 25 ) 21 26 { … … 104 109 if (!normals.empty()) 105 110 { 106 //if (dummy < 3) cout << nIndices[idx1] << " " << nIndices[idx2] << " " << nIndices[idx3] << endl;107 111 faceNormals.push_back(normals[nIndices[idx1]]); 108 112 faceNormals.push_back(normals[nIndices[idx2]]); … … 115 119 vertices[indices[idx2]], 116 120 vertices[indices[idx3]]); 121 117 122 const SimpleVec n = tri.GetNormal(); 118 123 … … 122 127 } 123 128 124 ++ dummy; 125 if (!texcoords.empty()) 129 if (!texCoords.empty()) 126 130 { 127 faceTex coords.push_back(texcoords[tIndices[idx1]]);128 faceTex coords.push_back(texcoords[tIndices[idx2]]);129 faceTex coords.push_back(texcoords[tIndices[idx3]]);131 faceTexCoords.push_back(texCoords[tIndices[idx1]]); 132 faceTexCoords.push_back(texCoords[tIndices[idx2]]); 133 faceTexCoords.push_back(texCoords[tIndices[idx3]]); 130 134 } 131 135 } … … 134 138 135 139 136 ObjConverter::ObjConverter()140 VisibilitySolutionConverter::VisibilitySolutionConverter() 137 141 {} 138 142 139 143 140 ObjConverter::~ObjConverter()144 VisibilitySolutionConverter::~VisibilitySolutionConverter() 141 145 { 142 146 for (size_t i = 0; i < mGeometry.size(); ++ i) … … 144 148 delete [] mGeometry[i]->mVertices; 145 149 delete [] mGeometry[i]->mNormals; 146 delete [] mGeometry[i]->mTex coords;150 delete [] mGeometry[i]->mTexCoords; 147 151 148 152 delete mGeometry[i]; … … 153 157 154 158 155 void ObjConverter::LoadShape(const VertexArray &faceVertices,156 const VertexArray &faceNormals,157 const vector<Texcoord> &faceTexcoords)158 { 159 int numElements = (int) faceVertices.size();159 void VisibilitySolutionConverter::LoadShape(const VertexArray &vertices, 160 const VertexArray &normals, 161 const vector<TexCoord> &texCoords) 162 { 163 int numElements = (int)vertices.size(); 160 164 Geometry *geom = new Geometry(); 161 165 … … 163 167 geom->mVertices = new SimpleVec[numElements]; 164 168 geom->mNormals = new SimpleVec[numElements]; 165 geom->mTex coords = new Texcoord[numElements];169 geom->mTexCoords = new TexCoord[numElements]; 166 170 167 171 geom->mVertexCount = numElements; 168 geom->mTexcoordCount = (int) faceTexcoords.size();172 geom->mTexcoordCount = (int)texCoords.size(); 169 173 170 174 cout << "number of vertices=" << numElements << endl; … … 172 176 for (int i = 0; i < numElements; ++ i) 173 177 { 174 #if 0178 #if 1 175 179 // convert to our camera system: change y and z 176 geom->mVertices[i].x = faceVertices[i].x;177 geom->mVertices[i].y = - faceVertices[i].z;178 geom->mVertices[i].z = faceVertices[i].y;179 180 geom->mNormals[i].x = faceNormals[i].x;181 geom->mNormals[i].y = - faceNormals[i].z;182 geom->mNormals[i].z = faceNormals[i].y;180 geom->mVertices[i].x = vertices[i].x; 181 geom->mVertices[i].y = -vertices[i].z; 182 geom->mVertices[i].z = vertices[i].y; 183 184 geom->mNormals[i].x = normals[i].x; 185 geom->mNormals[i].y = -normals[i].z; 186 geom->mNormals[i].z = normals[i].y; 183 187 184 188 #else 185 geom->mVertices[i].x = faceVertices[i].x;186 geom->mVertices[i].y = faceVertices[i].y;187 geom->mVertices[i].z = faceVertices[i].z;188 189 geom->mNormals[i].x = faceNormals[i].x;190 geom->mNormals[i].y = faceNormals[i].y;191 geom->mNormals[i].z = faceNormals[i].z;189 geom->mVertices[i].x = vertices[i].x; 190 geom->mVertices[i].y = vertices[i].y; 191 geom->mVertices[i].z = vertices[i].z; 192 193 geom->mNormals[i].x = normals[i].x; 194 geom->mNormals[i].y = normals[i].y; 195 geom->mNormals[i].z = normals[i].z; 192 196 193 197 #endif … … 195 199 if (i < geom->mTexcoordCount) 196 200 { 197 geom->mTex coords[i].first = faceTexcoords[i].first;198 geom->mTex coords[i].second = faceTexcoords[i].second;201 geom->mTexCoords[i].first = texCoords[i].first; 202 geom->mTexCoords[i].second = texCoords[i].second; 199 203 } 200 204 } … … 204 208 205 209 206 bool ObjConverter::Convert(const string &filename, const std::string &outputFilename) 210 bool VisibilitySolutionConverter::Convert(const std::string &sceneInputFilename, 211 const std::string &sceneOutputFilename, 212 const std::string &bvhInputFilename, 213 const std::string &bvhOutputFilename) 207 214 { 208 215 mNumShapes = 0; 209 216 217 // delete previous geometry 210 218 for (size_t i = 0; i < mGeometry.size(); ++ i) 211 219 { 212 220 delete [] mGeometry[i]->mVertices; 213 221 delete [] mGeometry[i]->mNormals; 214 delete [] mGeometry[i]->mTex coords;222 delete [] mGeometry[i]->mTexCoords; 215 223 216 224 delete mGeometry[i]; … … 219 227 mGeometry.clear(); 220 228 221 if (! ReadFile(filename))229 if (!LoadSolution(bvhInputFilename)) 222 230 { 223 231 cerr << "could not read file" << endl; … … 225 233 } 226 234 227 if (!WriteFile(outputFilename)) 235 if (!ReadScene(sceneInputFilename)) 236 { 237 cerr << "could not read file" << endl; 238 return false; 239 } 240 241 if (!WriteScene(sceneOutputFilename)) 228 242 { 229 243 cerr << "could not write file" << endl; … … 231 245 } 232 246 247 /*if (!WriteBvh(bvhOutputFilename)) 248 { 249 cerr << "could not write file" << endl; 250 return false; 251 }*/ 233 252 234 253 return true; … … 236 255 237 256 238 bool ObjConverter::ReadFile(const string &filename)257 bool VisibilitySolutionConverter::ReadScene(const string &filename) 239 258 { 240 259 FILE *file; … … 247 266 VertexArray faceVertices; 248 267 VertexArray faceNormals; 249 vector<Tex coord> faceTexcoords;268 vector<TexCoord> faceTexcoords; 250 269 251 270 VertexArray vertices; 252 271 VertexArray normals; 253 vector<Tex coord> texcoords;272 vector<TexCoord> texcoords; 254 273 255 274 vector<int> indices; … … 261 280 while (fgets(str, len, file) != NULL) 262 281 { 282 if (line % 1000000 == 0) 283 cout << line << " " << str << endl; 284 285 ++ line; 286 263 287 switch (str[0]) 264 288 { … … 266 290 { 267 291 float x, y, z; 292 293 if (vertices.size() >= 1000000 * 3) continue; 268 294 269 295 switch (str[1]) … … 280 306 sscanf(str + 1, "%f %f %f", &x, &y, &z); 281 307 //const float scale = 5e-3f; 282 const float scale = 1.0f;283 vertices.push_back(SimpleVec(x * scale, y * scale, z * scale));308 const float scale = 0.1f; 309 vertices.push_back(SimpleVec(x * scale, y * scale, z * scale)); 284 310 //cout <<"v " << x << " " << y << " "<< z << " "; 285 311 } … … 291 317 //-- indices in the current line 292 318 319 if (faceVertices.size() >= 1000000 * 3) continue; 320 293 321 LoadIndices(str, 294 322 vertices, normals, texcoords, 295 323 faceVertices, faceNormals, faceTexcoords); 296 324 297 if (0 &&298 (((line % 1000) == 999) && !faceVertices.empty()))299 {300 ++ mNumShapes;301 302 LoadShape(faceVertices, faceNormals, faceTexcoords);303 304 faceVertices.clear();305 faceNormals.clear();306 faceTexcoords.clear();307 }308 309 325 break; 310 } // end face 311 case 'g': // load a new shape 312 {/* 313 if (!faceVertices.empty()) 314 { 315 ++ mNumShapes; 316 317 LoadShape(faceVertices, faceNormals, faceTexcoords); 318 319 faceVertices.clear(); 320 faceNormals.clear(); 321 faceTexcoords.clear(); 322 }*/ 323 } 326 } 324 327 break; 325 328 default: … … 327 330 break; 328 331 } 329 330 ++ line;331 332 } 332 333 … … 335 336 ++ mNumShapes; 336 337 337 LoadShape(faceVertices, faceNormals, faceTexcoords);338 ConstructBvhObjects(faceVertices, faceNormals, faceTexcoords); 338 339 339 340 faceVertices.clear(); … … 348 349 349 350 350 void ObjConverter::WriteGeometry(ogzstream &str, Geometry *geom) 351 static inline float RandomColor(float x) 352 { 353 return x + (1.0f - x) * (float)rand() / RAND_MAX; 354 } 355 356 357 void VisibilitySolutionConverter::WriteGeometry(ogzstream &str, Geometry *geom) 351 358 { 352 359 int vertexCount = geom->mVertexCount; … … 360 367 361 368 if (texCoordCount) 362 str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2); 363 369 { 370 str.write(reinterpret_cast<char *>(geom->mTexCoords), sizeof(float) * texCoordCount * 2); 371 } 364 372 365 373 /////// … … 392 400 ambient.x = ambient.y = ambient.z = 0.2f; 393 401 //diffuse.x = diffuse.y = diffuse.z = 1.0f; 394 diffuse.x = 0.7f; diffuse.y = 0.5f; diffuse.z = 0.2f; 402 403 diffuse.x = RandomColor(0.5f); 404 diffuse.y = RandomColor(0.5f); 405 diffuse.z = RandomColor(0.5f); 406 395 407 spec.x = spec.y = spec.z = .0f; 396 408 emm = spec; … … 405 417 406 418 407 bool ObjConverter::WriteFile(const string &filename)419 bool VisibilitySolutionConverter::WriteScene(const string &filename) 408 420 { 409 421 ogzstream ofile(filename.c_str()); … … 482 494 return true; 483 495 } 496 497 498 void VisibilitySolutionConverter::ConstructBvhObjects(const VertexArray &vertices, 499 const VertexArray &normals, 500 const vector<TexCoord> &texCoords) 501 { 502 cout << "vtx: " << vertices.size() << endl; 503 /* BvhNode n; 504 505 mGlobalTriangleIds.clear(); 506 for (size_t i = 0; i < vertices.size() / 3; ++ i) 507 { 508 mGlobalTriangleIds.push_back((int)i); 509 } 510 511 for (size_t i = 0; i < vertices.size() / 3; ++ i) 512 n.mTriangleIds.push_back((int)i); 513 514 mBvhNodes.push_back(n); 515 */ 516 for (size_t i = 0; i < mBvhNodes.size(); ++ i) 517 { 518 VertexArray _vertices; 519 VertexArray _normals; 520 vector<TexCoord> _texCoords; 521 522 BvhNode *node = mBvhNodes[i]; 523 524 //for (size_t j = 0; j < node->mTriangleIds.size(); ++ j) 525 for (int j = node->first; j < node->last; ++ j) 526 { 527 const int idx = 3 * mGlobalTriangleIds[j]; 528 529 //cout << "idx: " << idx << " "; 530 531 if (idx < 1000000 * 3) 532 { 533 for (int k = 0; k < 3; ++ k) 534 { 535 _vertices.push_back(vertices[idx + k]); 536 _normals.push_back(normals[idx + k]); 537 //_texCoords.push_back(texCoords[idx + k]); 538 } 539 } 540 } 541 542 LoadShape(_vertices, _normals, _texCoords); 543 } 544 } 545 546 547 bool VisibilitySolutionConverter::WriteBvh(const string &filename) 548 { 549 ogzstream ofile(filename.c_str()); 550 551 if (!ofile.is_open()) 552 return false; 553 554 555 ///////// 556 //-- write textures 557 558 #ifdef USE_TEXTURE 559 int textureCount = 1; 560 #else 561 int textureCount = 0; 562 #endif 563 ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); 564 565 if (textureCount > 0) 566 { 567 // hack 568 const string texName("wood.jpg"); 569 570 int texnameSize = (int)texName.length() + 1; 571 ofile.write(reinterpret_cast<char *>(&texnameSize), sizeof(int)); 572 573 ofile.write(texName.c_str(), sizeof(char) * texnameSize); 574 575 int boundS = 1, boundT = 1; 576 577 ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int)); 578 ofile.write(reinterpret_cast<char *>(&boundT), sizeof(int)); 579 } 580 581 582 /////////// 583 //-- write shapes 584 585 ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int)); 586 587 vector<Geometry *>::const_iterator it, it_end = mGeometry.end(); 588 589 for (it = mGeometry.begin(); it != it_end; ++ it) 590 { 591 WriteGeometry(ofile, *it); 592 } 593 594 595 int entityCount = 1; 596 ofile.write(reinterpret_cast<char *>(&entityCount), sizeof(int)); 597 598 599 ////////// 600 //-- write single scene entity 601 602 // no transformation 603 bool hasTrafo = false; 604 ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool)); 605 606 // a dummy lod 607 int numLODs = 1; 608 ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int)); 609 610 float dist = 0; 611 ofile.write(reinterpret_cast<char *>(&dist), sizeof(float)); 612 613 ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int)); 614 615 // all shapes belong to this scene entity 616 for (int i = 0; i < mNumShapes; ++ i) 617 { 618 int shapeId = i; 619 ofile.write(reinterpret_cast<char *>(&shapeId), sizeof(int)); 620 } 621 622 return true; 623 } 624 625 626 bool VisibilitySolutionConverter::ReadBvh(FILE *fr) 627 { 628 int buffer[6]; 629 fread(buffer, sizeof(int), 6, fr); 630 631 if (buffer[0] != MAGIC) 632 { 633 cerr << "Error: Wrong file type" << endl; 634 return false; 635 } 636 637 if (buffer[1] != (int)(1000 * BVH_VERSION)) 638 { 639 cerr << "Error: Wrong BVH version" << endl; 640 return false; 641 } 642 643 // load triangle ids 644 size_t numTriangles = buffer[2]; 645 646 for (size_t i = 0; i < numTriangles; ++i) 647 { 648 int id; 649 fread(&id, sizeof(int), 1, fr); 650 mGlobalTriangleIds[i] = id; 651 //triangles[i] = scene->triangles[id]; 652 } 653 654 //if (mRoot) delete mRoot; 655 656 mNumNodes = 0; // this was set to 1 in constructor! 657 658 mRoot = LoadNode(fr, 0); 659 660 if (mNumNodes != buffer[5]) 661 { 662 cerr << "Warning: Loaded " << mNumNodes << 663 " bvh nodes instead of " << buffer[5] << endl; 664 } 665 666 fclose(fr); 667 668 return true; 669 } 670 671 672 BvhNode *VisibilitySolutionConverter::LoadNode(FILE *fr, int depth) 673 { 674 ++ mNumNodes; 675 676 int buffer[4]; 677 fread(buffer, sizeof(int), 4, fr); 678 679 if (buffer[2] != -1) 680 { 681 BvhInterior *interior = new BvhInterior(); 682 683 interior->first = buffer[0]; 684 interior->last = buffer[1]; 685 interior->axis = buffer[2]; 686 interior->id = buffer[3]; 687 interior->depth = depth; 688 689 BvhNode *front, *back; 690 691 front = LoadNode(fr, depth + 1); 692 back = LoadNode(fr, depth + 1); 693 694 // front->parent = (BvhNode *)interior; 695 // back->parent = (BvhNode *)interior; 696 interior->front = front; 697 interior->back = back; 698 699 //interior->box = Union(front->box, back->box); 700 701 return (BvhNode *)interior; 702 } 703 else 704 { 705 // leaf 706 //Debug << "Info: Loading leaf (id: " << numberOfNodes << ", depth: " << depth << ")" << endl; 707 BvhLeaf *leaf = new BvhLeaf(); 708 leaf->first = buffer[0]; 709 leaf->last = buffer[1]; 710 leaf->axis = buffer[2]; 711 leaf->id = buffer[3]; 712 713 leaf->depth = depth; 714 //UpdateLeafBox(leaf); 715 716 mBvhNodes.push_back(leaf); 717 // leaf->id = numberOfNodes; 718 return (BvhNode *)leaf; 719 } 720 } 721 722 723 bool VisibilitySolutionConverter::ReadDummyTree(FILE *fr) 724 { 725 int buffer[256]; 726 fread(buffer, sizeof(int), 3, fr); 727 728 // read dummy bounding box 729 float dummy[6]; 730 fread(dummy, sizeof(float) * 6, 1, fr); 731 732 int stack = 1; 733 734 // read dummy tree 735 while (stack) 736 { 737 int axis; 738 fread(&axis, sizeof(int), 1, fr); 739 -- stack; 740 741 if (axis != - 1) 742 { 743 float dummy; 744 fread(&dummy, sizeof(float), 1, fr); 745 746 stack += 2; 747 } 748 } 749 750 return true; 751 } 752 753 754 755 bool VisibilitySolutionConverter::LoadSolution(const string &filename) 756 { 757 FILE *fr = fopen(filename.c_str(), "rb"); 758 759 cerr << "Info: Loading visibility solution from file '" + filename + "'" << endl; 760 761 if (fr == NULL) 762 { 763 cerr << "Error: Cannot open file for reading" << endl; 764 return false; 765 } 766 767 float totalSamples, totalTime; 768 769 fread(&totalSamples, sizeof(float), 1, fr); 770 fread(&totalTime, sizeof(float), 1, fr); 771 772 //viewCellsTree = new ViewCellsTree; 773 //bool ok = viewCellsTree->_LoadFromFile(fr); 774 775 bool ok = ReadDummyTree(fr); 776 777 if (ok) 778 { 779 //AllocateLeafViewCells(); 780 781 //objectsTree = new Bvh(*scene); 782 //ok = objectsTree->_LoadFromFile(fr); 783 ok = ReadBvh(fr); 784 785 /*if (ok) 786 { 787 AllocatePvsObjects(); 788 ok = LoadPvs(fr); 789 } 790 */ 791 } 792 793 fclose(fr); 794 795 if (ok) 796 cout << "Info: visibility solution loaded" << endl; 797 else 798 cout << "Info: loading visibility solution failed" << endl; 799 800 return true; 801 } 802 803 804 #if 0 805 bool VisibilitySolution::LoadPvs(FILE *fw) 806 { 807 int number, entries; 808 809 fread(&number, sizeof(int), 1, fw); 810 811 if (number == 0) 812 { 813 Message("Info: Warning empty PVSs in visibility solution"); 814 return true; 815 } 816 817 if (number != viewCells.size()) 818 { 819 Message("Info: Number of view cells does not match when loading PVSs!"); 820 return false; 821 } 822 823 for (int i=0; i < number; i++) 824 { 825 fread(&entries, sizeof(int), 1, fw); 826 827 for (int j=0; j < entries; j++) 828 { 829 int objectId; 830 float time; 831 fread(&objectId, sizeof(int), 1, fw); 832 fread(&time, sizeof(float), 1, fw); 833 viewCells[i]->pvs.Insert(objectId, time); 834 } 835 } 836 return true; 837 } 838 839 840 bool ViewCellsTree::_LoadFromFile(FILE *fr) 841 { 842 int buffer[256]; 843 fread(buffer, sizeof(int), 3, fr); 844 845 if (buffer[0] != MAGIC) 846 { 847 Message( "Error: Wrong file type"); 848 return false; 849 } 850 851 if (buffer[1] != (int)(1000*VIEWCELLS_VERSION)) 852 { 853 Message( "Error: Wrong viewcells version" ); 854 855 return false; 856 } 857 858 // get the bounding box 859 fread(&box, sizeof(AxisAlignedBox3), 1, fr); 860 861 stack<ViewCellsTreeNode **> nodeStack; 862 nodeStack.push(&root); 863 864 while(!nodeStack.empty()) 865 { 866 ViewCellsTreeNode *&node = *nodeStack.top(); 867 868 nodeStack.pop(); 869 node = new ViewCellsTreeNode; 870 871 fread(&node->axis, sizeof(int), 1, fr); 872 873 if (!node->IsLeaf()) 874 { 875 fread(&node->position, sizeof(float), 1, fr); 876 877 nodeStack.push(&node->front); 878 nodeStack.push(&node->back); 879 } 880 } 881 882 return true; 883 } 884 #endif -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h
r3234 r3235 1 #ifndef _OBJCONVERTER_H 2 #define _OBJCONVERTER_H 1 #ifndef _VISIBILITYSOLUTIONCONVERTER_H 2 #define _VISIBILITYSOLUTIONCONVERTER_H 3 3 4 4 5 #include "SimpleVec.h" … … 6 7 #include <vector> 7 8 8 /*struct SimpleVec9 {10 SimpleVec() {}11 SimpleVec(float _x, float _y, float _z): x(_x), y(_y), z(_z) {}12 9 13 float x, y, z;14 };*/15 10 16 11 typedef std::vector<SimpleVec> VertexArray; 17 typedef std::pair<float, float> Tex coord;12 typedef std::pair<float, float> TexCoord; 18 13 19 14 class ogzstream; 20 15 16 17 struct BvhNode 18 { 19 int id; 20 char axis; 21 unsigned char depth; 22 short flags; 23 24 // indices to first and last triangle in the triangle array 25 // assumes the traingle are placed in continuous chunk of memory 26 // however this need not be a global array! 27 int first; 28 // one after the last triangle! 29 int last; 30 31 BvhNode(): axis(-1), first(-1), flags(0) {} 32 33 bool IsLeaf() { return axis == -1; } 34 bool Empty() const { return first == -1; } 35 int Count() const { return last - first + 1; } 36 37 std::vector<int> mTriangleIds; 38 }; 39 40 41 struct BvhInterior: public BvhNode 42 { 43 BvhInterior():back(NULL), front(NULL) { } 44 BvhNode *back; 45 BvhNode *front; 46 }; 47 48 49 struct BvhLeaf: public BvhNode 50 { 51 //Color color; 52 int texture; 53 54 BvhLeaf(): BvhNode(), texture(0) {} 55 }; 56 57 21 58 /** Converts obj format into objects readable by our format 22 59 */ 23 class ObjConverter60 class VisibilitySolutionConverter 24 61 { 25 62 public: 26 63 27 ObjConverter();64 VisibilitySolutionConverter(); 28 65 29 bool Convert(const std::string &inputFilename, 30 const std::string &outputFilename); 31 // const std::string textureFilename) const; 66 ~VisibilitySolutionConverter(); 32 67 33 ~ObjConverter(); 68 bool Convert(const std::string &sceneInputFilename, 69 const std::string &sceneOutputFilename, 70 const std::string &bvhInputFilename, 71 const std::string &bvhOutputFilename); 72 73 34 74 35 75 protected: … … 39 79 SimpleVec *mVertices; 40 80 SimpleVec *mNormals; 41 Tex coord *mTexcoords;81 TexCoord *mTexCoords; 42 82 43 83 int mVertexCount; … … 45 85 }; 46 86 47 void LoadShape(const VertexArray & faceVertices,48 const VertexArray & faceNormals,49 const std::vector<Tex coord> &faceTexcoords);87 void LoadShape(const VertexArray &vertices, 88 const VertexArray &normals, 89 const std::vector<TexCoord> &texCoords); 50 90 51 91 void WriteGeometry(ogzstream &str, Geometry *geom); 52 92 53 bool ReadFile(const std::string &inputFilename); 54 bool WriteFile(const std::string &outputFilename); 93 bool ReadScene(const std::string &iFilename); 55 94 95 bool WriteScene(const std::string &oFilename); 96 97 bool ReadBvh(FILE *fr); 98 99 bool WriteBvh(const std::string &oFilename); 100 101 void ConstructBvhObjects(const VertexArray &vertices, 102 const VertexArray &normals, 103 const std::vector<TexCoord> &texCoords); 104 105 bool LoadSolution(const std::string &filename); 106 107 108 BvhNode *LoadNode(FILE *fr, int depth); 109 110 bool ReadDummyTree(FILE *fr); 111 112 113 114 ////////////////////////////////// 56 115 57 116 std::vector<Geometry *> mGeometry; 58 117 59 118 int mNumShapes; 119 120 std::vector<int> mGlobalTriangleIds; 121 122 std::vector<BvhNode *> mBvhNodes; 123 124 BvhNode *mRoot; 125 126 int mNumNodes; 60 127 }; 61 128 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp
r3234 r3235 1 #include " ObjConverter.h"1 #include "VisibilitySolutionConverter.h" 2 2 #include <iostream> 3 3 #include <time.h> … … 11 11 int returnCode = 0; 12 12 13 ObjConverter converter;13 VisibilitySolutionConverter converter; 14 14 15 15 cout << "converting obj to dem format" << endl; 16 16 17 if (!converter.Convert(model_path + argv[1], model_path + argv[2] ))17 if (!converter.Convert(model_path + argv[1], model_path + argv[2], model_path + argv[3], model_path + argv[4])) 18 18 { 19 19 cerr << "conversion failed" << endl; … … 22 22 exit(0); 23 23 } 24 //std::cin.get(); 24 25 std::cin.get(); 25 26 cout << "conversion successful" << endl; 26 27 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3214 r3235 1326 1326 { 1327 1327 while (mGeometry[i]->GetWorldCenter()[axis] < position) ++ i; 1328 //while ((j > 0) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j; 1328 1329 while (position < mGeometry[j]->GetWorldCenter()[axis]) -- j; 1329 1330 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3233 r3235 301 301 mSunVisiblePixels(0), 302 302 mSavedFrameNumber(-1), 303 mSavedFrameSuffix("") 303 mSavedFrameSuffix(""), 304 mMaxDistance(1e6f) 304 305 { 305 306 /////////// … … 488 489 //////////////// 489 490 490 string dofParams[] = {"colorsTex", "filterOffs", "sceneRange" };491 492 sCgDOFProgram->AddParameters(dofParams, 0, 3);491 string dofParams[] = {"colorsTex", "filterOffs", "sceneRange", "zFocus"}; 492 493 sCgDOFProgram->AddParameters(dofParams, 0, 4); 493 494 494 495 … … 520 521 // todo matt: it is stupid to put num samples and width of kernel into constructor => change this!!! 521 522 PoissonDiscSampleGenerator2D poisson3(NUM_DOF_TABS, 1.0f); 522 poisson2.Generate((float *)dofSamples); 523 poisson3.Generate((float *)dofSamples); 524 525 for (int i = 0; i < NUM_DOF_TABS; ++ i) 526 { 527 dofSamples[i].x *= 1.0f / mWidth; 528 dofSamples[i].y *= 1.0f / mHeight; 529 } 523 530 524 531 //float dofWeights[NUM_PCF_TABS]; … … 567 574 } 568 575 576 /// do depth of field 577 DepthOfField(fbo); 578 569 579 if (useToneMapping) 570 580 { … … 574 584 ToneMap(fbo, imageKey, whiteLum, middleGrey); 575 585 } 576 577 578 /// do depth of field579 DepthOfField(fbo);580 586 581 587 /// compute lense flare … … 1312 1318 FlipFbos(fbo); 1313 1319 1314 float sceneRange = 1.0f;1315 1316 1320 int i = 0; 1321 1322 const float zFocus = 7.0f; 1317 1323 1318 1324 sCgDOFProgram->SetTexture(i ++, colorsTex); 1319 1325 sCgDOFProgram->SetArray2f(i ++, (float *)dofSamples, NUM_DOF_TABS); 1320 sCgDOFProgram->SetValue1f(i ++, mCamera->GetFar() - mCamera->GetNear()); 1326 sCgDOFProgram->SetValue1f(i ++, min(mCamera->GetFar(), mMaxDistance) - mCamera->GetNear()); 1327 sCgDOFProgram->SetValue1f(i ++, zFocus); 1321 1328 1322 1329 DrawQuad(sCgDOFProgram); … … 1442 1449 1443 1450 1451 void DeferredRenderer::SetMaxDistance(float maxDist) 1452 { 1453 mMaxDistance = maxDist; 1454 } 1455 1456 1444 1457 void DeferredRenderer::SetSaveFrame(const string &suffix, int frameNumber) 1445 1458 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3232 r3235 88 88 void SetSaveFrame(const std::string &suffix, int frameNumber); 89 89 90 void SetMaxDistance(float maxDist); 91 90 92 91 93 // hack: store the color buffer idx for the currently used flip flop-MRT here … … 158 160 159 161 162 160 163 //////////// 161 164 … … 205 208 int mSavedFrameNumber; 206 209 std::string mSavedFrameSuffix; 210 211 float mMaxDistance; 207 212 }; 208 213 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r3234 r3235 109 109 } 110 110 111 cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;111 //cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl; 112 112 } 113 113 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3227 r3235 541 541 //LoadModel("fisch.dem", dynamicObjects); 542 542 LoadModel("hbuddha.dem", dynamicObjects); 543 543 544 //LoadModel("venusm.dem", dynamicObjects); 544 545 //LoadModel("camel.dem", dynamicObjects); … … 575 576 dynamicObjects.push_back(ent); 576 577 } 578 579 580 //LoadModel("vienna_full_hp.dem", dynamicObjects); 581 //dynamicObjects.back()->GetTransform()->SetMatrix(transl); 577 582 578 583 … … 2276 2281 { 2277 2282 // usethe maximal visible distance to focus shadow map 2278 float maxVisibleDist= min(camera->GetFar(), traverser->GetMaxVisibleDistance());2279 RenderShadowMap( maxVisibleDist);2283 const float newFar = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 2284 RenderShadowMap(newFar); 2280 2285 } 2281 2286 // initialize deferred rendering -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/irradiance.cpp
r3216 r3235 1153 1153 deferredShader->SetUseTemporalCoherence(useTemporalCoherence); 1154 1154 deferredShader->SetSortSamples(sortSamples); 1155 deferredShader->SetMaxDistance(traverser->GetMaxVisibleDistance()); 1155 1156 1156 1157 ShadowMap *sm = showShadowMap ? shadowMap : NULL; … … 2017 2018 { 2018 2019 // usethe maximal visible distance to focus shadow map 2019 float maxVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance());2020 const float maxVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 2020 2021 RenderShadowMap(maxVisibleDist); 2021 2022 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/depthOfField.cg
r3232 r3235 7 7 8 8 9 float2 ComputeBlurFactors(float4 color, float sceneRange )9 float2 ComputeBlurFactors(float4 color, float sceneRange, float zFocus) 10 10 { 11 11 float2 result; 12 12 13 const float m = 1.0f; 14 const float focalLen = 1.0f; 15 16 const float scale = 5e4f; 17 13 18 // Compute blur factor based on the CoC size scaled and normalized to 0..1 range 14 //float pixCoC = abs(Dlens * focalLen * (Zfocus - v.fDepth) / (Zfocus * (v.fDepth - focalLen))); 19 //float blur = abs(dLens * focalLen * (zFocus - color.w)) / (1e-6f + abs(zFocus * (color.w - focalLen))); 20 21 const float dist = abs(zFocus - color.w); 22 const float blur = scale * m * focalLen * dist / (sceneRange * (1e-6f + abs(color.w + dist * step(0, zFocus - color.w)))); 15 23 16 //float blur = saturate( pixCoC* scale / maxCoC);24 //float blur = saturate(blur * scale / maxCoC); 17 25 18 26 // Depth/blurriness value scaled to 0..1 range 19 //result = float2(v.fDepth/ sceneRange, blur);27 result = float2(color.w / sceneRange, blur); 20 28 21 29 return result; … … 30 38 ) 31 39 { 32 float average = .0f;40 float4 avgCol = float4(.0f); 33 41 float total_w = .0f; 34 42 35 43 for (int i = 0; i < NUM_DOF_TABS; ++ i) 36 44 { 37 float2 sampleTexCoord = texCoords + filterOffs[i] ;45 float2 sampleTexCoord = texCoords + filterOffs[i] * blurFactors.y; 38 46 float4 sampleCol = tex2Dlod(colorsTex, float4(sampleTexCoord, 0, 0)); 39 47 … … 41 49 float w = 1; 42 50 43 av erage+= sampleCol * w;51 avgCol += sampleCol * w; 44 52 total_w += w; 45 53 } 46 54 47 av erage/= max(total_w, 1e-6f);55 avgCol /= max(total_w, 1e-6f); 48 56 49 return saturate(average);57 return avgCol; 50 58 } 51 59 … … 54 62 uniform sampler2D colorsTex, 55 63 uniform float2 filterOffs[NUM_DOF_TABS], 56 uniform float sceneRange 64 uniform float sceneRange, 65 uniform float zFocus 57 66 ): COLOR 58 67 { … … 60 69 const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0)); 61 70 62 float2 blurFactors = ComputeBlurFactors(color, sceneRange); 71 zFocus = min(zFocus, sceneRange * 0.5f); 72 float2 blurFactors = ComputeBlurFactors(color, sceneRange, zFocus); 73 74 //float4 outCol = float4(color.x, color.y, blurFactors.y, color.w); 63 75 float4 outCol = Blur(color, IN.texCoords, blurFactors, colorsTex, filterOffs); 64 76
Note: See TracChangeset
for help on using the changeset viewer.