Saturday, June 29, 2013

Introduction Part3 - Some small Examples

In the last Post i promised some Pictures, here they are. I have nothing fancy to show yet, but i think i can show some of my Testprograms.

The first one started as a Testcase for a general Voxelchunk, and then i used it to test out some Random Generators and Geometry Shaders.

I intended to make some Minecraftlike Terrain Generator, but this is not even near to be done... At the moment it just generates one 42x42x42 Chunk of Voxels and set their Values according to one of ten Random Generators, the Standard is Worley Noise - the others are more Primitive. To Render those Voxels, i can choose between the Old OpenGL1.0 Method (Intermediate Mode) where i draw a Cube out of six Quads for each Voxel, or a Geometry Shader where i just send the Voxeldata as Pointcloud to the Graphics Card (in Intermediate Mode, or as Vertex Array, Display List or Vertex Buffer) and the Shader then Draws a Cube for each Point. As i started this Program while still learning about modern OpenGL it was very useful to see the differences between those techniques... The Key-difference is Speed! When drawing everything in OpenGL 1.0 Mode, it needs to be heavily optimized to get Framerates above 10fps, while with VBO and Shaders it goes easily over 200fps even without optimization.

This Project helped me a lot, figuring out how to use VBOs and Shaders, so the initial purpose (to create anice working VoxelchunkObject) was dropped. But i will get back to it later.
Oh, and in the Background you can see a Part of my Compile Script at Work ;).



In this next Program i tried to create an Terrain patch Object which should select a LOD (Level of Detail) depending on the Distance to the Viewpoint.
I am using a QuadTree here to store the Patches and select the proper LOD. I did not test Heightmap and Textures yet, but the Code is already clumsy and ugly... so i think i will start this from scratch before adding Features
This Sphere is composed of six seperated Terrain Objects which are deformed to form a Sphere by this simple formula (in Pseudocode):

for each Vector v:
    v = (((v - CenterOfSphere)/DistanceToCenter)*Radius)+Height;

Altough "Height" is not used yet (as there is no heightmap or something similar). To have some Visual clue about what is going on until i add Textures, i colored the edges according to X/Y Values. So i can see where the Patches divide.

As i said, nothing fancy yet. Maybe if i get some Readers on this Blog, it would motivate me to produce something better-looking ;). I have many more Testprograms but those two i think are best suited to show what i am up to, and how i work on this. But if someone is interested i will show more, and i could also go into more detail on how i do certain things...

Friday, June 28, 2013

Introduction Part2 - The Plan

Before i get to the actual Plan, there are still some things i want to mention.

My Tools

 Over the years, i got used to a certain workflow. As i always wanted to know how things really work, and have control over everything in my Code i never used an IDE for long, instead i write my Code in a Texteditor(with code highlighting and block folding i admit ;) ) and compile at the shell. Over time i developed some Scripts to make some things easier, but most of the Time i do everything by Hand, and organize (well sort of ;) ) my Projects by myself in Folders. So here is my Development Environment:
for Coding:
  • Notepad++
  • MinGW-GCC 4.7
  • handwritten Compile- and Backup-Scripts
for Design:
  • Blender3D
  • GIMP 
and the Languages i mainly use:
  • C/C++ 
  • Assembler
  • GLSL
  • Python (for Blender Plugins when needed)
  • OpenCL (Maybe)
My Machines are running Win7 64bit, Win8 32bit, possibly Linux again ( any distro), and i may even have access to OsX Snow Leopard and Lion... but i will mainly code on Windows. At the moment i have no intention of going multiplattform, but i may do nonetheless... I am trying to be independent on third-party Libraries, so i will avoid them. Although i use glfw to create Windows and get a decent OpenGL-Context. And i might also use SDL, SLFW or Irrlicht for some side-projects to provide Features i have not yet implemented, but not for the final build of "Magrathea" - if i ever get to this Point ;).

The Codebase

the Past

