Skip to content

42henry/herb-engine-C-3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

236 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

herb-engine-C-3D

Playground for 3D rendering from scratch!
I know nothing about graphics, all I want is an array of pixels, that I can update each frame with my own functions, this is my attempt to make a 3D game like minecraft! I have used gpt to help write the x11 or winapi parts of the code, so I can just have my array of pixels that I update each frame. I also used gpt to make the perlin noise function, as the maths for this is outside project scope, but I thought it would be nice to have. Everything else is from scratch!

Work done so far:

  • a fill function that takes 4 points, a colour, and fills it in
  • a rotate and project function that takes an x y and z and rotates it about the camera using a global x and y rotation, and projects it by z
  • texture mapping, which takes each cube face, and colours it pixel by pixel from a given texture
  • simple cubicy collisions
  • simple hotbar/hand with different blocks accesible by pressing 1-9
  • back face culling, neighbour face culling
  • placing and removing cubes within any chunk
  • chunk system with dynamically saved chunk edits
  • chunk generation from a given noise function
  • tree/structure generation saved using the chunk edits
  • fog at chunk borders
  • day night cycle
  • transparent water blocks that don't have collisions

Known issues:

  • rendering issues when some points of a square have negative z values

Performance:

  • from profiling I can see that the fill square function accounts for nearly half the total program instructions
  • cache hits seem good, so the next step would be to come up with a faster fill square algorithm...
  • I tried a few similar variations with fewer conditionals, but with little difference so I'm happy with this.

Next steps:

  • I've come up with a way to make the sunlight better:
    • store the sun as a point on a semicircle centred around a cube, with a large enough radius
    • as the point moves around, calculate the distance from each face of the cube, to the point
    • the difference between the closest face, and the furthest face represents a scale from completely dark, to completely bright
    • use that scale to colour each face a certain brightness based on their distance to the sun
  • I'd also love to try use sockets to make multiplayer from scratch - or just use enet...
  • biomes sounds like a tough nut to crack so I'd love to try that some time too!
  • Also I should really only rotate and project 8 coords of the cube, and do the texturing afterwards...
  • Instead of reinventing the wheel for everything, I'd love to build this again in C from scratch, but do research into how it's actually done!
  • From minimal googling since finishing the project, I would love to do:
    • Z buffering, vertex buffering (don't rebuild everything every frame, buffer verticies of faces we can see, only update if chunk changes, or cube changes)
    • Frustrum culling

To compile:

  • linux:
    • gcc -o DigMake.o -lX11 -lm -O3 -march=native ./linux-platform.c
  • Windows:
    • gcc -o DigMake.exe -O3 -march=native windows-platform.c -lgdi32 -lwinmm -mwindows
  • Web:
    • emcc main_web.c -O2 -lm -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_RUNTIME_METHODS='["ccall"]' -s EXPORTED_FUNCTIONS='["_main","_set_holding_mouse"]' -o DigMake.html

Or play right now (warning: may crash):
https://42henry.github.io/digmake-test/

Dev screenshots:

screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot screenshot

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages