0
\$\begingroup\$

I'm working on a puzzle game featuring islands: there is a plane with a water shader, and objects colliding with that plane.

Now I'd like to make lakes on the islands, with different (higher) water levels than the ocean's.

enter image description here

The problem is that if I put a water plane in a "hole", I can see the ocean below at best, or even worse, the upper water surface just glitches out and disappear.

enter image description here

enter image description here

One option is that I move the lake's basin higher than the ocean's see level. This works, but I it doesn't look so good, because the lake becomes too shallow.

enter image description here

Another option is that I cut holes in the ocean's plane, but that seems a bit overengineered, isn't it?

Is there a better solution?

Also having a water plane for every "lake tile" causes some problems:

enter image description here

but I want to have dynamic lakes, so having a 2x2 water plane for a 2x2 group of lake tiles isn't a walkable path.

\$\endgroup\$
9
  • \$\begingroup\$ Have you considered rendering a depth-only object below your lake water level to clip out the ocean before it's drawn, similar to the approach described here? \$\endgroup\$
    – DMGregory
    Commented Jun 12, 2020 at 11:42
  • \$\begingroup\$ Not yet, but sounds good. Could you help with the solution in the Answer? I'm a bit newbie with shaders. \$\endgroup\$
    – Tudvari
    Commented Jun 15, 2020 at 16:47
  • \$\begingroup\$ What specific help do you need? How far have you gotten, using the linked Q&A as a guide? \$\endgroup\$
    – DMGregory
    Commented Jun 15, 2020 at 16:47
  • \$\begingroup\$ I just don't get how does it work and thus how could I use that to solve my issue. Under "clip out" you just mean to draw an "opaque, only-depth" face above the ocean? If yes, how would that differ from my current "having a basin object above ocean? if no, how could I have the basin rendered, but the ocean not? I'm a bit confused here :\ \$\endgroup\$
    – Tudvari
    Commented Jun 15, 2020 at 20:11
  • 1
    \$\begingroup\$ Nice work! Thanks for sharing your answer! \$\endgroup\$
    – DMGregory
    Commented Jun 16, 2020 at 20:05

1 Answer 1

1
\$\begingroup\$

Based on this answer: Fade in rendering mode doesn't work as intended

I've put a quad just above the ocean's gameobject in my lakes, with a material with this shader:

Shader "Custom/DepthReserve"
{
    Properties
    {
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" "Queue"="AlphaTest+1" }
        LOD 100

        Blend Zero One

        Pass
        {

        }
    }
}

So this quad "reserves" the depth, not letting the ocean mesh to be shown.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .