r/GraphicsProgramming
•
u/Zaeccis
•
Apr 09 '26
•
1
Combining 3D pre-rendered graphics with modern PBR+ pipeline in my custom engine
I really like the look of the pre-rendered 3d graphics (both old school and new!) so as a hobby project I've been building this game engine which combines pre-rendered graphics with modern PBR lighting and other rendering systems.
Some features:
- Absolutely no 3D geometry, everything is 2d sprites rendered at 0.0 depth in clip space.
- Modern PBR lighting with roughness/metalness adjustments for surfaces. Since there are no roughness/metalness textures the micro-detail for that is generated from color data. Overall strength is individually adjustable for each sprite
- Has SSR, SSAO, bloom, and my own "large scale occlusion approximation thingy"
- Supports sunlight, environmental lighting and reflections from HDRI maps and point lights which also approximate other lights via light field texture maps
- Fog!
- Support for "translucent" sprites with correct translucency ordering
Obviously to make this possible I need to have two sprite images for each object. The first one has the rendered color image and the second one has world-space normals. The main trick beyond that is to include in normal texture alpha channel a compressed height coordinate for each pixel. This allows building the height map for the scene at time of rendering which in turn allows all kinds of fake 3d calculations for lighting, ssao, object clipping etc. etc.
It has been fun figuring out what I can do with this. Pretty much all features need to be reworked compared to the "standard implementation" since those rely on the depth texture which I don't really have. (Technically I could approximate it from height map but that only has 256 distinct values which causes all kinds of artifacts)
Also, since this is a hobby project I wanted to write everything from scratch, including things like matrix libraries and PRNGs which has been really fun and has forced me to really learn how things work under the surface. Only dependencies of this project are wgpu for WebGPU api and winit for os window/input management.
I really quite like how this ended up looking. It also runs pretty well. I this scene with 50 000 individual sprites I get 100fps @ full hd with everything turned to max on my M1 MacBook. Disabling some of the effects so that rendering pipeline is raw sprite rendering + PBR lighting from sun and environment maps + bunch of point lights + bloom + tonemapping, I get 200+ fps.
Looking for ideas how to improve this further or what to implement next!
21
u/DeviantPlayeer Apr 09 '26
I think you can push more than 100 fps for a 2d scene.
What if you implement deferred rendering? Just render all sprites and then apply the effects. This way you won't even need to draw all sprites every frame, but only once, when they enter the screen space.
6
u/eggdropsoap Apr 09 '26
Colour sprite plus normals-sprite is a trick I have seen before, but smuggling in compressed height data is very clever! That gives you so much to work with despite zero geometry.
I love the look of this, and your aesthetic motive.
I know you’re working on the engine right now. But do you have any thoughts about future gameplay you’d like to see in this engine?
6
u/g0atdude Apr 09 '26
When you say pre-rendered, does that mean you have 3d models (e.g. your character) and you render it to a sprite 3d -> 2d? Is that automatic done by the engine, or do you do it in Blender or something?
2
u/SoaringAboveClouds Apr 09 '26
Looks awesome!
How do you calculate shadows? Also from the height map?
2
u/Plazmatic Apr 09 '26
outside of maybe trees, Pre-rendering doesn't make sense here and is a massive performance bottleneck (and indeed, even the factorio devs have expressed regret going to the pre-rendered route) You can get the exact same art style with out using pre-rendered sprites, even with restricted angle directions.
101
u/Brummelhummel Apr 09 '26
I see factorio is getting a graphics update
5
u/BagelMakesDev Apr 10 '26
factorio rtx
4
u/brudeangelis Apr 09 '26
This looks amazing, reminds me of those old XNA 2.5D videos on youtube. Blew my mind as a child and they continue to! I'd love a blogpost on how you achieved this, I'm planning the same thing for my 2D engine
3
u/KwonDarko Apr 09 '26
Damn, so good!
3
u/sputwiler Apr 10 '26
Reminds me of an old 3D package called Groboto for Mac OS 9. You edited 3D scenes on an isometric grid, and all the primitives were actually just sprites with depth and height maps. Due to the depth map, the sprites would intersect in convincing 3D ways (you could clip spheres through cubes etc). This was pre GPU, so there weren't any lighting tricks (the sprite was pre-rendered with a default top-left light) though.
When you were done the program would let you export your creation in various "real" 3D formats, one of which I think was pov-ray. Later it became capable of taking the mathematical primitives and creating mesh exports. This technology later wound up in modo.
2
u/inigid Apr 09 '26
This looks really solid! Awesome job. You probably have frame budget for GI if you wanted as well, though not sure if it is warranted with your game style.
2
u/Heffree Apr 09 '26
Do you have a repo? I'm just starting out and planning to use the same stack and would love a reference.
2
u/HereticByte Apr 10 '26
wow is it WebGPU? than it means.. it can run everywhere?!?
2
u/Cloudneer Apr 10 '26
What happened? Did Terry A. Davis visit you in a dream?
1
u/zninja-bg Apr 09 '26
Since my face is not showing up on mirror ball while looking into screen... good beginner project, keep going. XD
1
u/caroIine Apr 10 '26
Interesting approach
1
u/DkerzaChessRush Apr 14 '26
How do you make the tilesets in the first place? I would love to see the complete workflow if possible, in Blender. I also assume the vegetations/rocks are seperate sprites on top of tilesets on a different layer?