Shader Forge

Practice in Chalmers course TDA572 Game engine architecture:
Basic 2D game engine with features of 2d render pipeline, build on ECS

Pixel Forge

Features in the engine

Feature Description
ECS Each system in the engine is based on ECS (Entitas library)
Parallel rendering Support rendering objects to different layers, and then merge them together.
Post-processing component/system Scalable post-processing system (including Bloom and Gaussian blur) that allows for adding different effects to different layers.
Lighting components/systems Pixel-based 2D lighting can add different lights to different layers.
Render Tools Objects used for rendering, such as Renderer, Texture, RenderTexture (with FBO), and Blitter, encapsulated in a manner similar to Unity.
Other components/systems Camera (handling camera parameters), Renderer component (controlling object rendering process)
Cellular automaton 2D physics and world element updates based on cellular automata.
Collision detection(in progress) Pixel-based collision detection.

2D light principle

Pixel Forge - 2D light branch

Below is the process of generating 2D lighting from the Color Buffer.

1. Retrieve ColorBuffer from screen

2. Create LightRT with light pixel size as radius

3. Blit the pixels near the light on the screen to LightRT, leaving blank the pixels that are off-screen

4. Create a ShadowMap (RT) to capture the minimum distance from every angle. I set the width to be 360, emitting a ray every 1°, with a height of 1

5. Create full-screen quad, render to ShadowMap. For each fragment in the ShadowMap, RayMarching to find the closest distance to the light source in that direction.

6. The obtained shadow map records the closest distances of surrounding objects.

7. Blit the screen, compare the distance from each fragment to the light source with the value recorded in the ShadowMap to determine whether to write the light color.

8. Render to screen RT.

Addition features in 2D light

Using Gaussian blur to achieve softer shadow edges.

Added downsampling function sacrifices lightMap size and quality in exchange for higher performance. When combined with Gaussian blur, it can achieve good results.

By offloading calculations to GPU for parallel processing, namely utilizing Ray Marching, the overall performance is quite good. It can support a screen resolution of 1200*1200, full-resolution LightMap, radial stepping 200 times, circumferential stepping 360 times, and run 300 lights at 60 frames per second (on 4070ti).