This pseudo 3D engine will be implemented from scratch using only Windows Forms & C#.NET framework in Microsoft Visual Studio 2017.
To showcase my engine’s functionality I have created two demo levels: Park level with scrollable skybox, animated water floor texture, walls and moving sprites as well as Underground level with solid floor and ceiling as well as in-game teleport in form of ladder to move user (player) between those levels. In-game levels are loaded in a form of low resolution bitmaps where each pixel color represents certain block type. These bitmaps are user-created and can be edited anytime.
Implemented graphical API can render floors, sprites and walls so that each pixel on the screen is calculated manually without using any other external framework or library.
Nowadays rendering APIs like OpenGL and Direct3D use polygons and shaders to properly draw models onto a screen which are mathematically defined as volumetric shapes. The difference between my rendering framework and modern frameworks is the fact that modern rendering procedures use triangles while my engine works directly with pixels.
Reason why triangle is the most popular elementary surface is because there are minimum of three points needed to create a flat surface which always form a triangle. Simplified rendering pipeline model can be seen on the picture below:
Simplified rendering pipeline diagram |
Procedures colored green indicate that both Vertex and Fragment shader functions can be programmed to do specific tasks. Each model file format (fbx, obj or 3ds) contains data like vertex positions, normals, tangents, triangle indices and uv coordinates. These data are passed into vertex shader function which applies certain transformations so they can be rasterized and passed further into fragment shader function which fills in the frame buffer.
As a final step, frame buffer content is displayed on the screen with predefined framerate which can be either 30 FPS for mobile platforms and 60 or more FPS for pc and console platforms.
Modern games and other graphical software use hardware accelerated rendering where GPU is used to redraw the entire screen while my rendering framework doesn’t use any hardware acceleration support at all. Such a renderer, which uses part of CPU time instead of GPU is called software renderer. The reason why I chose this approach is the fact that I use Windows Forms framework to initialize window and create graphics object to redraw canvas.
Windows Forms framework offers light and most suitable workflow for such project. Unfortunately it doesn’t support hardware accelerated rendering by default which is not a problem since drawing area of the window is set to have resolution of 160 x 120 (19 200 pixels) and screen ratio of 4:3.
List of Abbreviations and Symbols
It is important to define all abbreviations used throughout the entire blog, which are listed below.
- FPS – Frames Per Second (Number of discrete frames that will be rendered within a single second)
- API – Application Programming Interface
- GDI – Graphical Device Interface
- FOV – Field of View (Angle of how much of the world could be seen by a camera)
- CG – Computer Graphics
- STR – Rotation, Translation & Scale matrices multiplied together in this order
- GPU – Graphical Processing Unit
- CPU – Central Processing Unit
- RAM – Random Access Memory (Used by CPU)
- VRAM – Video RAM (RAM used by GPU)
- PBR – Physically Based Rendering (Realistic light model)
- AABB – Axis Aligned Bounding Box
- AI – Artificial intelligence
- ms – milliseconds
No comments:
Post a Comment