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

Fix OceanDepthCache disabling in edit mode #897

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ namespace Crest
/// (directional light, reflections, ambient etc) with the underwater depth. This works with vanilla lighting, but
/// uncommon or custom lighting will require a custom solution (use this for reference).
/// </summary>
[DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_EXAMPLE + "Underwater Environmental Lighting")]
public class UnderwaterEnvironmentalLighting : MonoBehaviour
{
public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;

/// <summary>
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public interface IFloatingOrigin
/// script should normally be attached to the viewpoint, typically the main camera.
/// </summary>
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Floating Origin")]
[DefaultExecutionOrder(k_DefaultExecutionOrder)]
[HelpURL(Internal.Constants.HELP_URL_BASE_USER + "other-features.html" + Internal.Constants.HELP_URL_RP + "#floating-origin")]
public class FloatingOrigin : MonoBehaviour
{
public const int k_DefaultExecutionOrder = -200;

/// <summary>
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions crest/Assets/Crest/Crest/Scripts/LodData/OceanDepthCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ namespace Crest
/// This should be used for static geometry, dynamic objects should be tagged with the Render Ocean Depth component.
/// </summary>
[ExecuteAlways]
[DefaultExecutionOrder(k_DefaultExecutionOrder)]
[HelpURL(Internal.Constants.HELP_URL_BASE_USER + "shallows-and-shorelines.html" + Internal.Constants.HELP_URL_RP)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Ocean Depth Cache")]
public partial class OceanDepthCache : MonoBehaviour
{
public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;

/// <summary>
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
Expand Down Expand Up @@ -90,12 +93,6 @@ public enum OceanDepthCacheRefreshMode

void Start()
{
if (OceanRenderer.Instance == null)
{
enabled = false;
return;
}

#if UNITY_EDITOR
if (EditorApplication.isPlaying && _runValidationOnStart)
{
Expand Down Expand Up @@ -643,6 +640,17 @@ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessag
isValid = false;
}

if (ocean == null)
{
showMessage
(
"The <i>Ocean Depth Cache</i> uses the <i>Ocean Renderer</i> height which is not present. " +
"The transform height will be used instead.",
"", // Leave fix message blank as this could be a valid option.
ValidatedHelper.MessageType.Info, this
);
}

if (ocean != null && ocean.Root != null && !Mathf.Approximately(transform.position.y, ocean.Root.position.y))
{
showMessage
Expand Down
4 changes: 4 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ namespace Crest
/// and moves/scales the ocean based on the viewpoint. It also hosts a number of global settings that can be tweaked here.
/// </summary>
[ExecuteAlways, SelectionBase]
[DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Ocean Renderer")]
[HelpURL(Constants.HELP_URL_GENERAL)]
public partial class OceanRenderer : MonoBehaviour
{
// Update ocean after Cinemachine.
public const int k_DefaultExecutionOrder = 200;

/// <summary>
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
Expand Down
2 changes: 1 addition & 1 deletion crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ static void InitStatics()
/// <summary>
/// Attach to a camera to generate a reflection texture which can be sampled in the ocean shader.
/// </summary>
[RequireComponent(typeof(Camera))]
[DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Ocean Planar Reflections")]
public class OceanPlanarReflection : MonoBehaviour
public partial class OceanPlanarReflection : MonoBehaviour
{
public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;

/// <summary>
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
Expand Down Expand Up @@ -125,33 +129,21 @@ public class OceanPlanarReflection : MonoBehaviour
const int CULL_DISTANCE_COUNT = 32;
float[] _cullDistances = new float[CULL_DISTANCE_COUNT];

private void Start()
void OnEnable()
{
if (OceanRenderer.Instance == null)
if (_camViewpoint == null)
{
enabled = false;
return;
_camViewpoint = GetComponent<Camera>();
}

_camViewpoint = GetComponent<Camera>();
if (!_camViewpoint)
if (_camViewpointSkybox == null)
{
Debug.LogWarning("Crest: Disabling planar reflections as no camera found on gameobject to generate reflection from.", this);
enabled = false;
return;
_camViewpointSkybox = _camViewpoint.GetComponent<Skybox>();
}
_camViewpointSkybox = _camViewpoint?.GetComponent<Skybox>();

// This is anyway called in OnPreRender, but was required here as there was a black reflection
// for a frame without this earlier setup call.
CreateWaterObjects(_camViewpoint);

#if UNITY_EDITOR
if (!OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled("_PLANARREFLECTIONS_ON"))
{
Debug.LogWarning("Crest: Planar reflections are not enabled on the current ocean material and will not be visible.", this);
}
#endif
}

bool RequestRefresh(long frame)
Expand Down Expand Up @@ -401,4 +393,27 @@ private void OnDisable()
}
}
}

#if UNITY_EDITOR
public partial class OceanPlanarReflection : IValidated
{
public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessage)
{
var isValid = true;

if (ocean != null && !ocean.OceanMaterial.IsKeywordEnabled("_PLANARREFLECTIONS_ON"))
{
showMessage
(
"Crest: Planar reflections are not enabled on the current ocean material and will not be visible.",
"Enable planar reflections.",
ValidatedHelper.MessageType.Warning,
this
);
}

return isValid;
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ namespace Crest
/// For convenience, all shader material settings are copied from the main ocean shader.
/// </summary>
[RequireComponent(typeof(Camera))]
[DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Underwater Renderer")]
[HelpURL(Internal.Constants.HELP_URL_BASE_USER + "underwater.html" + Internal.Constants.HELP_URL_RP)]
public partial class UnderwaterRenderer : MonoBehaviour
{
public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;

/// <summary>
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.