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

Make shader keyword check compatible with Shader Graph shader #781

Merged
merged 2 commits into from
Mar 14, 2021
Merged
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
3 changes: 3 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public abstract class LodDataMgr
public const int THREAD_GROUP_SIZE_X = 8;
public const int THREAD_GROUP_SIZE_Y = 8;

// NOTE: This is a temporary solution to keywords having prefixes downstream.
internal const string MATERIAL_KEYWORD_PREFIX = "";

protected abstract int GetParamIdSampler(bool sourceLod = false);

protected abstract bool NeedToReadWriteTextureData { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class LodDataMgrClipSurface : LodDataMgr
protected override GraphicsFormat RequestedTextureFormat => GraphicsFormat.R8_UNorm;
protected override bool NeedToReadWriteTextureData { get { return true; } }

internal const string MATERIAL_KEYWORD = "_CLIPSURFACE_ON";
internal const string MATERIAL_KEYWORD_PROPERTY = "_ClipSurface";
internal const string MATERIAL_KEYWORD = MATERIAL_KEYWORD_PREFIX + "_CLIPSURFACE_ON";
internal const string ERROR_MATERIAL_KEYWORD_MISSING = "Clipping must be enabled on the ocean material to enable clipping holes in the water surface. Tick the <i>Enable</i> option in the <i>Clip Surface</i> parameter section on the material currently assigned to the OceanRenderer component.";
internal const string ERROR_MATERIAL_KEYWORD_ON_FEATURE_OFF = "The clipping feature is disabled on this component but is enabled on the ocean material. If this is not intentional, either enable the <i>Create Clip Surface Data</i> option on this component to turn it on, or disable the Clipping feature on the ocean material to save performance.";

Expand All @@ -35,7 +36,9 @@ public override void Start()
base.Start();

#if UNITY_EDITOR
if (!OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled(LodDataMgrClipSurface.MATERIAL_KEYWORD))
if (OceanRenderer.Instance.OceanMaterial != null
&& OceanRenderer.Instance.OceanMaterial.HasProperty(MATERIAL_KEYWORD_PROPERTY)
&& !OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled(MATERIAL_KEYWORD))
{
Debug.LogWarning(ERROR_MATERIAL_KEYWORD_MISSING, _ocean);
}
Expand Down
7 changes: 5 additions & 2 deletions crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgrFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class LodDataMgrFlow : LodDataMgr
protected override GraphicsFormat RequestedTextureFormat => GraphicsFormat.R16G16_SFloat;
protected override bool NeedToReadWriteTextureData { get { return false; } }

internal const string MATERIAL_KEYWORD = "_FLOW_ON";
internal const string MATERIAL_KEYWORD_PROPERTY = "_Flow";
internal const string MATERIAL_KEYWORD = MATERIAL_KEYWORD_PREFIX + "_FLOW_ON";
internal const string ERROR_MATERIAL_KEYWORD_MISSING = "Flow must be enabled on the ocean material. Tick the <i>Enable</i> option in the <i>Flow</i> parameter section on the material currently assigned to the OceanRenderer component.";
internal const string ERROR_MATERIAL_KEYWORD_ON_FEATURE_OFF = "The Flow feature is disabled on the this but is enabled on the ocean material. If this is not intentional, either enable the <i>Create Flow Data</i> option on this component to turn it on, or disable the Flow feature on the ocean material to save performance.";
bool _targetsClear = false;
Expand Down Expand Up @@ -52,7 +53,9 @@ public override void Start()
base.Start();

#if UNITY_EDITOR
if (!OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled(MATERIAL_KEYWORD))
if (OceanRenderer.Instance.OceanMaterial != null
&& OceanRenderer.Instance.OceanMaterial.HasProperty(MATERIAL_KEYWORD_PROPERTY)
&& !OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled(MATERIAL_KEYWORD))
{
Debug.LogWarning(ERROR_MATERIAL_KEYWORD_MISSING, _ocean);
}
Expand Down
6 changes: 4 additions & 2 deletions crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgrFoam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class LodDataMgrFoam : LodDataMgrPersistent
public override string SimName { get { return "Foam"; } }
protected override GraphicsFormat RequestedTextureFormat => Settings._renderTextureGraphicsFormat;

internal const string MATERIAL_KEYWORD = "_FOAM_ON";
internal const string MATERIAL_KEYWORD_PROPERTY = "_Foam";
internal const string MATERIAL_KEYWORD = MATERIAL_KEYWORD_PREFIX + "_FOAM_ON";
internal const string ERROR_MATERIAL_KEYWORD_MISSING = "Foam must be enabled on the ocean material. Tick the <i>Enable</i> option in the <i>Foam</i> parameter section on the material currently assigned to the OceanRenderer component.";
internal const string ERROR_MATERIAL_KEYWORD_ON_FEATURE_OFF = "The Foam feature is disabled on this component but is enabled on the ocean material. If this is not intentional, either enable the <i>Create Foam Sim</i> option on this component to turn it on, or disable the Foam feature on the ocean material to save performance.";

Expand Down Expand Up @@ -55,7 +56,8 @@ public override void Start()
base.Start();

#if UNITY_EDITOR
if (OceanRenderer.Instance != null && OceanRenderer.Instance.OceanMaterial != null
if (OceanRenderer.Instance.OceanMaterial != null
&& OceanRenderer.Instance.OceanMaterial.HasProperty(MATERIAL_KEYWORD_PROPERTY)
&& !OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled(MATERIAL_KEYWORD))
{
Debug.LogWarning(ERROR_MATERIAL_KEYWORD_MISSING, _ocean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private void LateUpdate()

#if UNITY_EDITOR
protected override bool FeatureEnabled(OceanRenderer ocean) => ocean.CreateClipSurfaceData;
protected override string RequiredShaderKeywordProperty => LodDataMgrClipSurface.MATERIAL_KEYWORD_PROPERTY;
protected override string RequiredShaderKeyword => LodDataMgrClipSurface.MATERIAL_KEYWORD;
protected override void FixOceanFeatureDisabled(SerializedObject oceanComponent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected override void FixOceanFeatureDisabled(SerializedObject oceanComponent)
oceanComponent.FindProperty("_createFlowSim").boolValue = true;
}

protected override string RequiredShaderKeywordProperty => LodDataMgrFlow.MATERIAL_KEYWORD_PROPERTY;
protected override string RequiredShaderKeyword => LodDataMgrFlow.MATERIAL_KEYWORD;
protected override string KeywordMissingErrorMessage => LodDataMgrFlow.ERROR_MATERIAL_KEYWORD_MISSING;
#endif // UNITY_EDITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected override void FixOceanFeatureDisabled(SerializedObject oceanComponent)
oceanComponent.FindProperty("_createFoamSim").boolValue = true;
}

protected override string RequiredShaderKeywordProperty => LodDataMgrFoam.MATERIAL_KEYWORD_PROPERTY;
protected override string RequiredShaderKeyword => LodDataMgrFoam.MATERIAL_KEYWORD;
protected override string KeywordMissingErrorMessage => LodDataMgrFoam.ERROR_MATERIAL_KEYWORD_MISSING;
#endif // UNITY_EDITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ public abstract partial class RegisterLodDataInputBase : IValidated
{
protected abstract bool FeatureEnabled(OceanRenderer ocean);
protected virtual string RequiredShaderKeyword => null;
// NOTE: Temporary until shader keywords are the same across pipelines.
protected virtual string RequiredShaderKeywordProperty => null;

protected virtual string FeatureDisabledErrorMessage => "Feature must be enabled on the OceanRenderer component.";
protected virtual string KeywordMissingErrorMessage => "Feature must be enabled on the ocean material.";
Expand All @@ -274,7 +276,7 @@ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessag
isValid = false;
}

if (!string.IsNullOrEmpty(RequiredShaderKeyword) && !ocean.OceanMaterial.IsKeywordEnabled(RequiredShaderKeyword))
if (!string.IsNullOrEmpty(RequiredShaderKeyword) && ocean.OceanMaterial.HasProperty(RequiredShaderKeywordProperty) && !ocean.OceanMaterial.IsKeywordEnabled(RequiredShaderKeyword))
{
showMessage(KeywordMissingErrorMessage, ValidatedHelper.MessageType.Error, ocean.OceanMaterial);
isValid = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class LodDataMgrShadow : LodDataMgr
protected override GraphicsFormat RequestedTextureFormat => GraphicsFormat.R8G8_UNorm;
protected override bool NeedToReadWriteTextureData { get { return true; } }

internal const string MATERIAL_KEYWORD = "_SHADOWS_ON";
internal const string MATERIAL_KEYWORD_PROPERTY = "_Shadows";
internal const string MATERIAL_KEYWORD = MATERIAL_KEYWORD_PREFIX + "_SHADOWS_ON";
internal const string ERROR_MATERIAL_KEYWORD_MISSING = "Shadowing must be enabled on the ocean material. Tick the <i>Shadowing</i> option in the <i>Scattering</i> parameter section on the material currently assigned to the OceanRenderer component.";
internal const string ERROR_MATERIAL_KEYWORD_ON_FEATURE_OFF = "The shadow feature is disabled on this component but is enabled on the ocean material. If this is not intentional, either enable the <i>Create Shadow Data</i> option on this component to turn it on, or disable the Shadowing feature on the ocean material to save performance.";

Expand Down Expand Up @@ -95,7 +96,9 @@ public override void Start()
}

#if UNITY_EDITOR
if (!OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled(MATERIAL_KEYWORD))
if (OceanRenderer.Instance.OceanMaterial != null
&& OceanRenderer.Instance.OceanMaterial.HasProperty(MATERIAL_KEYWORD_PROPERTY)
&& !OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled(MATERIAL_KEYWORD))
{
Debug.LogWarning(ERROR_MATERIAL_KEYWORD_MISSING, _ocean);
}
Expand Down
14 changes: 10 additions & 4 deletions crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,13 @@ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessag
);
}

if (ocean.CreateFoamSim != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrFoam.MATERIAL_KEYWORD))
// For safety.
if (ocean == null || ocean.OceanMaterial == null)
{
return isValid;
}

