Post B2DPGfwM5orBEJ0kN6 by eniko@mastodon.gamedev.place
(DIR) More posts by eniko@mastodon.gamedev.place
(DIR) Post #B2DPGP6ig22v1WjHfM by eniko@mastodon.gamedev.place
2026-01-07T09:51:36Z
0 likes, 0 repeats
i'm going to write a software rendered occlusion culling mechanism for block game 😤
(DIR) Post #B2DPGQB0hZ4YL7kDzc by eniko@mastodon.gamedev.place
2026-01-07T10:26:35Z
0 likes, 0 repeats
i have my plan all laid out
(DIR) Post #B2DPGRAh0EPdQQbU8W by eniko@mastodon.gamedev.place
2026-01-07T15:28:25Z
0 likes, 0 repeats
oh no it's only partially done and it's already slow ðŸ˜
(DIR) Post #B2DPGRhJ2yV53ZrWyG by eniko@mastodon.gamedev.place
2026-01-07T22:43:45Z
0 likes, 0 repeats
well i got it working, and it does work. fps at 12 chunk render distance up to 75ish from 45ish on my not very powerful gpusome kinks to work out still, can probably make it faster, but it's a good proof of conceptatm it's running across multiple frames so if you rotate the camera very fast, it takes a frame or two for the geometry to show up >_>;
(DIR) Post #B2DPGSFgz80QmDwzZI by eniko@mastodon.gamedev.place
2026-01-07T22:50:10Z
0 likes, 0 repeats
i wish i knew a better way to approximate the bounding rectangle of these AABB cubes. atm i'm using an extremely generous buffer to make sure nothing is considered offscreen when it's not actually offscreen in my first pass, but that means i wind up doing a lot of matrix multiplications for corners of subchunks that aren't on screen
(DIR) Post #B2DPGSu6YsKenYrGYi by eniko@mastodon.gamedev.place
2026-01-07T23:14:37Z
0 likes, 0 repeats
lol. it is *much* more effective underground. at 12 chunk radius fps goes from 45 to 230 😊(big occluders in your face helps cull a lot of chunks)
(DIR) Post #B2DPGTgfeJBFEBa3G4 by eniko@mastodon.gamedev.place
2026-01-08T11:48:00Z
0 likes, 0 repeats
ok so two ideas:1. i should be culling in world or view space, which is more reliable and cheaper2. for projecting corners i think i can cut out some operations when doing the world->screen transform since all i care about is screen x/y and some relative depth, not actually normalized depth like for a depth buffer so i can actually use linear view space distance
(DIR) Post #B2DPGUWmWYrdpnxfU0 by eniko@mastodon.gamedev.place
2026-01-08T15:40:52Z
0 likes, 0 repeats
simplified my world->screen transforms. instead of doing a 4x4 matrix multiply then dividing by w and multiplying by buffer size (21 multiplies) i switched to a view matrix, view transform the position, then project to the screen manually (13 multiplies) and use view distance instead of depth since i don't careand it now runs in about 2/3rds the time it did before :D
(DIR) Post #B2DPGVMtOoY2RQLHhw by eniko@mastodon.gamedev.place
2026-01-08T16:41:16Z
0 likes, 0 repeats
changed the way i cull subchunks courtesy of @bnut. i extract the world space frustum planes from my view-projection matrix, normalize, then do `dot(plane.normal, subchunkCenter) + plane.dist` and check against the bounding sphere radius (0.5*sqrt3*side)occlusion culling now runs in 0.43x the time but also the culling is up from 43% to 74%, which means the game runs much faster. at 12 chunk distance fps above ground is up from 60 to 110!
(DIR) Post #B2DPGW2Mubj0W3kPM8 by eniko@mastodon.gamedev.place
2026-01-08T16:55:43Z
0 likes, 0 repeats
interestingly, if i switch from 4 subchunks per axis (64 per chunk) to only 2 (8 per chunk) the entire occlusion culling pass finishes in just 7ms even on my underpowered workstation at 12 visible chunk radiusunfortunately the culling% does go down from 71% to 57% and so fps goes down from 110 to 90, but that might be worth the trade off 🤔
(DIR) Post #B2DPGWcsiqvqLIpZGi by eniko@mastodon.gamedev.place
2026-01-08T17:06:05Z
0 likes, 0 repeats
even if i set the visible chunk radius to 16 (which is quite far!) the occlusion culling runs in 11ms* and my fps above ground is 55which i would say is solid for this early in the project*with 8 subchunks per chunk
(DIR) Post #B2DPGXGwJuyULXZYhs by eniko@mastodon.gamedev.place
2026-01-08T18:33:26Z
0 likes, 0 repeats
Oh. Most of the gains are from the frustum culling. I can cull a significant % of chunks if I use 64 subchunks per chunk, but that is also very very slow. But it does bring cull % up to like 75%But just frustum culling chunks culls like 45-50% of chunks and is very very fast :|8 subchunks per chunks is just a regular amount of slow but also not very effectiveSo hm. Well I guess at least I learned how to do efficient frustum culling? Womp womp 😔
(DIR) Post #B2DPGY2nRzFujxxmIi by eniko@mastodon.gamedev.place
2026-01-08T20:26:46Z
0 likes, 0 repeats
oh hey i got it down to 54ms from 93 at 16 visible chunk radius with 64 subchunks per chunk by only processing subchunks that have visible facesi was using visible *blocks* before. but a theoretically visible block (not void/air) surrounded by blocks has no visible faces, so can't actually be seen
(DIR) Post #B2DPGYiyv902qnhT3Q by eniko@mastodon.gamedev.place
2026-01-08T21:11:07Z
0 likes, 0 repeats
oops i had a bug that was causing a bunch of subchunks to not get occluded when they should be. so now the number of depth occluded subchunks is up by 50% and there's 1 depth occluded subchunk for every 2 frustum culled subchunks
(DIR) Post #B2DPGZlr1wtM603HAe by eniko@mastodon.gamedev.place
2026-01-08T22:35:05Z
0 likes, 0 repeats
Had an idea to try tomorrowOnly render occluders nearby the camera and skip depth culling, because far away occluders will be tiny and unlikely to occlude muchThen depth cull far away (sub)chunks, since they're tiny and so only cover a few pixels and so are more likely to be culled
(DIR) Post #B2DPGaZ84kJ6Yp6cyW by eniko@mastodon.gamedev.place
2026-01-08T22:48:58Z
0 likes, 0 repeats
Actually it could be interesting to treat subchunks like mipmaps 🤔 so level 0 is 1 block per subchunk, level 1 is 2, 2 is 4, 3 is 8 and 4 is the whole chunkThen I can use lower levels up close for better occlusion and higher levels far away for quicker culling
(DIR) Post #B2DPGb9dszVwO4Bmt6 by eniko@mastodon.gamedev.place
2026-01-09T11:06:33Z
0 likes, 0 repeats
aha! i might be onto something! only rendering occluders into the depth buffer for nearby subchunks and only depth culling far away subchunks dropped the run time from 0.21x original to 0.14x originali bet if i reduce the number of subchunks far away by making subchunks larger i can get even better gains
(DIR) Post #B2DPGbtj7eNSgzkaie by eniko@mastodon.gamedev.place
2026-01-09T14:46:47Z
0 likes, 0 repeats
so uh, wow, holy shit!my new subchunk levels method (where each level is smaller) is a 7x improvement over my last attempt, and my software occluder now runs in 0.02x the time it did before i started optimizing. in other words, it runs 50x faster now! for 12 visible chunk radius its down from 155ms to fucking *4*interestingly though, even though i have 3 levels, 16, 8 and 4 blocks, i didn't even need the middle level. i just switch straight to whole chunks for depth occlusion
(DIR) Post #B2DPGcbKVXFusE9PgO by eniko@mastodon.gamedev.place
2026-01-09T14:47:02Z
0 likes, 0 repeats
in hindsight this makes sense. occluders should be small, since they set up the depth buffer, but then occlusion culling can be done on whole chunks since it doesn't matter how big the area you're testing at one time is so long as the occlusion map is filled up properlyso next i might try rendering single blocks into the occlusion map and depth culling entire chunks always and see how that performs
(DIR) Post #B2DPGdB8MPtafGu0US by eniko@mastodon.gamedev.place
2026-01-09T15:02:31Z
0 likes, 0 repeats
16 visible chunk radius now runs at 68 fps above ground (1 short of being truly nice 😔) and the occlusion culler runs in only 5ms
(DIR) Post #B2DPGdkwDIXGSJebIW by eniko@mastodon.gamedev.place
2026-01-09T22:09:48Z
0 likes, 0 repeats
simplified everything and split occluders from depth culling candidate chunksalso trying to be more picky and granular about what occluders to use, so now i'm rendering single blocks nearby the camera. hopefully more granular occluders will improve the culling percentage
(DIR) Post #B2DPGeQlhlzoY3E0Uy by eniko@mastodon.gamedev.place
2026-01-10T08:24:26Z
0 likes, 0 repeats
you can call me weird but it is very fun to build a little box around myself and watch my fps go up from 110 to 450 because of the depth occlusion system
(DIR) Post #B2DPGf1zTNloPUdjW4 by eniko@mastodon.gamedev.place
2026-01-10T08:55:50Z
0 likes, 0 repeats
hmm hmm so my subchunk levels go 1³, 2³, 4³, 8³, 16³but im betting anything above 2³ is gonna be exceedingly rare since a new requirement is having a block with an exposed face. though i havent tested thisbut i feel like maybe 1³, then 2²x1 4²x1 8²x1 16²x1 for each axis would probably work a *lot* better given how human construction tends to goand also ground planes/cliff faces
(DIR) Post #B2DPGfGsa1gD9fbciu by eniko@mastodon.gamedev.place
2026-01-10T18:15:01Z
0 likes, 0 repeats
i'm *sure* you'll all find this as riveting as i do, but while there are loads of 8x8x8 areas of fully opaque blocks with at least one visible exterior face, there appear to be literally no 16x16x16 areas of the same description in any given chunk >_>
(DIR) Post #B2DPGfwM5orBEJ0kN6 by eniko@mastodon.gamedev.place
2026-01-10T18:21:49Z
0 likes, 0 repeats
here's photographic evidence of all the 8x8x8 blobs out in their natural habitat
(DIR) Post #B2DPGg7hPdvlnUJo3M by eniko@mastodon.gamedev.place
2026-01-10T20:53:12Z
0 likes, 0 repeats
so i've tweaked all the parameters and above ground its now culling 75% ish of chunks that survive frustum culling. even at 24 chunk radius it runs in ~8ms so about half a frame (and it's threaded so that's fine)and i'm getting 75 fps above ground at 16 render dist, and 115 at 12. and indoors or in caves its more like 300-400so i'd call this feature a success and also done for the time being!
(DIR) Post #B2DPGgalfZBPFdv1MW by eniko@mastodon.gamedev.place
2026-01-10T21:20:19Z
0 likes, 0 repeats
being in a cave make fps go zoom! :3(lol the alt badge hides the fps counter. it reads 450)
(DIR) Post #B2DPGgzaBJ24UbWq2a by eniko@mastodon.gamedev.place
2026-01-11T15:09:25Z
1 likes, 1 repeats
ngl this never gets old (turning occlusion culling on and off to show how much its culling)