Skip to content

Add Ocean Depth Shader

In this part, I add Ocean depth shader to distinguish different depth of the ocean.

To make this happen, I need to add a new parameter in colorsettings.cs script to determine the gradient color of the ocean.

And in the previous code, we start to calculate the elevation from the ocean to the max elevation.

Right now, we need to add the ocean depth into the elevation calculation.

So we divided the ocean and continent part into half, the ocean elevation from 0 to 0.5 and continent from 0.5 to 1. This code below help to make this happen.

public float CalculateUnscaledElevation(Vector3 pointOnUnitSphere)
    {
        float firstLayerValue = 0;
        float elevation = 0;

        if (noiseFilters.Length > 0)
        {
            firstLayerValue = noiseFilters[0].Evaluate(pointOnUnitSphere);
            if (settings.noiseLayers[0].enabled)
            {
                elevation = firstLayerValue;
            }
        }

        for (int i = 0; i < noiseFilters.Length; i++)
        {
            if (settings.noiseLayers[i].enabled)
            {
                float mask = (settings.noiseLayers[i].useFirstLayerAsMask) ? firstLayerValue : 1;
                elevation += noiseFilters[i].Evaluate(pointOnUnitSphere)*mask;
            }
        }
        elevationMinMax.AddValue(elevation);
        return elevation;
    }

    public float GetScaledElevation(float unscaledElevation)
    {
        float elevation = Mathf.Max(0, unscaledElevation);
        elevation = settings.planetRadius * (1 + elevation);
        return elevation;
    }

By setting the PBR looks like below, it can set the color into ocean depth.

 

(Visited 17 times, 1 visits today)

Be First to Comment

Leave a Reply

%d bloggers like this: