Changeset 3119 for GTP/trunk/App/Demos
- Timestamp:
- 11/11/08 19:14:04 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
r3110 r3119 9 9 10 10 11 static void LoadIndices(char *str,12 const VertexArray &vertices,13 const VertexArray &normals,14 const vector<pair<float, float> > &texcoords,15 VertexArray &faceVertices,16 VertexArray &faceNormals,17 vector<Texcoord> &faceTexcoords18 )19 {20 vector<char *> substrings;21 22 char *next_token;23 24 // extract the triples of the form v/t/n v/t/n ...25 char *pch = strtok_s(str + 1, " ", &next_token);26 27 while (pch != NULL)28 {29 substrings.push_back(pch);30 pch = strtok_s(NULL, " ", &next_token);31 }32 33 vector<int> indices;34 vector<int> nIndices;35 vector<int> tIndices;36 37 for (size_t i = 0; i < substrings.size(); ++ i)38 {39 // vertex, normal, texture indices40 char *str = strtok_s(substrings[i], "/", &next_token);41 int index = (int)strtol(str, NULL, 10) - 1;42 43 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;59 }60 61 // store indices62 if (index >= 0)63 {64 indices.push_back(index);65 nIndices.push_back(nIndex);66 tIndices.push_back(tIndex);67 }68 69 // new triangle found70 if (indices.size() > 2)71 {72 // change orientation of faces?73 #if 174 int idx1 = 0;75 int idx2 = (int)indices.size() - 2;76 int idx3 = (int)indices.size() - 1;77 #else78 int idx3 = 0;79 int idx2 = (int)indices.size() - 2;80 int idx1 = (int)indices.size() - 1;81 #endif82 faceVertices.push_back(vertices[indices[idx1]]);83 faceVertices.push_back(vertices[indices[idx2]]);84 faceVertices.push_back(vertices[indices[idx3]]);85 86 if (!normals.empty())87 {88 faceNormals.push_back(normals[nIndices[idx1]]);89 faceNormals.push_back(normals[nIndices[idx2]]);90 faceNormals.push_back(normals[nIndices[idx3]]);91 }92 else93 {94 // no face normals?95 const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]);96 const SimpleVec n = tri.GetNormal();97 98 faceNormals.push_back(n);99 faceNormals.push_back(n);100 faceNormals.push_back(n);101 }102 103 if (!texcoords.empty())104 {105 faceTexcoords.push_back(texcoords[tIndices[idx1]]);106 faceTexcoords.push_back(texcoords[tIndices[idx2]]);107 faceTexcoords.push_back(texcoords[tIndices[idx3]]);108 }109 }110 }111 }112 113 114 11 VboFormatConverter::VboFormatConverter() 115 12 {} … … 131 28 132 29 133 void VboFormatConverter::LoadShape(const VertexArray &faceVertices, 134 const VertexArray &faceNormals, 135 const vector<Texcoord> &faceTexcoords) 136 { 137 int numElements = (int)faceVertices.size(); 30 bool VboFormatConverter::Convert(const string &filename, 31 const std::string &outputFilename) 32 { 33 mNumShapes = 0; 34 35 for (size_t i = 0; i < mGeometry.size(); ++ i) 36 { 37 delete [] mGeometry[i]->mVertices; 38 delete [] mGeometry[i]->mNormals; 39 delete [] mGeometry[i]->mTexcoords; 40 41 delete mGeometry[i]; 42 } 43 44 mGeometry.clear(); 45 46 if (!ReadFile(filename)) 47 { 48 cerr << "could not read file" << endl; 49 return false; 50 } 51 52 if (!WriteFile(outputFilename)) 53 { 54 cerr << "could not write file" << endl; 55 return false; 56 } 57 58 59 return true; 60 } 61 62 63 bool VboFormatConverter::ReadFile(const string &filename) 64 { 65 FILE *file; 66 if ((file = fopen(filename.c_str(), "r")) == NULL) return false; 67 68 int line = 0; 69 70 const int len = 10000; 71 char str[len]; 72 73 int numElements; 74 75 // first line only holds number of vertices 76 fgets(str, len, file); 77 sscanf(str, "%d", &numElements); 78 138 79 Geometry *geom = new Geometry(); 139 80 140 81 // convert the triangles to geometry 82 geom->mVertexCount = numElements; 141 83 geom->mVertices = new SimpleVec[numElements]; 142 84 geom->mNormals = new SimpleVec[numElements]; 143 85 geom->mTexcoords = new Texcoord[numElements]; 144 86 145 geom->mVertexCount = numElements; 146 geom->mTexcoordCount = (int)faceTexcoords.size(); 147 148 cout << "number of vertices=" << numElements << endl; 149 150 for (int i = 0; i < numElements; ++ i) 151 { 152 #if 0 153 // convert to our camera system: change y and z 154 geom->mVertices[i].x = faceVertices[i].x; 155 geom->mVertices[i].y = -faceVertices[i].z; 156 geom->mVertices[i].z = faceVertices[i].y; 157 158 geom->mNormals[i].x = faceNormals[i].x; 159 geom->mNormals[i].y = -faceNormals[i].z; 160 geom->mNormals[i].z = faceNormals[i].y; 161 #else 162 geom->mVertices[i].x = faceVertices[i].x; 163 geom->mVertices[i].y = faceVertices[i].y; 164 geom->mVertices[i].z = faceVertices[i].z; 165 166 geom->mNormals[i].x = faceNormals[i].x; 167 geom->mNormals[i].y = faceNormals[i].y; 168 geom->mNormals[i].z = faceNormals[i].z; 169 170 #endif 171 geom->mVertices[i].x += 470.398f; 172 geom->mVertices[i].y += 240.364f; 173 geom->mVertices[i].z += 182.5f; 174 175 if (i < geom->mTexcoordCount) 176 { 177 geom->mTexcoords[i].first = faceTexcoords[i].first; 178 geom->mTexcoords[i].second = faceTexcoords[i].second; 179 } 87 SimpleVec vtx, normal, tangent; 88 Texcoord tex; 89 90 cout << "elements: " << numElements << endl; 91 while (fgets(str, len, file) != NULL) 92 { 93 sscanf(str, "%f %f %f %f %f %f %f %f %f %f %f", 94 &vtx.x, &vtx.z, &vtx.y, 95 &normal.x, &normal.z, &normal.y, 96 &tex.first, &tex.second, 97 &tangent.x, &tangent.y, &tangent.z); 98 99 vtx.x *= 0.07f; 100 vtx.y *= 0.07f; 101 vtx.z *= 0.07f; 102 103 geom->mVertices[line] = vtx; 104 geom->mNormals[line] = normal; 105 geom->mTexcoords[line] = tex; 106 107 ++ line; 180 108 } 181 109 182 110 mGeometry.push_back(geom); 183 } 184 185 186 bool VboFormatConverter::Convert(const string &filename, const std::string &outputFilename) 187 { 188 mNumShapes = 0; 189 190 for (size_t i = 0; i < mGeometry.size(); ++ i) 191 { 192 delete [] mGeometry[i]->mVertices; 193 delete [] mGeometry[i]->mNormals; 194 delete [] mGeometry[i]->mTexcoords; 195 196 delete mGeometry[i]; 197 } 198 199 mGeometry.clear(); 200 201 if (!ReadFile(filename)) 202 { 203 cerr << "could not read file" << endl; 204 return false; 205 } 206 207 if (!WriteFile(outputFilename)) 208 { 209 cerr << "could not write file" << endl; 210 return false; 211 } 212 213 214 return true; 215 } 216 217 218 bool VboFormatConverter::ReadFile(const string &filename) 219 { 220 FILE *file; 221 222 if ((file = fopen(filename.c_str(), "r")) == NULL) 223 { 224 return false; 225 } 226 227 VertexArray faceVertices; 228 VertexArray faceNormals; 229 vector<Texcoord> faceTexcoords; 230 231 VertexArray vertices; 232 VertexArray normals; 233 vector<Texcoord> texcoords; 234 235 vector<int> indices; 236 237 int line = 0; 238 239 const int len = 10000; 240 char str[len]; 241 242 while (fgets(str, len, file) != NULL) 243 { 244 // if (1)//(line % 100) == 0) 245 // cout << "read line " << line << " " << str; 246 switch (str[0]) 247 { 248 case 'v': // vertex or normal 249 { 250 float x, y, z; 251 252 switch (str[1]) 253 { 254 case 'n' : 255 sscanf(str + 2, "%f %f %f", &x, &y, &z); 256 normals.push_back(SimpleVec(x, y, z)); 257 break; 258 case 't': 259 sscanf(str + 2, "%f %f", &x, &y); 260 texcoords.push_back(pair<float, float>(x, y)); 261 break; 262 default: 263 sscanf(str + 1, "%f %f %f", &x, &y, &z); 264 vertices.push_back(SimpleVec(x, y, z)); 265 //cout <<"v " << x << " " << y << " "<< z << " "; 266 } 267 break; 268 } 269 case 'f': 270 { 271 ////////// 272 //-- indices in the current line 273 274 LoadIndices(str, 275 vertices, normals, texcoords, 276 faceVertices, faceNormals, faceTexcoords); 277 278 if (0 && 279 (((line % 1000) == 999) && !faceVertices.empty())) 280 { 281 ++ mNumShapes; 282 283 LoadShape(faceVertices, faceNormals, faceTexcoords); 284 285 faceVertices.clear(); 286 faceNormals.clear(); 287 faceTexcoords.clear(); 288 } 289 290 break; 291 } // end face 292 case 'g': // load a new shape 293 {/* 294 if (!faceVertices.empty()) 295 { 296 ++ mNumShapes; 297 298 LoadShape(faceVertices, faceNormals, faceTexcoords); 299 300 faceVertices.clear(); 301 faceNormals.clear(); 302 faceTexcoords.clear(); 303 }*/ 304 } 305 break; 306 default: 307 break; 308 } 309 310 ++ line; 311 } 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 111 112 mNumShapes = 1; 324 113 fclose(file); 325 114 … … 346 135 //-- texture 347 136 348 //int texId = -1;349 int texId = 0;137 int texId = -1; 138 //int texId = 0; 350 139 str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 351 140 … … 390 179 //-- write textures 391 180 392 int textureCount = 1;393 //int textureCount = 0;181 //int textureCount = 1; 182 int textureCount = 0; 394 183 395 184 ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.h
r3107 r3119 6 6 #include <vector> 7 7 8 /*struct SimpleVec9 {10 SimpleVec() {}11 SimpleVec(float _x, float _y, float _z): x(_x), y(_y), z(_z) {}12 13 float x, y, z;14 };*/15 8 16 9 typedef std::vector<SimpleVec> VertexArray; … … 29 22 bool Convert(const std::string &inputFilename, 30 23 const std::string &outputFilename); 31 //const std::string textureFilename) const;24 //const std::string textureFilename) const; 32 25 33 26 ~VboFormatConverter(); … … 45 38 }; 46 39 47 void LoadShape(const VertexArray &faceVertices,48 const VertexArray &faceNormals,49 const std::vector<Texcoord> &faceTexcoords);50 51 40 void WriteGeometry(ogzstream &str, Geometry *geom); 52 41 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3117 r3119 1 ############################# 2 # environment file for the friendlyculling demo 1 ##################################################### 2 # environment file for the friendlyculling demo # 3 ##################################################### 4 5 3 6 4 7 ############ 5 # #chc++ options8 # chc++ options 6 9 7 10 assumedVisibleFrames=10 … … 10 13 trianglesPerVirtualLeaf=300 11 14 15 ################ 16 17 useLODs=1 18 shadowSize=4096 19 20 #################### 21 # camera / light options 12 22 13 23 # move speed … … 17 27 #keyRotation=1.5f 18 28 19 20 winWidth=1024 21 winHeight=768 22 23 # initial positin + orientation 29 # initial camera position 24 30 camPosition=483.398f 242.364f 186.078f 31 # initial camera orientation 25 32 camDirection=1 0 0 26 33 … … 28 35 lightDirection=-0.3f 0.2f -0.7f 29 36 37 38 ##################### 39 # window options 40 41 winWidth=1024 42 winHeight=768 43 30 44 useFullScreen=0 31 useLODs=1 32 shadowSize=4096 45 33 46 34 47 #modelPath=data/city/model/ 35 48 36 49 37 38 50 ############ 39 # shader stuff51 # shader options 40 52 41 53 # ssao temporal coherence factor -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3118 r3119 463 463 //-- load some dynamic stuff 464 464 465 LoadModel("hbuddha.dem", dynamicObjects); 465 LoadModel("fisch.dem", dynamicObjects); 466 //LoadModel("hbuddha.dem", dynamicObjects); 466 467 buddha = dynamicObjects.back(); 467 468 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3117 r3119 102 102 // retrieve the sample from the last frame 103 103 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 104 104 // the eye linear depth from the previous frame 105 105 const float oldEyeSpaceDepth = oldPixel.w; 106 106 … … 110 110 const float projectedEyeSpaceDepth = invlen * length(translatedPos); 111 111 112 float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 0 :113 abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);112 float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 3.0f) ? 113 0 : abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 114 114 115 115 return depthDif; … … 207 207 ); 208 208 //overallDepth += sampleDif; 209 210 209 if (sampleDif >= MIN_DEPTH_DIFF) ++ notValid; 211 210 }
Note: See TracChangeset
for help on using the changeset viewer.