Jump to content
  • Advertisement
  • entries
    4
  • comments
    31
  • views
    1557

Planet generation in real time.....

Gnollrunner

740 views

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.



4 Comments


Recommended Comments

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

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By JeZ-l-Lee
      Hi,
      We are working on a sequel to my all time favorite application:
      "Garry Kitchen's GameMaker" for the Commodore 64.
      (it's a very simple game creation IDE)
      Application builds and runs on Windows(R) and Linux.
      (the only dependency is SDL2 and there is a makefile included to build on any Linux)
      NOTE: This is a just started work-in-progress...don't expect too much
      We will be updating this thread posting as production progresses.
      Please post complaints and suggestions to this forum thread.
      This is our most ambitious project to date so don't expect a beta for at least 6-12 months...
      Thanks!
      JeZxLee
      www.FallenAngelSoftware.com
      If you are unfamiliar with this superb game creation IDE then please check out the wiki below:
      en.wikipedia.org Garry Kitchen's GameMaker
      Garry Kitchen's GameMaker is an IDE for the Commodore 64, Apple II, and IBM PCs, created by Garry Kitchen and released by Activision in 1985. The software is notable as one of the earliest all-in-one game design products aimed at the general consumer, preceded by Broderbund’s The Arcade Machine in 1982. Two add-on disks are available for the Commodore 64 version: Sports, and Science Fiction. These include sprites, music, and background elements for loading into GameMaker. To demonstrate the vers...
        You can download the current entire project below on GitHub:
      GitHub FallenAngelSoftware/SDL2-C64GKGM2
      100% FREE Cross-Platform Open-Source SDL2 Video Game Engine! - FallenAngelSoftware/SDL2-C64GKGM2
        Here is a screenshot:

    • By Gnollrunner
      I was tying to figure out what to do with my procedural planets and for an initial step and I wanted to fly a spacecraft in and establish a low orbit around my world starting from some distant point and initial velocity.  I know how to set up the gravity and I think I can pretty much do manual controls that will simulate Newtonian physics. However what I'm looking for is some software or algorithms that let me establish the orbit by controlling thrust in the right direction at the appropriate points in a trip towards the planet.
      So I guess the software would accept something like starting position, starting velocity, desired orbit height (I'm assuming circular for now) , and desired orbit plane.  From there it would give me firing points, duration and trust vectors needed to for the orbit.  To make things simpler I'm assuming infinite fuel. I figure NASA must do stuff like this all the time but I haven't been able to find something solid on how it's done.  Perhaps it's too complex, I'm not really sure, but I thought I throw the question out there anyway.
    • By Ricardo3Ddev
      Hi guys! Our first game (Dongo Adventure) has just been released on Steam! I hope you have fun with the game! O/
      The game was produced by me and my brother for 11 months. We did everything with free and open source software (Blender 3D and Gimp).
      About the game: The game is 3D Platform style, inspired by the classic platform games (mainly 'Donkey Kong Country 2'), bringing all those challenges and fun of the genre. Thank you all for the support! 
      Steam Game Page: http://store.steampowered.com/app/811450/Dongo_Adventure/
      Official Trailer: 
       

    • By isu diss
      This post is about continuation of https://www.gamedev.net/forums/topic/699032-3d-rigidbody-simulation/. I have setup the Collision Detection and Collision Response for the cricket ball. But the ball doesn't bounce off the ground. After a bit of debugging, I've found that the impulse, generated when the ball bounces off the ground is very small. What should I do to make this right(right impulse)?
      Rigidbody.cpp XMVECTOR RigidBody::GetVelocityAtPoint(XMVECTOR p) { return (v + XMVector3Cross(Omega, (p - x))); } XMMATRIX RigidBody::GetIInverse() { return IInverse; } ...... CollisionResponse.cpp enum CollidingType { None = -1, MoveAway = 0, Resting = 1, Collide = 2 }; struct Contact { RigidBody *a, *b; XMVECTOR p, n; }; CollidingType VerifyTypeOfColliding(Contact *c) { XMVECTOR padot = c->a->GetVelocityAtPoint(c->p); XMVECTOR pbdot = c->b->GetVelocityAtPoint(c->p); XMVECTOR vrel = XMVector3Dot(c->n, (padot - pbdot)); if (vrel.m128_f32[0] > 0) return MoveAway; else if (vrel.m128_f32[0] == 0) return Resting; else if (vrel.m128_f32[0] < 0) return Collide; return None; } void CollisionResponse(Contact *c, float epsilon) { XMVECTOR padot = c->a->GetVelocityAtPoint(c->p); XMVECTOR pbdot = c->b->GetVelocityAtPoint(c->p); XMVECTOR n = c->n; XMVECTOR ra = (c->p - c->a->GetPosition()); XMVECTOR rb = (c->p - c->b->GetPosition()); XMVECTOR vrel = XMVector3Dot(c->n, (padot - pbdot)); float numerator = (-(1 + epsilon)*vrel.m128_f32[0]); float term1 = (1 / c->a->GetMass()); float term2 = (1 / c->b->GetMass()); XMVECTOR term3 = XMVector3Dot(c->n, XMVector3Cross(XMVector4Transform(XMVector3Cross(ra, n), c->a->GetIInverse()), ra)); XMVECTOR term4 = XMVector3Dot(c->n, XMVector3Cross(XMVector4Transform(XMVector3Cross(rb, n), c->b->GetIInverse()), rb)); float j = (numerator / (term1 + term2 + term3.m128_f32[0] + term4.m128_f32[0])); XMVECTOR f = (j*n); c->a->AddForce(f); c->b->AddForce(-f); c->a->AddTorque(XMVector3Cross(ra, f)); c->b->AddTorque(-XMVector3Cross(rb, f)); } ..... Collision Detection // BS - BoundingSphere class & Plane- Normal Plane class bool SpherePlaneIntersection(BS *CricketBall, Plane *CricketGround, Contact *c) { float dist = XMVector3Dot(XMLoadFloat3(&CricketBall->GetCenter()), XMLoadFloat3(&CricketGround->GetNormal())).m128_f32[0] - CricketGround->GetOffset(); c->a = rbBall; c->b = rbGround; if ((dist) <= CricketBall->GetRadius()) { c->n = XMLoadFloat3(&CricketGround->GetNormal()); c->p = XMLoadFloat3(&CricketBall->GetCenter()) - dist * XMLoadFloat3(&CricketGround->GetNormal()); return true; } else return false; return false; } ..... In the Rendering loop code Contact CBwithCG; if (SpherePlaneIntersection(cdBall, cdGround, &CBwithCG)) { if (VerifyTypeOfColliding(&CBwithCG) == Resting) { rbBall->AddForce(XMVectorSet(0, CB_Mass*g, 0, 0)); } else if (VerifyTypeOfColliding(&CBwithCG) == Collide) { CollisionResponse(&CBwithCG, .5f); } } else rbBall->AddForce(XMVectorSet(0, -CB_Mass*g, 0, 0));  
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!