if (ocean.OceanMaterial.HasProperty(LodDataMgrFoam.MATERIAL_KEYWORD_PROPERTY) && ocean.CreateFoamSim != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrFoam.MATERIAL_KEYWORD))
{
if (ocean.CreateFoamSim)
{
Expand All @@ -1294,7 +1300,7 @@ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessag
}
}

if (ocean.CreateFlowSim != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrFlow.MATERIAL_KEYWORD))
if (ocean.OceanMaterial.HasProperty(LodDataMgrFlow.MATERIAL_KEYWORD_PROPERTY) && ocean.CreateFlowSim != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrFlow.MATERIAL_KEYWORD))
{
if (ocean.CreateFlowSim)
{
Expand All @@ -1306,7 +1312,7 @@ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessag
}
}

if (ocean.CreateShadowData != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrShadow.MATERIAL_KEYWORD))
if (ocean.OceanMaterial.HasProperty(LodDataMgrShadow.MATERIAL_KEYWORD_PROPERTY) && ocean.CreateShadowData != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrShadow.MATERIAL_KEYWORD))
{
if (ocean.CreateShadowData)
{
Expand All @@ -1318,7 +1324,7 @@ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessag
}
}

if (ocean.CreateClipSurfaceData != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrClipSurface.MATERIAL_KEYWORD))
if (ocean.OceanMaterial.HasProperty(LodDataMgrClipSurface.MATERIAL_KEYWORD_PROPERTY) && ocean.CreateClipSurfaceData != ocean.OceanMaterial.IsKeywordEnabled(LodDataMgrClipSurface.MATERIAL_KEYWORD))
{
if (ocean.CreateClipSurfaceData)
{
Expand Down