Planet generation in real time.....

posted in Orden Drakona
Published November 16, 2018
Advertisement

Well we're back with a new entry.  As usual we have made a lot of bug fixes. The primary new feature though is the separation of graphics, and planet generation in different threads. Here's the somewhat familiar code that was modified from our first entry....


void CDLClient::InitTest2()
{
   this->CreateConsole();
   printf("Starting Test2\n");
   fflush(stdout);

   // Create virtual heap
   m_pHeap = new(MDL_VHEAP_MAX, MDL_VHEAP_INIT, MDL_VHEAP_HASH_MAX) CDLVHeap();
   CDLVHeap *pHeap = m_pHeap.Heap();

   // Create the universe
   m_pUniverse = new(pHeap) CDLUniverseObject(pHeap);

   // Create the graphics interface
   CDLDXWorldInterface *pInterface = new(pHeap) CDLDXWorldInterface(this);

   // Camera control
   double fMinDist = 0.0;
   double fMaxDist = 3200000.0;
   double fSrtDist = 1600000.0;

   // World size
   double fRad = 400000.0;

   // Fractal function for world
   CDLValuatorRidgedMultiFractal *pNV = new(pHeap) CDLValuatorRidgedMultiFractal(pHeap,fRad,fRad/20,2.0,23423098);
   //CDLValuatorSimplex3D *pNV = new(pHeap) CDLValuatorSimplex3D(fRad,fRad/20,2.0,23423098);

   // Create world
   CDLSphereObjectView *pSO = new(pHeap) CDLSphereObjectView( pHeap, fRad, 1.0 , 0.25, 6, pNV );
   pSO->SetGraphicsInterface(pInterface);

   // Create an astral reference from the universe to the world and attach it to the universe
   CDLReferenceAstral *pRef = new(pHeap) CDLReferenceAstral(m_pUniverse(),pSO);
   m_pUniverse->PushReference(pRef);

   // Create the camera 
   m_pCamera = new(pHeap) CDLCameraObject(pHeap, FDL_PI/4.0, this->GetWidth(), this->GetHeight());
   m_pCamera->SetGraphicsInterface(pInterface);

   // Create a world tracking reference from the unverse to the camera
   m_pBoom = new(pHeap) CDLReferenceFollow(m_pUniverse(),m_pCamera(),pSO,fSrtDist,fMinDist,fMaxDist);
   m_pUniverse->PushReference(m_pBoom());

   // Set zoom speed in the client
   this->SetZoom(fMinDist,fMaxDist,3.0);
 
   // Create the god object (Build point for LOD calculations)
   m_pGod = new(pHeap) CDLGodObject(pHeap);

   // Create a reference for the god opbject and attach it to the camera
   CDLReference *pGodRef = new(pHeap) CDLReference(m_pUniverse(), m_pGod());
   m_pCamera->PushReference(pGodRef);

   // Set the main camera and god object for the universe'
   m_pUniverse->SetMainCamera(m_pCamera());
   m_pUniverse->SetMainGod(m_pGod());

   // Load and compile the vertex shader
   CDLUString clVShaderName = L"VS_DLDX_Test.hlsl";
   m_pVertexShader = new(pHeap) CDLDXShaderVertexPC(this,clVShaderName,false,0,1);

   // Attach the Camera to the vertex shader
   m_pVertexShader->UseConstantBuffer(0,static_cast<CDLDXConstantBuffer *>(m_pCamera->GetViewData()));

   // Create the pixel shader
   CDLUString clPShaderName = L"PS_DLDX_Test.hlsl";
   m_pPixelShader = new(pHeap) CDLDXShaderPixelGeneral(this,clPShaderName,false,0,0);

   // Create a rasterizer state and set to wireframe
   m_pRasterizeState = new(pHeap) CDLDXRasterizerState(this);
   m_pRasterizeState->ModifyState().FillMode = D3D11_FILL_WIREFRAME;

   // Initailze the universe
   m_pUniverse()->InitFromMainCamera();

   // Run the universe!
   m_pUniverse->Run();

}


Right at the end we call "m_pUniverse->Run();". This actually starts the build thread. What it does is continuously look at the position of the god object which we have attached to the camera above in the code, and build the planet with the appropriate LOD based on it's proximity to the various terrain chunks.........Let's not bore you with more text or boring pictures. Instead we will bore you with a boring video:
 

As you can see it generates terrain reasonably fast.  But there is still a lot more we can do. First off we should eliminate the backside of the planet.  Note that as we descend towards the planet the backside becomes bigger and bigger as the horizon becomes closer and closer to the camera. This is one advantage of a spherical world.  Second we can add a lot more threads. In general we try to cache as much data as possible.  What we can still do is pre-generate our octree at one level down using a fractal function pipeline.  In general most the CPU time is spent in the fractal data generation, so it makes sense to put add more threading there.  Fortunately this is one of the easier places we can use threading. For our next entry we hope to go all the way down to the surface and include some nominal shading.

Previous Entry Mountain Ranges
Next Entry Here comes the sun!
6 likes 4 comments

Comments

Rutin

You're a true wizard!!! ? Very nice job! :) 

November 16, 2018 11:08 PM
Gnollrunner
8 hours ago, Rutin said:

You're a true wizard!!! ? Very nice job! :) 

Thanks. We have mall called Oz Mall in my city. I guess I should start hanging out there :D

November 17, 2018 07:27 AM
Rutin

Awesome  :D Well I can't wait to see what is next!

November 17, 2018 12:00 PM
Nick Griffith

That's awesome!

November 17, 2018 02:34 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Advertisement