Hopson97 / open-builder

Open "Minecraft-like" game with multiplayer support and Lua scripting support for the both client and server
https://github.com/Hopson97/open-builder/projects/3
GNU General Public License v3.0
703 stars 80 forks source link

Water not rendering when a block is placed on top of it #156

Closed GrossoDev closed 4 years ago

GrossoDev commented 4 years ago

Bug name

Water rendering problem

Description

When a block is placed on top of a block of water, that block of water doesn't get rendered.

To Reproduce

  1. Run the game.
  2. Go to a source of water.
  3. Place a block just above the water level.
  4. Contemplate.

Expected behavior

The top face of the water block should get rendered.

Screenshots

image

Desktop

Ubuntu 18.04

Additional context

Caused in the chunk mesh generation file.

We could check if the current voxel contains gaps on it (which will make it work with stairs, slabs, doors, etc) by adding a flag to the VoxelData struct that indicates which faces it won't fully cover.

Hopson97 commented 4 years ago

Good issue. I believe this would also happen with leaf blocks.

Also your solution makes sense. A flag like "isOpaque" could be added, allowing the meshbuilding to code to add faces when it is set to false.

GrossoDev commented 4 years ago

It might be necessary to specify which faces have to be rendered. Not only because of optimization reasons (1 extra face vs all 6 faces), but because the faces inside water shouldn't be rendered, only the faces that contact with other blocks.

I'll be working on implementing this, if that's not a problem of course.

Hopson97 commented 4 years ago

That is fine :)

It might be necessary to specify which faces have to be rendered.

This is true, for now though (to keep things nice and simple, and the face I don't have anything like stairs or slabs in the game for now), it could just be all faces.

but because the faces inside water shouldn't be rendered,

IIRC, the chunk meshing code will not add block faces if the neighbour block is the same (This is what allows the terrain faces to render underwater, while "underwater faces" are not rendered)

GrossoDev commented 4 years ago

Good news:

image

Bad news (but hey, the trees are visible underwater :D):

image

This happens inside the water, where the back-faces appear, because isOpaque afects all faces.

It gets spaghetti to hardcode the water not to render its sides when isOpaque == false, so fluids will always render their top face for now.

Until the stair update comes around, I'll be preparing a fix/faces-not-rendering-through-gaps branch with a (hopefully) proper solution.