As i said, i started several times to develop something like an Engine, but never finished one of these. Although once, i nearly got to the point where i could have said to have an working alpha... i could load textured, skeletal animated meshes from a selfmade Fileformat, Render them animated and with rudimentary Lighting and Shadows, and i had an ugly-but-working GUI... yeah nothing like modern Engines, but i made it all by myself and from scratch while still learning how to code! But then i realised, as i learned more and more, i needed to change a LOT, and this Project was not really modular, so i spent days on fixing all the Code after one little change - thats a big motivation killer! Then i realized, all my Rendering Code was based on OpenGL 1.0, which was OLD... and very inefficient! My Model-Viewer was running very slow, while just drawing ONE lowpoly Model, a Grid and the GUI. So i deceided to learn more about modern techniques - at this time i knew less than nothing about Shaders, Vertex Buffers etc... and by learning about that, i became so scared at the amount of work i had to put into it to change my Code. It would actually be easier to start all over again... so i did. But after that my motivation was so low i never again got an Engine to this Level - the best i got was a (still unfinished) basic Check Game, and some halfhearted attempts at recreating Parts of my old Engine - which was a nuisance  because of the unorganized and often changed old Pile of Code. Now it was Time to find a new way!

The Plan

Although it is my Long-Time-Goal to write a complete Engine, i will not try to do so right now! I will try to first build small independent Modules, by trying out everything that i am interested in, which i will later (when they all work as they should) combine to build an alpha of the Engine. And then Develop on top of that...
So at the Moment i am just searching for different techniques, technologies, methods, algorithms and try them out in an minimal Environment. Then i extract that piece of Code, make it modular and independent, and work on it as i find issues by using it in a different Test.
Here is what i have so far:
  • 3D Base Object 
    • Contains basic Information like ModelMatrix + Vectors (Position, Front, Right, Up), Bounding Sphere, Bounding Box, and Pointers to Parent and Childs
    • Is usable to set the Camera-Viewpoint
  • GL Shader Wrapper
    • Able to load Compile and Bind Shader Programs from File or as char Array from RAM
    • Setup Uniform Values
  • OpenCL Wrapper
    • Able to load Compile and Run CL Kernels from File or as char Array from RAM
    • Create Memory Locations and fill them with Data to process
    • Load Processed Data
  • A State Machine/Manager
    • Able to Manage Program-Flow or AI Decisions(at least i hope so) through States
  • GL Vertex Array (RAM) / Vertex Buffer/ Display List Wrapper
    • Collect Data
    • Setup and Draw Arrays or Buffers as needed or Compile as Display List
    • Not finished yet! Planned is a complete OpenGL Buffer Object Wrapper including:
      • Frame Buffer Objects
      • Pixel Buffer Objects
      • Vertex Array Objects 
  • Simple Worley Noise Generator
    • somewhat useful, but i want to revisit this together with some more noise algos
  • The Text Part of my Old ugly GUI
    • Does not Support Newlines yet
    • Needs revisiting when i am working on GUI Code
  • QuadTree Based Terrain
    • still has Seams where Two Patches of Different LOD meet
    • I did no Tests with Heightmap or Textures yet
    • needs heavy revisiting
  •  Basic PlanetObject Code
    • At the Moment just a Placeholder which Wraps six QT-Terrain Patches arround to form a Sphere
  • A Voxel Chunk Object
    • still in Testphase
    • I am still searching for an fitting algorithm for poligonization...
  • An Basic Command Parser
    • shall be revisited and converted to a fullfledged Console as soon as i have a working GUI
And here are some things i definitly plan to do:
  •  For the Basic Engine
    • SceneManager To manage and draw All Visible Objects and responsible for:
      • Shader selection
      • Instancing
      • Distance Deformation/Deplacement ( I will talk about that later)
      • Calling to Physics where needed
    • TextureManager To collect needed Textures and prepare them
    • Static and Animated Meshes (Voxel and Polygon based)
    • Proper lighting
  • For the Universe Generation
    • Newtonian Physics (for stellar Objects and Spaceflight)
    • Procedural City and Architecture Generators (I think i will contact +Miguel Cepero from Procworld for advice on this one, when im ready ;) )
    • Procedural Plant Generator
    • Procedural Landscape Generator (as soon as i have my Terrain Patches and Voxel Chunks running)
    • In general, learn as much as possible about procedural and fractal algorithms
  • Try out
    • Volumetric Clouds/Fog
    • Atmospheric Scattering Shaders
    • Voxel manipulation
    • Voxel Animation (I know this has been tried many times with mediocre results, but i cant resist ;) )
    • Different Methods of Voxel Representation and Storage
    • LOD based Hybrid Voxel/Polygon Terrain
    • Multilayered Planets (so you can actualy dig to the Core...)

A faraway Goal...

