r/GraphicsProgramming • u/Kooky-Advance7870 • May 22 '26
Experimental voxel renderer
I've been playing with a minecraft style voxel renderer. Current demo has about 11 different techniques to render large worlds as fast as possible.
Demo also has TAA, distance and height fog, shadow maps for directional and ambient cube with per voxel baked AO for ambient, tonemapping and sharpening.
Data is the kings landing model duplicated 100X to make the world bigger. I would ideally like a much larger mesh but memory usage is already quite high so it'll need to be optimize and potentially streamed in on demand. Screenshot is at about 7ms @ 1440p on a 5070 Laptop. Being in the corner so all 100 worlds can be scene is about 15ms. Still a huge amount of various optimizations to be done.
24
u/smm_h May 22 '26
holy shit how many voxels is in this screenshot
23
u/Kooky-Advance7870 May 22 '26
I'll try and get some numbers. Source will be in the 10's of billions probably but drawn is much less . There lots underground too and I currently don't cull them very well which is a future optimization.
The bulk of the voxels are simply drawn as points as GPUs can rip through pointlists. A compute shader then fills in the gaps by looking for neighbors who got rendered and doing a ray/cube slab test to reconstruct the voxel cube. A search radius of 2 is guaranteed to be sufficient.
Points are aggregated into 2x2x2 and 4x4x4 groups as well in the distance which cuts down the number of points needed by 8x and 64x . LOD level is stored in alpha channel which the CS then uses to know how big of a cube to reconstruct.
5
u/corysama May 22 '26
You might get some ideas from https://github.com/m-schuetz/CuRast
Method: A 3-stage rasterization pipeline first rasterizes small triangles efficiently in stage 1, and falls back to other stages for increasingly larger triangles. Stage 1 assumes triangles are small and uses 1 thread to render them directly. If they are not, they are instead queued for stage 2 which uses 1 warp to render larger triangles with more compute power. If they are still too large, they are split up and queued for stage 3.
5
u/Kooky-Advance7870 May 22 '26
Close clusters are typical polys. Far clusters are simply points.
Tris 3,598,846
Vert 7,197,692
Points 36,228,3670
May 22 '26
[deleted]
3
u/Kooky-Advance7870 May 22 '26
Currently not very but there are plans to have it fully dynamic at the expense of higher costs. AO is baked and poly mesh is optimized by merging faces where possible. I have some idea of SDF based AO using compute shaders to generate the multires SDF data. I may just have it fully point based and making the dilation filter separable so I can have much bigger search radius.
43
u/corysama May 22 '26
This guy is why we're having a voxel supply shortage.
7
u/TehBens May 23 '26
Just yesterday I wondered why I couldn't get any voxels rendered on my machine. Now I realize they are all on OPs machine.
3
4
u/slenderman011 May 22 '26
Very neat! Have you tried ray marching instead of triangle meshes? I've been working on a ray marching engine later to some success using compute shaders in OpenGL 4.6, and I hope to see some improvements once I bite the bullet and implement a Vulkan renderer.
3
u/Kooky-Advance7870 May 22 '26
Yes I plan to do a raycast/DDA style approach as well. Idea is to divide into coarse bricks and then traverse into them similar to how teardown works. Its probably the next experiment I'll try.
1
u/Le_9k_Redditor May 23 '26
If you haven't already checked this guy out https://www.youtube.com/@GabeRundlett/videos and the codebase https://github.com/GabeRundlett/gvox_engine
2
u/Kooky-Advance7870 May 23 '26
Awesome. Thanks for sharing that. That looks really cool.
1
u/Le_9k_Redditor May 24 '26 edited May 25 '26
I'm doing a similar thing myself, baking SDF shaders into voxels. I'm just testing out a switch from stackless BVH to a VDB style tiered radix tree at the moment. I'm too stupid to learn graphical APIs, it's all compute shaders so stacks and pointers are the enemy. So yeah I think traversing a few individually dense bitmasks is the way
The most optimised voxel engine I've ever seen uses parallax raymarching though. So rasterise large cubes as a typical engine would, conservative distance, only backface of the cube rendered, fragment shaders on each cube with another 8x8x8 cubes within each. Some guy on YouTube was running this thing on an old integrated MacBook processor and it's crazy
Edit: https://youtu.be/h81I8hR56vQ?si=a4okY9CC3al3zGvy parallax voxel raymarcher guy with explanation, look at his later videos to see how far its come
Edit 2: oh yeah, where did you get the kings landing model? Looks really helpful for benchmarking
Edit 3: fixed link, I hope
1
u/UnlikelyUniverse May 25 '26
Is this just me or is this youtube links to Cursor 3 announcement?
3
u/Le_9k_Redditor May 25 '26
Oh wtf, that's not what I clicked share on. YouTube being crazy. It must've shared the ad before the video I guess
I'll go find it again and fix the link
Link? I hope https://youtu.be/h81I8hR56vQ?si=a4okY9CC3al3zGvy
2
2
u/Capitinefrobou May 22 '26
Really cool... Are you sharing / selling it later?
8
u/Kooky-Advance7870 May 22 '26
Yes, I'll put it on github. Its currently just a Visual Studio sln with dependencies (Imgui/Microprofile) copied inline. I want to move it to a proper build system with dependency pulling instead. Its only 3 days of work so a bit rough around the edges. Its all D3D11 but might move to OpenGL so can also run on mac/linux.
3
u/MCWizardYT May 23 '26
1
u/Kooky-Advance7870 May 23 '26
Yeah you are right. I'll convert to VK.
I do have my own RHI style abstraction layer but its old and still on D3D9 era APIs. I may resurrect that and update to DX12/VK/Metal but for now I'll probably go to VK. The main hassle is the shaders. I so prefer writing in HLSL.2
u/TehBens May 23 '26
Please don't mind if it's not perfect or the build system is not up to your standards. It's already super cool and worthy to upload and people will enjoy fidgering with it and learn a bunch of stuff.
Too often I got discouraged by my own perfectionism and I know I am not the only one.
1
4
1
1
u/Economy_Bedroom3902 May 23 '26
Sick!ย Have you already removed all occluded voxels from being stored?
1
u/Kooky-Advance7870 May 24 '26
No. That is still to do. The only culling is view frustum and back face using vis masks. I have some ideas for efficient occlusion culling but I want to move all rendering to retained mode and have it fully GPU driven first.
1
u/Economy_Bedroom3902 May 24 '26
There's two types of occluded voxels: 1.ย Stored opaque or translucent voxels which are not bordered by any transparent or translucent voxels and/or stored voxels which are 100% transparent (don't store air).ย They might be needed for physics calculations, but don't need to be stored at all at the rendering level.ย So they can be populated at a different chunk loading layer. 2. Voxels which for whatever reason are not struck by a camera or lighting ray
1 is relatively easy to deal with and you don't have to be absurdly performant with it as it can be cached after it has been computed once, and can be entirely precomuted for loading voxel models.
2 is the harder problem depending what you want to do with lighting tech.
1
1
1
1
1
u/Standard-Struggle723 May 23 '26
Legitimatly one of the most exciting posts on this subreddit in a long time. Point clouds are pretty brilliant of a concept and not often recognized for the potential they have.
1
u/Evening_Archer_2202 May 24 '26
how I dream for a voxel game with infinite render distance (minecraft has a mod that can do it)
1
1
1
21
u/Annual_Pudding1125 May 22 '26
Any source or overview of techniques used?