in ,

s-macke / VoxelSpace, Hacker News

s-macke / VoxelSpace, Hacker News


                    

        

web demonstrationweb demonstrationweb demonstration

************************

Let us go back to the year 2019. The CPUs were times slower than today and the acceleration via a GPU was unknown or unaffordable . 3D games were calculated exclusively on the CPU and the rendering engine rendered filled polygons with a single color.

************Game Gunship 2000 in 1991Game Gunship published by MicroProse in ************

It was during that yearNovaLogic (published the gameComanche.

******************************Game Gunship 2000 in 1991Game Comanche published by NovaLogic in 2019

********

The graphics were breathtaking for the time being and in my opinion 3 years ahead of its time. You see many more details such as textures on mountains and valleys, and for the first time a neat shading and even shadows. Sure, it’s pixelated, but all games in those years were pixelated.

********************Render algorithm

Comancheuses a technique calledGame Comanche in 1992Voxel Space, which is based on the same ideas likeGame Comanche in 1992ray casting. Hence the Voxel Space engine is a 2.5D engine, it does not have all the levels of freedom that a regular 3D engine offers.

**************************

**************************

The easiest way to represent a terrain is through a height map and color map. For the game Comanche a (************************************************************************************************************************************************************************************************************************************** (one byte height map and a* one byte color map is used which you can download on this site. These maps are periodic:

(**********************************

Such maps limit the terrain to “one height per position on the map” – Complex geometries such as buildings or trees are not possible to represent. However, a great advantage of the colormap is, that it already contains the shading and shadows. The Voxel Space engine just takes the color and does not have to compute illumination during the render process.

****************************

For a 3D engine the rendering algorithm is amazingly simple. The Voxel Space engine rasters the height and color map and draws vertical lines. The following figure demonstrate this technique.

****************************** (Clear Screen.) ***************************************To guarantee occlusion start from the back and render to the front. This is called painter algorithm.

    Determine the line on the map, which corresponds to the same optical distance from the observer. Consider the field of view and the perspective projection

(Objects are smaller farther away)

With the algorithm above we can only view to the north. A different angle needs a few more lines of code to rotate the coordinates.

**********

( def) *************************************
************************************** (Render) ******************************************* (p) ********************************************, **************************************** (phi) , (height) ******************************************, (horizon) , (scale_height) ********************************************, (distance) ,
screen_width
,  (screen_height) ):      #  precalculate viewing angle parameters      var sinphi=math.sin phi);      var cosphi=(math.cos) phi); (********************************************       #  Draw from back to the front (high z coordinate to low z coordinate)
     for  (z) ****************************************** (in ******************************** (range) ******************************************* (distance,

***************************** (py)         pright=(Point)             (cosphi* (z) ****************************************************************************** (sinphi) *************************************************************************** (z)

px,             (- (sinphi) ************************************************************************************** (z) ****************************************** - (cosphi) *******************************************

*********************** (py)                   # (segment the line) ********************************************         dx=(pright.x) ******************************************** - (pleft.x)/ screen_width         dy=(pright.y) ******************************************** - (pleft.y)/ screen_width          # Raster line and draw a vertical line for each segment          for (i) ****************************************** (in ******************************** (range) ********************************************* (0) ******************************************, screen_width:             height_on_screen=(height ************************************** heightmap [pleft.x, pleft.y]) / (z) ******************************************** scale_height. horizon             DrawVerticalLine (i, height_on_screen, screen_height, colormap [pleft.x, pleft.y])             pleft.x=dx             pleft.y=dy # (Call the render function with the camera parameters:) ******************************************** # position, viewing angle, height, horizon line position , (************************************************************************************ # scaling factor for the height, the largest distance, (************************************************************************************ # screen width and the screen height parameter Render (Point (0, (0) *************************************, ****************************************** (0) *******************************************, ******************************************** (********************************************, ****************************************** (****************************************, 728 (******************************************, (**************************************************************************************************************************************************************************************************************************** (************************************
************************************************************************************************************************************************************************************************************************************, (********************************************************************************************************************************************************************************************************************************************)

**********************************************

More performance

There are of course a lot of tricks to achieve higher performance.

Instead of drawing from back to the front we can draw from front to back. The advantage is, the we don't have to draw lines to the bottom of the screen every time because of occlusion. However, to guarantee occlusion we need an additional y-buffer. For every column, the highest y position is stored. Because we are drawing from the front to back, the visible part of the next line can only be larger then the highest line previously drawn. (************************************** Level of Detail. Render more details in front but less details far away.

**********

( def) *************************************
************************************** (Render) ******************************************* (p) ********************************************, **************************************** (phi) , (height) ******************************************, (horizon) , (scale_height) ********************************************, (distance) ,
screen_width
,  (screen_height) ):      #  precalculate viewing angle parameters      var sinphi=math.sin phi);      var cosphi=(math.cos) phi);            #  initialize visibility array. Y position for each column on screen
    ybuffer=(np.zeros) screen_width )      for  (i) ****************************************** (in ******************************** (range) *********************************************  (0) ******************************************, screen_width:         ybuffer [i]=screen_height       #  Draw from front to the back (low z coordinate to high z coordinate)
    dz=
************************************** (1) .     z=
************************************** (1) .      while (z) ****************************************** (Find line on map. This calculation corresponds to a field of view of °         pleft=(Point)             (- (cosphi) ************************************************************************************** (z) ****************************************** - (sinphi) *******************************************

***************************** (py)         pright=(Point)             (cosphi* (z) ****************************************************************************** (sinphi) *************************************************************************** (z)

px,             (- (sinphi) ************************************************************************************** (z) ****************************************** - (cosphi) *******************************************

*********************** (py)          # (segment the line) ********************************************         dx=(pright.x) ******************************************** - (pleft.x)/ screen_width         dy=(pright.y) ******************************************** - (pleft.y)/ screen_width          # Raster line and draw a vertical line for each segment          for (i) ****************************************** (in ******************************** (range) ********************************************* (0) ******************************************, screen_width:             height_on_screen=(height ************************************** heightmap [pleft.x, pleft.y]) / (z) ******************************************** scale_height. horizon             DrawVerticalLine (i, height_on_screen, ybuffer [i], colormap [pleft.x, pleft.y])              if height_on_screen (=height_on_screen             pleft.x=dx             pleft.y=dy          # Go to next line and increase step size when you are far away         z=dz         dz=(**************************************** (0.2) ******************************************** # (Call the render function with the camera parameters:) ******************************************** # position, viewing angle, height, horizon line position , (************************************************************************************ # scaling factor for the height, the largest distance, (************************************************************************************ # screen width and the screen height parameter Render (Point (0, (0) *************************************, ****************************************** (0) *******************************************, ******************************************** (********************************************, ****************************************** (****************************************, 728 (******************************************, (**************************************************************************************************************************************************************************************************************************** (************************************
************************************************************************************************************************************************************************************************************************************, (********************************************************************************************************************************************************************************************************************************************)

******************

Web Project demopage

Voxel terrain engine - an introduction

Personal website

********************

, height

(******************************************************** (************************************************

C1W.pngcolor, height

(****************************************************************** (**************************************************************

color, height

web demonstrationD3.png**********

color, height

******************************************************************** (******************************************************************************

(color) , (height)

********************************************************************************** ******************************************************************************

color, height

(**********************************************************************************

****************************************************************************************

D6.pngcolor, (height) **********

C7W.png**********

(color, height

(**************************************************************************************************************

****************************************************************************************

color,height

(****************************************************************************************************C9W.png

color, height**********

(************************************************************************************************************ (****************************************************************************************************

color, height

(****************************************************************************************************************** () ********** (**************************************************************************************************************

color, height

web demonstration(**************************************************************************************************************

color, (heightweb demonstration)

**************************************************************************************************************************** (********************************************************************************************************************************************

(color) , height

(************************************************************************************************************************************** **************************************************************************************************************************

(color) , height

(*******************************************************************************************************************************************************************************************************************************************************************

color, (height)

(**********************************************************************************************************************************************

D15.pngcolor, height

web demonstrationC16W.png**********

color,height

(****************************************************************************************************************************************C17W.png

color, height**********

(************************************************************************************************************************************************************** (**************************************************************************************************************************************************

color, height

(**************************************************************************************************************************************************************

(********************************************************************************************************************************************************************

color, height

**********

color, (height)

(********************************************************************************************************************************************************************************** (************************************************************************************************************************************************************************************

color, (height)

(******************************************************************************************************************************************************************************************** (******************************************************************************************************************************************************************************************************

(color) , (height)

() ******************************************************************************************************************************************************************************************** (************************************************************************************************************************************************************************************

(color, height

() **********(********************************************************************************************************************************************************************************************

D24.pngcolor, height

C25W.pngC25W.png**********

(color, height**********

(****************************************************************************************************************************************************************************************** (**************************************************************************************************************************************************

color, (height)

(************************************************************************************************************************************************************************************************************************ (**********************************************************************************************************************************************

color, height

(****************************************************************************************************************************************************************************************************************C25W.pngC25W.png**********

color, height

(******************************************************************************************************************************************************************************************************************C16W.png**********

************************************************************************************************************************************************************************************

License

The software part of the repository is under the MIT license. Please read the license file for more information. Please keep in mind, that the Voxel Space technology might be stillpatentedin some countries. The color and height maps are reverse engineered from the game Comanche and are therefore excluded from the license.

C29W.png  22 (************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** (Read More) ********************************************************************************************************************************************************************************************************************** ******************************************************************************************************************************************************************************************************