Skip to content

Commit

Permalink
Merge pull request #902 from wave-harmonic/feature/water-body-materia…
Browse files Browse the repository at this point in the history
…l-override

Water body material override
  • Loading branch information
huwb authored Sep 15, 2021
2 parents c14ec77 + 49945ea commit 343830a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crest/Assets/Crest/Crest/Scripts/OceanChunkRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class OceanChunkRenderer : MonoBehaviour
public Renderer Rend { get; private set; }
PropertyWrapperMPB _mpb;

public bool MaterialOverridden { get; set; }

// We need to ensure that all ocean data has been bound for the mask to
// render properly - this is something that needs to happen irrespective
Expand Down Expand Up @@ -113,7 +114,7 @@ internal void BindOceanData(Camera camera)
return;
}

if (Rend.sharedMaterial != OceanRenderer.Instance.OceanMaterial)
if (!MaterialOverridden && Rend.sharedMaterial != OceanRenderer.Instance.OceanMaterial)
{
Rend.sharedMaterial = OceanRenderer.Instance.OceanMaterial;
}
Expand Down
11 changes: 11 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,17 @@ void LateUpdateTiles()
if (overlapping)
{
overlappingOne = true;

if (body._overrideMaterial != null)
{
tile.Rend.sharedMaterial = body._overrideMaterial;
tile.MaterialOverridden = true;
}
else
{
tile.MaterialOverridden = false;
}

break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/WaterBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public partial class WaterBody : MonoBehaviour

public Bounds AABB { get; private set; }

[Tooltip("Water geometry tiles that overlap this waterbody area will be assigned this material. This " +
"is useful for varying water appearance across different water bodies. If no override material is " +
"specified, the default material assigned to the OceanRenderer component will be used.")]
public Material _overrideMaterial = null;

private void OnEnable()
{
CalculateBounds();
Expand Down
1 change: 1 addition & 0 deletions docs/about/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Changed

- Add *Dynamic Waves* reflections from *Ocean Depth Cache* geometry.
- Add inverted option to *Clip Surface* signed-distance primitives and convex hulls which removes clipping.
- Add *Override Material* field to the *Water Body* component to enable varying water material across water bodies.


4.13
Expand Down
3 changes: 3 additions & 0 deletions docs/user/water-bodies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ There are mechanisms to limit the area:
The *Clip Surface* feature can be used to precisely remove any remaining water outside the intended area.
Additionally, the clipping system can be configured to clip everything by default, and then areas can be defined where water should be included. See the :ref:`clip-surface-section` section.

Another advantage of the *WaterBody* component is it allows an optional override material to be provided, to change the appearance of the water.
This currently only changes the appearance of the water surface, it does not currently affect the underwater effect.


Wizard (preview)
----------------
Expand Down

0 comments on commit 343830a

Please sign in to comment.