afonsolage / projekto

Voxel game made with Bevy Engine
MIT License
59 stars 4 forks source link

Height clipping #50

Closed afonsolage closed 2 years ago

afonsolage commented 2 years ago

Add height clipping based on character height. This allows the character to enter inside caves and also prevents the orbit camera from spotting objects outside the character view

image

afonsolage commented 2 years ago

I was unable to find a way to fix those blue edges on voxel textures. The ugly work around would be just add a pixel off set between each tile, but this is out of scope of this PR.

afonsolage commented 2 years ago

I need to find a way to don't draw those faces when there is a "visible area" bellow it:

image

afonsolage commented 2 years ago

I'll try another approach, since working on shader I have very little information about surrounding voxels.

afonsolage commented 2 years ago

I was able to have a working height clipping, but I'll not merge this until I figured out a way to use this.

clip_height.webm

The way it is now, it'll reveal all caves and buildings underneath voxels. This should be trigged only when player is inside some cave/place where there is a floor over his head and only that area should be height clipped

afonsolage commented 2 years ago

I don't think it'll be possible to do what I wanna do, due to how voxel faces are merged, since sometimes the clipping will hit a face and I wanna only clip half of it

afonsolage commented 2 years ago

I'll close this, since another approach will be needed

afonsolage commented 2 years ago

Finally I think I've figured out a way to make this work. Still needs some tweaks, but this is the general idea:

image

This is a mix of flood-fill to detect visible areas (and voxels touching those visible areas) and shader to clip voxels that shouldn't be rendered.

Next todo:

afonsolage commented 2 years ago

I fixed the problem with some faces not being rendered by switching to use an texture 1d to map which voxels should be visible:

image

But even tho the flood fill is fine, I'm not being able to properly read this info on shader.

afonsolage commented 2 years ago

image

Ok it's almost there. Now I just need to figure out how to deal with those edge cases, where the top voxel is clipped since it's on the clip map.

afonsolage commented 2 years ago

Ok, I made some progress: image

Now I need to fix a bug when character move out of the (0,0,0) chunk

afonsolage commented 2 years ago

app-2022-08-21-14-00-47_2.webm

Just need fix one more bug and I think it's good to be merged (also, after some clean up)

afonsolage commented 2 years ago

There is some clean up to do, but I'll do it in another PR, since this is good to go.