comparison Render.cpp @ 2320:847aba0b7f82

draw terrain distance
author Ritor1
date Fri, 21 Mar 2014 01:12:52 +0600
parents 133882370e83
children 53c9d34024d6
comparison
equal deleted inserted replaced
2319:9987f93d7e1f 2320:847aba0b7f82
357 pTilePolygon->dimming_level = 20.0 - floorf(20.0 * _f + 0.5f); 357 pTilePolygon->dimming_level = 20.0 - floorf(20.0 * _f + 0.5f);
358 if ( norm_idx < 0 || norm_idx > uNumTerrainNormals - 1 ) 358 if ( norm_idx < 0 || norm_idx > uNumTerrainNormals - 1 )
359 norm = 0; 359 norm = 0;
360 else 360 else
361 norm = &pTerrainNormals[norm_idx]; 361 norm = &pTerrainNormals[norm_idx];
362 pGame->pLightmapBuilder->StackLights_TerrainFace(norm, &a3a, array_50AC10, 4, 1);//Ritor1: slows 362 //pGame->pLightmapBuilder->StackLights_TerrainFace(norm, &a3a, array_50AC10, 4, 1);//Ritor1: slows
363 pDecalBuilder->_49BE8A(pTilePolygon, norm, &a3a, array_50AC10, 4, 1); 363 //pDecalBuilder->_49BE8A(pTilePolygon, norm, &a3a, array_50AC10, 4, 1);
364 //----------------------------------------------------------------------------------------------- 364 //-----------------------------------------------------------------------------------------------
365 365
366 ++pODMRenderParams->uNumPolygons; 366 ++pODMRenderParams->uNumPolygons;
367 ++pODMRenderParams->field_44; 367 ++pODMRenderParams->field_44;
368 assert(pODMRenderParams->uNumPolygons < 20000); 368 assert(pODMRenderParams->uNumPolygons < 20000);
374 { 374 {
375 memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft)); 375 memcpy(&array_50AC10[k], &array_73D150[k], sizeof(struct RenderVertexSoft));
376 array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097); 376 array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097);
377 } 377 }
378 //---------Draw distance(Дальность отрисовки)------------------------------- 378 //---------Draw distance(Дальность отрисовки)-------------------------------
379 pODMRenderParams->shading_dist_mist = 0x5000; 379 int temp = pODMRenderParams->shading_dist_mist;
380 if ( draw_terrain_dist_mist )
381 pODMRenderParams->shading_dist_mist = 0x5000;
380 bool neer_clip = array_73D150[0].vWorldViewPosition.x < 8.0 382 bool neer_clip = array_73D150[0].vWorldViewPosition.x < 8.0
381 || array_73D150[1].vWorldViewPosition.x < 8.0 383 || array_73D150[1].vWorldViewPosition.x < 8.0
382 || array_73D150[2].vWorldViewPosition.x < 8.0 384 || array_73D150[2].vWorldViewPosition.x < 8.0
383 || array_73D150[3].vWorldViewPosition.x < 8.0; 385 || array_73D150[3].vWorldViewPosition.x < 8.0;
384 bool far_clip = (double)pODMRenderParams->shading_dist_mist < array_73D150[0].vWorldViewPosition.x 386 bool far_clip = (double)pODMRenderParams->shading_dist_mist < array_73D150[0].vWorldViewPosition.x
388 if ( !byte_4D864C || ~pGame->uFlags & 0x80 ) 390 if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
389 { 391 {
390 if ( neer_clip ) 392 if ( neer_clip )
391 { 393 {
392 pTilePolygon->uNumVertices = ODM_NearClip(pTilePolygon->uNumVertices); 394 pTilePolygon->uNumVertices = ODM_NearClip(pTilePolygon->uNumVertices);
393 //ODM_Project(pTilePolygon->uNumVertices); 395 ODM_Project(pTilePolygon->uNumVertices);
394 } 396 }
395 if ( far_clip ) 397 if ( far_clip )
396 { 398 {
397
398 pTilePolygon->uNumVertices = ODM_FarClip(pTilePolygon->uNumVertices); 399 pTilePolygon->uNumVertices = ODM_FarClip(pTilePolygon->uNumVertices);
399 //ODM_Project(pTilePolygon->uNumVertices); 400 ODM_Project(pTilePolygon->uNumVertices);
400 } 401 }
401 } 402 }
402 pODMRenderParams->shading_dist_mist = 0x2000; 403 pODMRenderParams->shading_dist_mist = temp;
403 404
404 // check the transparency and texture (tiles) mapping (проверка прозрачности и наложение текстур (тайлов))---------------------- 405 // check the transparency and texture (tiles) mapping (проверка прозрачности и наложение текстур (тайлов))----------------------
405 bool transparent = false; 406 bool transparent = false;
406 if ( !( pTilePolygon->flags & 1 ) ) // не поддерживается TextureFrameTable 407 if ( !( pTilePolygon->flags & 1 ) ) // не поддерживается TextureFrameTable
407 { 408 {
8522 int ODM_NearClip(unsigned int num_vertices) 8523 int ODM_NearClip(unsigned int num_vertices)
8523 { 8524 {
8524 bool current_vertices_flag; // edi@1 8525 bool current_vertices_flag; // edi@1
8525 bool next_vertices_flag; // [sp+Ch] [bp-24h]@6 8526 bool next_vertices_flag; // [sp+Ch] [bp-24h]@6
8526 double t; // st6@10 8527 double t; // st6@10
8527 //int pNextVertices; 8528 bool bFound;
8529
8530 bFound = false;
8528 8531
8529 if (!num_vertices) 8532 if (!num_vertices)
8533 return 0;
8534 for (uint i = 0; i < num_vertices; ++i)// есть ли пограничные вершины
8535 {
8536 if ( array_50AC10[i].vWorldViewPosition.x > 8.0 )
8537 {
8538 bFound = true;
8539 break;
8540 }
8541 }
8542 if ( !bFound )
8530 return 0; 8543 return 0;
8531 8544
8532 memcpy(&array_50AC10[num_vertices], &array_50AC10[0], sizeof(array_50AC10[0])); 8545 memcpy(&array_50AC10[num_vertices], &array_50AC10[0], sizeof(array_50AC10[0]));
8533 current_vertices_flag = false; 8546 current_vertices_flag = false;
8534 next_vertices_flag = false; 8547 next_vertices_flag = false;
8535 if ( array_50AC10[0].vWorldViewPosition.x <= 8.0 ) 8548 if ( array_50AC10[0].vWorldViewPosition.x <= 8.0 )
8536 current_vertices_flag = true; 8549 current_vertices_flag = true;
8550 //check for near clip plane(проверка по ближней границе)
8551 //
8552 // v3.__________________. v0
8553 // | |
8554 // | |
8555 // | |
8556 // ----------------------- 8.0(near_clip - 8.0)
8557 // | |
8558 // .__________________.
8559 // v2 v1
8537 8560
8538 int out_num_vertices = 0; 8561 int out_num_vertices = 0;
8539 for (int i = 0; i < num_vertices; ++i) 8562 for (int i = 0; i < num_vertices; ++i)
8540 { 8563 {
8541 next_vertices_flag = array_50AC10[i + 1].vWorldViewPosition.x <= 8.0;// 8564 next_vertices_flag = array_50AC10[i + 1].vWorldViewPosition.x <= 8.0;//
8579 { 8602 {
8580 bool current_vertices_flag; // [sp+Ch] [bp-28h]@6 8603 bool current_vertices_flag; // [sp+Ch] [bp-28h]@6
8581 bool next_vertices_flag; // edi@1 8604 bool next_vertices_flag; // edi@1
8582 double t; // st6@10 8605 double t; // st6@10
8583 signed int depth_num_vertices; // [sp+18h] [bp-1Ch]@1 8606 signed int depth_num_vertices; // [sp+18h] [bp-1Ch]@1
8584 //int pNextVertices;
8585 bool bFound; 8607 bool bFound;
8586 //Доп инфо "Программирование трёхмерных игр для windows" Ламот стр 910 8608 //Доп инфо "Программирование трёхмерных игр для windows" Ламот стр 910
8587 8609
8588 bFound = false; 8610 bFound = false;
8589 8611
8621 if ( current_vertices_flag ^ next_vertices_flag )//одна из граней за границей видимости 8643 if ( current_vertices_flag ^ next_vertices_flag )//одна из граней за границей видимости
8622 { 8644 {
8623 if ( next_vertices_flag )//следующая вершина больше границы видимости(настоящая вершина меньше границы видимости) - v3 8645 if ( next_vertices_flag )//следующая вершина больше границы видимости(настоящая вершина меньше границы видимости) - v3
8624 { 8646 {
8625 //t = far_clip - v2.x / v3.x - v2.x (формула получения точки пересечения отрезка с плоскостью) 8647 //t = far_clip - v2.x / v3.x - v2.x (формула получения точки пересечения отрезка с плоскостью)
8648 t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i].vWorldViewPosition.x - array_50AC10[i + 1].vWorldViewPosition.x);
8649 array_507D30[depth_num_vertices].vWorldViewPosition.x = pODMRenderParams->shading_dist_mist;
8650 //New_y = v2.y + (v3.y - v2.y)*t
8651 array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i].vWorldViewPosition.y + (array_50AC10[i].vWorldViewPosition.y - array_50AC10[i + 1].vWorldViewPosition.y) * t;
8652 //New_z = v2.z + (v3.z - v2.z)*t
8653 array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i].vWorldViewPosition.z + (array_50AC10[i].vWorldViewPosition.z - array_50AC10[i + 1].vWorldViewPosition.z) * t;
8654 array_507D30[depth_num_vertices].u = array_50AC10[i].u + (array_50AC10[i].u - array_50AC10[i + 1].u) * t;
8655 array_507D30[depth_num_vertices].v = array_50AC10[i].v + (array_50AC10[i].v - array_50AC10[i + 1].v) * t;
8656 array_507D30[depth_num_vertices]._rhw = 1.0 / pODMRenderParams->shading_dist_mist;
8657 }
8658 else//настоящая вершина больше границы видимости(следующая вершина меньше границы видимости) - v0
8659 {
8660 //t = far_clip - v1.x / v0.x - v1.x
8626 t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i + 1].vWorldViewPosition.x - array_50AC10[i].vWorldViewPosition.x); 8661 t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i + 1].vWorldViewPosition.x - array_50AC10[i].vWorldViewPosition.x);
8627 array_507D30[depth_num_vertices].vWorldViewPosition.x = pODMRenderParams->shading_dist_mist; 8662 array_507D30[depth_num_vertices].vWorldViewPosition.x = pODMRenderParams->shading_dist_mist;
8628 //New_y = v2.y + (v3.y - v2.y)*t 8663 //New_y = (v0.y - v1.y)*t + v1.y
8629 array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i].vWorldViewPosition.y + (array_50AC10[i + 1].vWorldViewPosition.y - array_50AC10[i].vWorldViewPosition.y) * t; 8664 array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i].vWorldViewPosition.y + (array_50AC10[i + 1].vWorldViewPosition.y - array_50AC10[i].vWorldViewPosition.y) * t;
8630 //New_z = v2.z + (v3.z - v2.z)*t 8665 //New_z = (v0.z - v1.z)*t + v1.z
8631 array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i].vWorldViewPosition.z + (array_50AC10[i + 1].vWorldViewPosition.z - array_50AC10[i].vWorldViewPosition.z) * t; 8666 array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i].vWorldViewPosition.z + (array_50AC10[i + 1].vWorldViewPosition.z - array_50AC10[i].vWorldViewPosition.z) * t;
8632 array_507D30[depth_num_vertices].u = array_50AC10[i].u + (array_50AC10[i + 1].u - array_50AC10[i].u) * t; 8667 array_507D30[depth_num_vertices].u = array_50AC10[i].u + (array_50AC10[i + 1].u - array_50AC10[i].u) * t;
8633 array_507D30[depth_num_vertices].v = array_50AC10[i].v + (array_50AC10[i + 1].v - array_50AC10[i].v) * t; 8668 array_507D30[depth_num_vertices].v = array_50AC10[i].v + (array_50AC10[i + 1].v - array_50AC10[i].v) * t;
8634 array_507D30[depth_num_vertices]._rhw = 1.0 / pODMRenderParams->shading_dist_mist; 8669 array_507D30[depth_num_vertices]._rhw = 1.0 / pODMRenderParams->shading_dist_mist;
8635 } 8670 }
8636 else//настоящая вершина больше границы видимости(следующая вершина меньше границы видимости) - v0
8637 {
8638 //t = far_clip - v1.x / v0.x - v1.x
8639 t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i + 1].vWorldViewPosition.x - array_50AC10[i].vWorldViewPosition.x);
8640 array_507D30[depth_num_vertices].vWorldViewPosition.x = pODMRenderParams->shading_dist_mist;
8641 //New_y = (v0.y - v1.y)*t + v1.y
8642 array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i + 1].vWorldViewPosition.y + (array_50AC10[i].vWorldViewPosition.y - array_50AC10[i + 1].vWorldViewPosition.y) * t;
8643 //New_z = (v0.z - v1.z)*t + v1.z
8644 array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i + 1].vWorldViewPosition.z + (array_50AC10[i].vWorldViewPosition.z - array_50AC10[i + 1].vWorldViewPosition.z) * t;
8645 array_507D30[depth_num_vertices].u = array_50AC10[i + 1].u + (array_50AC10[i].u - array_50AC10[i + 1].u) * t;
8646 array_507D30[depth_num_vertices].v = array_50AC10[i + 1].v + (array_50AC10[i].v - array_50AC10[i + 1].v) * t;
8647 array_507D30[depth_num_vertices]._rhw = 1.0 / pODMRenderParams->shading_dist_mist;
8648 }
8649 ++depth_num_vertices; 8671 ++depth_num_vertices;
8650 } 8672 }
8651 if ( !next_vertices_flag )//оба в границе видимости 8673 if ( !next_vertices_flag )//оба в границе видимости
8652 { 8674 {
8653 memcpy(&array_507D30[depth_num_vertices], &array_50AC10[i + 1], sizeof(array_507D30[depth_num_vertices])); 8675 memcpy(&array_507D30[depth_num_vertices], &array_50AC10[i + 1], sizeof(array_507D30[depth_num_vertices]));
8654 depth_num_vertices++; 8676 depth_num_vertices++;
8655 } 8677 }
8656 current_vertices_flag = next_vertices_flag; 8678 current_vertices_flag = next_vertices_flag;
8657 }
8658 for (uint i = 0; i < depth_num_vertices; ++i)// есть ли пограничные вершины
8659 {
8660 if ( array_507D30[i].vWorldViewPosition.x > pODMRenderParams->shading_dist_mist )
8661 {
8662 __debugbreak();
8663 }
8664 } 8679 }
8665 return depth_num_vertices >= 3 ? depth_num_vertices : 0; 8680 return depth_num_vertices >= 3 ? depth_num_vertices : 0;
8666 } 8681 }
8667 8682
8668 //----- (0047840D) -------------------------------------------------------- 8683 //----- (0047840D) --------------------------------------------------------