Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 880 vs 881 for /trunk/Source Code/Environment/Terrain/Terrain.cpp

Diff revisions: vs.
  @@ -8,6 +8,7 @@
8 8 #include "Core/Math/Headers/Transform.h"
9 9 #include "Graphs/Headers/SceneGraphNode.h"
10 10 #include "Managers/Headers/SceneManager.h"
11 + #include "Geometry/Shapes/Headers/Predefined/Patch3D.h"
11 12
12 13 #include "Geometry/Material/Headers/Material.h"
13 14 #include "Platform/Video/Headers/GFXDevice.h"
  @@ -51,7 +52,6 @@
51 52 // stop subdividing a terrain patch once it's width is
52 53 // less than the cutoff
53 54 #define VMB_TERRAIN_REC_CUTOFF 10
54 - #define MAX_TERRAIN_NODES 500
55 55
56 56 terrainNode_t *terrainTree;
57 57 terrainNode_t *terrainTreeTail;
  @@ -62,7 +62,7 @@
62 62 */
63 63 terrainNode_t* createNode(terrainNode_t *parent, U8 type, F32 x, F32 y, F32 z, F32 width, F32 height)
64 64 {
65 - if (numTerrainNodes >= MAX_TERRAIN_NODES)
65 + if (numTerrainNodes >= Terrain::MAX_RENDER_NODES)
66 66 return NULL;
67 67 numTerrainNodes++;
68 68
  @@ -88,7 +88,7 @@
88 88 void terrain_clearTree()
89 89 {
90 90 terrainTreeTail = terrainTree;
91 - memset(terrainTree, 0, MAX_TERRAIN_NODES * sizeof(terrainNode_t));
91 + memset(terrainTree, 0, Terrain::MAX_RENDER_NODES * sizeof(terrainNode_t));
92 92 numTerrainNodes = 0;
93 93 }
94 94
  @@ -205,7 +205,7 @@
205 205 */
206 206 void terrain_init()
207 207 {
208 - terrainTree = (terrainNode_t*)malloc(MAX_TERRAIN_NODES * sizeof(terrainNode_t));
208 + terrainTree = (terrainNode_t*)malloc(Terrain::MAX_RENDER_NODES * sizeof(terrainNode_t));
209 209 terrain_clearTree();
210 210 }
211 211
  @@ -374,14 +374,14 @@
374 374
375 375 SceneGraphNode_ptr planeSGN(sgn.addNode(_plane, normalMask, PhysicsGroup::GROUP_STATIC));
376 376 planeSGN->setActive(false);
377 - /*for (TerrainChunk* chunk : _terrainChunks) {
378 - SceneGraphNode_ptr vegetation = sgn.addNode(Attorney::TerrainChunkTerrain::getVegetation(*chunk), normalMask);
379 - vegetation->lockVisibility(true);
380 - }*/
377 + for (TerrainChunk* chunk : _terrainChunks) {
378 + //SceneGraphNode_ptr vegetation = sgn.addNode(Attorney::TerrainChunkTerrain::getVegetation(*chunk), normalMask);
379 + //vegetation->lockVisibility(true);
380 + }
381 381 // Skip Object3D::load() to avoid triangle list computation (extremely expensive)!!!
382 382
383 383 ShaderBufferParams params;
384 - params._primitiveCount = MAX_TERRAIN_NODES;
384 + params._primitiveCount = Terrain::MAX_RENDER_NODES;
385 385 params._primitiveSizeInBytes = sizeof(Test::NodeData);
386 386 params._ringBufferLength = 1;
387 387 params._unbound = true;
  @@ -389,7 +389,7 @@
389 389
390 390 _shaderData = _context.newSB(params);
391 391 sgn.get<RenderingComponent>()->registerShaderBuffer(ShaderBufferLocation::TERRAIN_DATA,
392 - vec2<U32>(0, 1),
392 + vec2<U32>(0, Terrain::MAX_RENDER_NODES),
393 393 *_shaderData);
394 394
395 395 Test::terrain_init();
  @@ -408,7 +408,6 @@
408 408 // The terrain's final bounding box is the QuadTree's root bounding box
409 409 _boundingBox.set(_terrainQuadtree.computeBoundingBox());
410 410
411 -
412 411 const Material_ptr& mat = getMaterialTpl();
413 412
414 413 const vec3<F32>& bbMin = _boundingBox.getMin();
  @@ -489,20 +488,22 @@
489 488
490 489 g_PlaneCommandIndex = drawCommandsInOut.size();
491 490 if (renderStagePass._stage == RenderStage::DISPLAY) {
492 -
493 - cmd.primitiveType(PrimitiveType::TRIANGLES);
494 - cmd.disableOption(GenericDrawCommand::RenderOptions::RENDER_TESSELLATED);
495 491 //infinite plane
496 - VertexBuffer* const vb = _plane->getGeometryVB();
497 - cmd.cmd().firstIndex = 0;
498 - cmd.cmd().indexCount = vb->getIndexCount();
499 - cmd.LoD(0);
500 - cmd.sourceBuffer(vb);
501 - drawCommandsInOut.push_back(cmd);
492 + GenericDrawCommand planeCmd;
493 + planeCmd.primitiveType(PrimitiveType::TRIANGLE_STRIP);
494 + planeCmd.cmd().firstIndex = 0;
495 + planeCmd.cmd().indexCount = _plane->getGeometryVB()->getIndexCount();
496 + planeCmd.LoD(0);
497 + planeCmd.sourceBuffer(_plane->getGeometryVB());
498 + planeCmd.shaderProgram(renderStagePass._passType == RenderPassType::DEPTH_PASS
499 + ? _planeDepthShader
500 + : _planeShader);
501 + drawCommandsInOut.push_back(planeCmd);
502 502
503 503 //BoundingBoxes
504 504 GenericDrawCommands commands;
505 505 commands.reserve(getQuadtree().getChunkCount());
506 +
506 507 _terrainQuadtree.drawBBox(_context, commands);
507 508 for (const GenericDrawCommand& crtCmd : commands) {
508 509 drawCommandsInOut.push_back(crtCmd);
  @@ -518,7 +519,6 @@
518 519 GenericDrawCommands& drawCommandsInOut) {
519 520
520 521 //_context.setClipPlane(ClipPlaneIndex::CLIP_PLANE_0, Plane<F32>(WORLD_Y_AXIS, _waterHeight));
521 -
522 522 //drawCommandsInOut.front().shaderProgram()->Uniform("dvd_waterHeight", _waterHeight);
523 523 drawCommandsInOut.front().shaderProgram()->Uniform("TerrainOrigin", vec3<F32>(-to_F32(_terrainDimensions.width) / 2.0f, -1024.0f / 2.0f, -to_F32(_terrainDimensions.height) / 2.0f));
524 524 drawCommandsInOut.front().shaderProgram()->Uniform("TerrainHeightOffset", 1024.0f);
  @@ -539,9 +539,14 @@
539 539
540 540 if (renderStagePass._stage == RenderStage::DISPLAY) {
541 541 // draw infinite plane
542 - drawCommandsInOut[g_PlaneCommandIndex].drawCount(0);
543 - //assert(drawCommandsInOut[g_PlaneCommandIndex].drawCount() == 1);
542 + assert(drawCommandsInOut[g_PlaneCommandIndex].drawCount() == 1);
544 543
544 + _planeShader->Uniform("underwaterDiffuseScale", _underwaterDiffuseScale);
545 + _planeDepthShader->Uniform("underwaterDiffuseScale", _underwaterDiffuseScale);
546 + drawCommandsInOut[g_PlaneCommandIndex].shaderProgram(
547 + renderStagePass._passType == RenderPassType::DEPTH_PASS
548 + ? _planeDepthShader
549 + : _planeShader);
545 550 size_t i = g_PlaneCommandIndex + 1;
546 551
547 552 if (_drawBBoxes) {
  @@ -549,15 +554,15 @@
549 554 commands.reserve(getQuadtree().getChunkCount());
550 555 _terrainQuadtree.drawBBox(_context, commands);
551 556
552 - for (const GenericDrawCommand& cmd : commands) {
553 - drawCommandsInOut[i++] = cmd;
557 + for (const GenericDrawCommand& bbCmd : commands) {
558 + drawCommandsInOut[i++] = bbCmd;
554 559 }
555 560
556 561 } else {
557 562 std::for_each(std::begin(drawCommandsInOut) + i,
558 563 std::end(drawCommandsInOut),
559 - [](GenericDrawCommand& cmd) {
560 - cmd.drawCount(0);
564 + [](GenericDrawCommand& bbCmd) {
565 + bbCmd.drawCount(0);
561 566 });
562 567 }
563 568 }
  @@ -638,6 +643,7 @@
638 643 posI.y >= 0 && posI.y < to_I32(_terrainDimensions.y) - 1);
639 644
640 645 vec3<F32> normals[4];
646 +
641 647 Util::UNPACK_VEC3(_physicsVerts[TER_COORD(posI.x, posI.y, to_I32(_terrainDimensions.x))]._normal, normals[0]);
642 648 Util::UNPACK_VEC3(_physicsVerts[TER_COORD(posI.x + 1, posI.y, to_I32(_terrainDimensions.x))]._normal, normals[1]);
643 649 Util::UNPACK_VEC3(_physicsVerts[TER_COORD(posI.x, posI.y + 1, to_I32(_terrainDimensions.x))]._normal, normals[2]);
  @@ -668,8 +674,8 @@
668 674 assert(posI.x >= 0 && posI.x < to_I32(_terrainDimensions.x) - 1 &&
669 675 posI.y >= 0 && posI.y < to_I32(_terrainDimensions.y) - 1);
670 676
671 -
672 677 vec3<F32> tangents[4];
678 +
673 679 Util::UNPACK_VEC3(_physicsVerts[TER_COORD(posI.x, posI.y, to_I32(_terrainDimensions.x))]._tangent, tangents[0]);
674 680 Util::UNPACK_VEC3(_physicsVerts[TER_COORD(posI.x + 1, posI.y, to_I32(_terrainDimensions.x))]._tangent, tangents[1]);
675 681 Util::UNPACK_VEC3(_physicsVerts[TER_COORD(posI.x, posI.y + 1, to_I32(_terrainDimensions.x))]._tangent, tangents[2]);