Jasoco wrote: ↑Wed May 18, 2022 6:27 pm
Out of curiosity, would writing an Ambient Occlusion shader be possible, if so would it be trivial, and if so would it work fast enough to not cause slowdown? Or should I not bother trying to write one? I feel like my game would look much better with subtle AO. In my old raycasting project I baked AO into the floor textures and it helped the look of the game a lot. But I'd love to do it myself. I just don't know where to start. I have been looking at tutorials online, but of course they're all meant for Unity and stuff like that so you have to try and translate it to how it would work in Löve.
I've been trying to figure this out too and while I never managed to wrap my head around some of the pure glsl tutorials out there for things like SSAO, I did come up with this solution for my not-quite-voxel game.
Since the game you showed off earlier used voxel terrain maybe some of this will translate, all you really need in your shader code is a function that takes a position as an argument and returns a boolean depending on whether or not the position is inside the terrain.
My ao implementation works by darkening each pixel based on the shortest distance to any adjacent surface. The grid like nature of the world makes finding this distance fairly straight forward since you only really need to check in 8 directions and finding the distance between a point and a grid line in a cardinal direction just boils down to getting the decimals of either the X,Y or Z component and finding the position of a corner of a given grid cell just requires you to floor the position vector.
A simpler solution would be to sample random points around each fragment and darken each pixel a little for every sample which lands inside an occluded part of the map. This will however produce some pretty noisy results and is generally less performant, although the noisiness could in theory be reduced by blurring the result but I never got around to that. Glsl doesn't have any noise functions built in but there are plenty of simple implementations out there, just know that most user made noise functions tend to have some quirks. The screenshot below is from an earlier version of the project which used this sort of ao.
I also found this article about ao in minecraft like worlds
which might be of interest. I don't think the default g3d shader supports vertex colors so you might have to implement that on your own if this method interests you.
I hope this was of some help
I'm way too sober for this...