... i know, but i have no Deadlines and no pressure at all to finish anything. I have fun researching and trying things out though! So i will just go on and see where i end :) . I hope this Blog will help me stay motivated.
 I am Sorry for this second Wall of Text without Explanation for those who dont actually do Graphics Programming. Please, if you somehow found this Blog and read this far, ask Questions, give Feedback... I am new to the World of Blogging and dont know at all what i am doing here ;) . I just write down what comes to my Mind, and hope someone will read it and give Feedback. But as i know, people like Pictures, i made some Screenshots from two of my Testcases, and i will tell you a little bit about them - in the next Post.

Introduction / The Journey Begins

The Purpose of this Blog

In this Blog, i will write about me, trying to build a virtual Universe from scratch... More specifically, i am coding a Game/Simulation Engine which should be able to generate procedural content on every scale. I know this is possible, i just dont know how (yet) - but i want to figure it out! This is a Hobby-Project so i will not promise to finish or release anything (although i really hope to). I will not even promise to regularly update this Blog. But in the last few years, searching for techniques, technologies and algorithms i came across many Blogs of people who, like me tried to build Games or Engines from scratch. I got a whole lot of inspiration from those people, and i found that most of them got a lot of motivation from the comments and discussions on their Blogs. So i thought why not start a Blog myself? I could really do with some extra motivation, and i would be really proud, if i managed to inspire someone!

I also want to recommend two of my favorite Blogs, if you are interested in Game/Graphics Programming Voxels and Procedural Content Creation they are definitely worth a look!
procworld.blogspot.com - all about creating procedural Voxel-Content in a endless world, some nice info about poligonizing Voxels, and more...
www.sea-of-memes.com - one man trying to build a Game in a Voxel-based Blockworld ( somewhat like minecraft but different ;) )...
Many of you will already know those Blogs, but i had to mention them, because those two people are just amazing and inspired me a lot! (If you two read this someday: I want to say thank you! And keep up the great work!)

What is this Blog about?

I intent to write mostly about this Project: "Magrathea" (Working Title) - a Game/Simulation Engine, able to proceduraly generate Galaxies, Solar Systems, Planets, Continents, Countries, Cities etc... at least thats the Plan ;). At the Moment i am not able to generate anything like that, but thats my ultimate goal. As i know myself, i will get sidetracked, bored and frustrated a lot on the way... so i think i will write (or rant) about many things related to programming, not only this Project. I may also write some Tutorials, but we will see.

My Experience

I have no "Professional Experience" as i never had a Job as Developer, but i am quite good at learning self-educated. I began learning to code about 17 years ago (i was 9 years old), and started with HTML. About one year later i learned Real Basic, Omicron Basic and then C. It took a while to understand how everything works, but i had much fun coding. So learned more about programming Languages and computers in general, and tried out everything i could get my hands on. So i learned more Languages like C++, Assembler, PHP, Java, Python, Fortran, Pascal (in this order) and last year i even learned C#, i hesitated to do so, as i want to code as near to the Processor as possible and dont like scripting languages or compiling to vm-bytecode, for Application Development - and i dont like Microsoft Products in General.
 I wrote many many small and mostly useless little programs, just for fun, and for learning purposes. I became interested in Graphics programming. So i wanted to try and make a Game (what a surprise ;) ). At this time i was not very experienced, so i tried some tutorials first... most of them were using Visual C++ and DirectX an Win32... did i mention my dislike for MS-Products? Here is why(related to coding): Coding the Win32 API is UGLY and gave me serious headaches, DirectX is not a bit better! VC++ (and all other Visual XXX IDEs) is just like "click there and let me load your project with a huge package of unnecessary code automatically, just dont bother learning how it really works"... btw. that is actually also the attitude of most (fortunately not all) Tutorials, which i think makes them rather useless. Finaly i found some Tutorials for OpenGL (most OpenGL Coders will remember NeHe ;) ) and some libs to avoid the Win32 API (especialy SDL).
Well, long Story short: i tried to write a Game - and got stuck. But that was a long time ago, and in the meantime i started several Game-Engine Projects, and everytime i got stuck on something else... lack of experience, unorganized code, lack of time, lack of motivation... and some more. But everytime i learned something more and now i will try it again - but different.

To be continued...

I wanted to write more for introduction... but i think this is enough for my very first Blogpost ever. Nobody wants to start reading with a Wall of Text ;). The rest will go to the second post, which will probably come sooner than any readers :D.
Last but not least: SORRY if my english is bad... i am not a native english speaker, and i had very little practice in actually speaking (or writing) english, in the last few years... so please be patient, i will improve ;)