Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make water get darker closer to the bottom #124

Closed
csf30816 opened this issue Jul 17, 2020 · 6 comments
Closed

How to make water get darker closer to the bottom #124

csf30816 opened this issue Jul 17, 2020 · 6 comments

Comments

@csf30816
Copy link

I am wondering how I can make the water get darker and have less visibility the farther down it goes. I tried using fog to get this effect but I couldn't get the results I wanted. Any help is appreciated greatly!

image

I'd like it to get less transparent and darker that's all :) Oh I also tried creating multiple shades of water and assigning them based on distance from the waterline but because of how the fluid works in this engine that only changes the visibility once you are under water.

@csf30816 csf30816 changed the title Hello there. How to make water get darker closer to the bottom Jul 17, 2020
@fenomas
Copy link
Owner

fenomas commented Jul 18, 2020

Hi, this would be a really nice feature! I don't have any good ideas offhand for how to implement it though. Certainly open to ideas.

@csf30816
Copy link
Author

csf30816 commented Jul 18, 2020

yeah, I got no clue, other than darkening blocks that are farther away and underwater, that might work.

With logic like this:

if (underWaterBlock(x, y, z)) {
    return blockType("sand" + Math.min(distanceFromPlayer(x, y, z) / someValue, maxShades))
} else return blockType("sand");

the only problem is you'd have to update that every player move.

@johnhorsema
Copy link

What if the logic becomes

if (notSwimming) {
  for(block in visibleWaterBlocks) {
    return blockType("sand" + Math.min(distanceFromGround / someValue, maxShades))
  }
}
else {
  for(block in visibleWaterBlocks) {
    return blockType("sand" + Math.min(distanceFromPlayer(x, y, z) / someValue, maxShades))
  }
}

@fenomas
Copy link
Owner

fenomas commented Sep 3, 2020

So the problem with those last two ideas is that you'd need to be re-meshing large amounts of terrain as the player moved around, which would not scale.

Having thought more about this, an effect like this could be achieved by changing the way the terrain mesher works. The terrain mesher works by creating polygons between voxels where needed, but currently it never creates any geometry between two voxels with the same ID/material. So when you have a pool of water, a layer of geometry is created between the water and air, and between the water and ground, but no geometry is created between any adjacent water blocks. If instead the mesher created a terrain face between vertically adjacent fluid blocks, then when you looked down into water you'd look through multiple horizontal layers of transparent blocks, creating a sort of "gets darker as it gets deeper" effect.

There are some drawbacks though - I guess it would probably perform badly for large bodies of water, and I'm not sure that the depth-sorting for transparent layers would work as expected. Also doing this properly would mean some fairly fiddly engine logic that would be very hard to expose such that the client could customize it.

Anyway I don't currently have the cycles to work on this, but if someone is forking the engine for their own work I think the above approach could work.

@fenomas
Copy link
Owner

fenomas commented Jun 2, 2021

On thinking more about this, I don't think there's any realistic way except for the engine to support a lighting model, and have dark water be a subset of that. So, closing for now.

@fenomas fenomas closed this as completed Jun 2, 2021
@csf30816
Copy link
Author

csf30816 commented Jun 2, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants