Skip to content

Commit

Permalink
Merge pull request #15 from Unity-Technologies/rg-conversion-base
Browse files Browse the repository at this point in the history
RenderGraph support
  • Loading branch information
Verasl authored May 8, 2023
2 parents 4c5b5d1 + c370a13 commit 68db52d
Show file tree
Hide file tree
Showing 57 changed files with 2,578 additions and 671 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Runtime/.DS_Store
.DS_Store
33 changes: 1 addition & 32 deletions Editor/OceanEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static class Styles
public static GUIContent waveFoamProfile = new GUIContent("Profile");
public static GUIContent waveDepthProfile = new GUIContent("Depth Multiplier");
// Reflection
public static GUIContent refType = new GUIContent("Mode");
public static GUIContent cubemap = new GUIContent("Cubemap");
// Shore
public static GUIContent foamIntensity = new GUIContent("Foam Amount");
Expand All @@ -50,12 +49,7 @@ public static class Styles

private SerializedProperty waveDepthProfile;
// reflection
private SerializedProperty refelctionType;

private SerializedProperty cubemap;

private SerializedProperty planarSettings;
private SerializedProperty ssrSettings;
// flow
// shore
private SerializedProperty foamIntensity;
Expand Down Expand Up @@ -96,10 +90,7 @@ private void OnEnable()

waveDepthProfile = settings.FindPropertyRelative(nameof(Data.OceanSettings._waveDepthProfile));
// Reflection Settings
refelctionType = settings.FindPropertyRelative(nameof(Data.OceanSettings.refType));
cubemap = settings.FindPropertyRelative(nameof(Data.OceanSettings.cubemapRefType));
planarSettings = settings.FindPropertyRelative(nameof(Data.OceanSettings.planarSettings));
ssrSettings = settings.FindPropertyRelative(nameof(Data.OceanSettings.SsrSettings));

// Shore
foamIntensity = settings.FindPropertyRelative(nameof(Data.OceanSettings._foamIntensity));
Expand Down Expand Up @@ -174,29 +165,7 @@ void DoWaves()

void DoReflection()
{
EditorGUILayout.PropertyField(refelctionType, Styles.refType);
EditorGUI.indentLevel++;
switch ((Data.ReflectionType)refelctionType.enumValueIndex)
{
case Data.ReflectionType.Cubemap:
EditorGUILayout.PropertyField(cubemap, Styles.cubemap);
break;
case Data.ReflectionType.ReflectionProbe:
EditorGUILayout.HelpBox("Currently there are no settings for this mode.", MessageType.Info);
break;
case Data.ReflectionType.PlanarReflection:
EditorGUILayout.PropertyField(planarSettings);
break;
case Data.ReflectionType.ScreenSpaceReflection:
EditorGUILayout.PropertyField(ssrSettings);
EditorGUILayout.LabelField("Fallback Cubemap", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(cubemap, Styles.cubemap);
break;
default:
throw new ArgumentOutOfRangeException();
}

EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(cubemap, Styles.cubemap);
}

void DoFlow()
Expand Down
72 changes: 55 additions & 17 deletions Editor/PlanarSettingsDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using PlanarSettings = WaterSystem.Rendering.PlanarReflections.PlanarReflectionSettings;

Expand All @@ -7,8 +8,6 @@ namespace WaterSystem.Rendering
[CustomPropertyDrawer(typeof(PlanarReflections.PlanarReflectionSettings))]
public class PlanarSettingsDrawer : PropertyDrawer
{
private bool rendererModeExpand = false;

// Props
private SerializedProperty resolutionMode;
private SerializedProperty resolutionMulti;
Expand All @@ -19,6 +18,8 @@ public class PlanarSettingsDrawer : PropertyDrawer
private SerializedProperty rendererMode;
private SerializedProperty rendererIndex;

private float height;

private void InitProps(SerializedProperty property)
{
resolutionMode = property.FindPropertyRelative(nameof(PlanarSettings.m_ResolutionMode));
Expand All @@ -33,42 +34,79 @@ private void InitProps(SerializedProperty property)

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
InitProps(property);
EditorGUI.BeginProperty(position, label, property);

InitProps(property);
// Setup of extra data
rendererModeExpand = (PlanarReflections.RendererMode)rendererMode.enumValueIndex != PlanarReflections.RendererMode.Match;
var basePos = position;
position.height = SingleLine();

EditorGUI.PropertyField(position, resolutionMode);
position.y += SingleLine();
EditorGUI.indentLevel++;
switch (resolutionMode.enumValueIndex)
{
case (int)PlanarReflections.ResolutionModes.Multiplier:
EditorGUI.PropertyField(EditorGUILayout.GetControlRect(true), resolutionMulti);
EditorGUI.PropertyField(position, resolutionMulti);
position.y += SingleLine();
break;
case (int)PlanarReflections.ResolutionModes.Custom:
EditorGUI.indentLevel++;
EditorGUI.PropertyField(EditorGUILayout.GetControlRect(true), resolutionCustom);
EditorGUI.indentLevel--;
EditorGUI.PropertyField(position, resolutionCustom);
position.y += SingleLine();
break;
}
EditorGUI.indentLevel--;
EditorGUI.PropertyField(EditorGUILayout.GetControlRect(true), layerMask);
EditorGUI.PropertyField(EditorGUILayout.GetControlRect(true), shadows);
EditorGUI.PropertyField(EditorGUILayout.GetControlRect(true), obliqueProjection);
EditorGUI.PropertyField(position, layerMask);
position.y += SingleLine();
EditorGUI.PropertyField(position, shadows);
position.y += SingleLine();
EditorGUI.PropertyField(position, obliqueProjection);
position.y += SingleLine();
if (obliqueProjection.boolValue == false)
EditorGUILayout.HelpBox(
{
position.height = SingleLine() * 2;
EditorGUI.HelpBox(position,
"Disabling Oblique Projection will lead to objects refelcting below the water," +
" only use this if you are having issue with certaint effects in the relfeciotns like Fog.",
MessageType.Info);
EditorGUI.PropertyField(EditorGUILayout.GetControlRect(true), rendererMode);
if (rendererModeExpand)
position.y += SingleLine() * 2;
}
position.height = SingleLine();
EditorGUI.PropertyField(position, rendererMode);
position.y += SingleLine();
if (RendererModeExpand())
{
EditorGUI.indentLevel++;
EditorGUI.PropertyField(EditorGUILayout.GetControlRect(true), rendererIndex);
EditorGUI.PropertyField(position, rendererIndex);
position.y += SingleLine();
EditorGUI.indentLevel--;
}
EditorGUI.EndProperty();

position.height = height = position.y - basePos.y;
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
InitProps(property);
var baseHeight = 5; // base properties (res, layers, shadows, oblique, renderer mode) = 5
baseHeight += (obliqueProjection.boolValue ? 0 : 2); // add height for oblique help box
baseHeight += (RendererModeExpand() ? 1 : 0); // add height for oblique help box
baseHeight += resolutionMode.enumValueIndex // add extra space for resolution extras
is (int) PlanarReflections.ResolutionModes.Custom
or (int) PlanarReflections.ResolutionModes.Multiplier
? 1 : 0;

return SingleLine() * baseHeight;
}

private float SingleLine()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}

private bool RendererModeExpand()
{
return (PlanarReflections.RendererMode) rendererMode.enumValueIndex != PlanarReflections.RendererMode.Match;
}
}
}
188 changes: 187 additions & 1 deletion Editor/PropertyDrawers.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using UnityEditor;
using UnityEngine;
using WaterSystem.Settings;

namespace WaterSystem
{
public class PropertyDrawers
class PropertyDrawers
{
[CustomPropertyDrawer(typeof(Data.BasicWaves))]
public class BasicWavesEditor : PropertyDrawer
Expand Down Expand Up @@ -43,5 +45,189 @@ public class DataEditor : Editor
{
// null
}

[CustomPropertyDrawer(typeof(WaterQualitySettings))]
public class WaterQualitySettingsDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var baseRect = position;

position.height = SingleLineHeight(false);
DoGeometry(ref position, ref property);
DoReflection(ref position, ref property);
DoLighting(ref position, ref property);
DoCaustics(ref position, ref property);
}

private void DoGeometry(ref Rect position, ref SerializedProperty property)
{
EditorGUI.LabelField(position, "Geometry", EditorStyles.boldLabel);
position.y += SingleLineHeight();
EditorGUI.indentLevel++;
{
EditorGUI.PropertyField(position,
property.FindPropertyRelative(nameof(WaterQualitySettings.waterGeomType)));
position.y += SingleLineHeight();
}
EditorGUI.indentLevel--;
}

private void DoReflection(ref Rect position, ref SerializedProperty property)
{
EditorGUI.LabelField(position, "Reflection", EditorStyles.boldLabel);
position.y += SingleLineHeight();

var refSettings = property.FindPropertyRelative(nameof(WaterQualitySettings.reflectionSettings));

EditorGUI.indentLevel++;
{
var refMode = refSettings.FindPropertyRelative(nameof(WaterQualitySettings.reflectionSettings
.reflectionType));
EditorGUI.PropertyField(position, refMode);
position.y += SingleLineHeight();

EditorGUI.indentLevel++;
switch ((Data.ReflectionSettings.Type)refMode.enumValueIndex)
{
case Data.ReflectionSettings.Type.Cubemap:
DoRefTypeCubemap(ref position, ref property);
break;
case Data.ReflectionSettings.Type.ReflectionProbe:
DoRefTypeProbe(ref position, ref property);
break;
case Data.ReflectionSettings.Type.PlanarReflection:
var planarProp =
refSettings.FindPropertyRelative(nameof(Data.ReflectionSettings.planarSettings));
DoRefTypePlanarRefleciton(ref position, ref planarProp);
break;
case Data.ReflectionSettings.Type.ScreenSpaceReflection:
DoRefTypeSSR(ref position, ref property);
break;
default:
throw new ArgumentOutOfRangeException();
}

EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
}

private void DoLighting(ref Rect position, ref SerializedProperty property)
{
EditorGUI.LabelField(position, "Lighting", EditorStyles.boldLabel);
position.y += SingleLineHeight();
EditorGUI.indentLevel++;
{
var lightingProp = property.FindPropertyRelative(nameof(WaterQualitySettings.lightingSettings));
EditorGUI.PropertyField(position, lightingProp, true);
position.y += EditorGUI.GetPropertyHeight(lightingProp);
}
EditorGUI.indentLevel--;
}

private void DoCaustics(ref Rect position, ref SerializedProperty property)
{
EditorGUI.LabelField(position, "Caustics", EditorStyles.boldLabel);
position.y += SingleLineHeight();
EditorGUI.indentLevel++;
{
var causticsProp = property.FindPropertyRelative(nameof(WaterQualitySettings.causticSettings));
EditorGUI.PropertyField(position, causticsProp, true);
position.y += EditorGUI.GetPropertyHeight(causticsProp);
}
EditorGUI.indentLevel--;
}

private void DoRefTypeCubemap(ref Rect position, ref SerializedProperty property)
{
// no GUI
}

private void DoRefTypeProbe(ref Rect position, ref SerializedProperty property)
{
// no GUI
}

private void DoRefTypePlanarRefleciton(ref Rect position, ref SerializedProperty property)
{
EditorGUI.PropertyField(position, property);
position.y += EditorGUI.GetPropertyHeight(property);
}

private void DoRefTypeSSR(ref Rect position, ref SerializedProperty property)
{
var ssrProp = property.FindPropertyRelative(nameof(WaterQualitySettings.ssrSettings));
EditorGUI.PropertyField(position, ssrProp, true);
position.y += EditorGUI.GetPropertyHeight(ssrProp);
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var height = SingleLineHeight() * 4; // all 4 catergory headers
height += SingleLineHeight();// geometry

var refSettings = property.FindPropertyRelative(nameof(WaterQualitySettings.reflectionSettings));

if (refSettings == null) return 50f;

var refMode = refSettings.FindPropertyRelative(nameof(Data.ReflectionSettings.reflectionType)).enumValueIndex;
height += SingleLineHeight();// ref mode dropdown
switch ((Data.ReflectionSettings.Type)refMode)
{
case Data.ReflectionSettings.Type.Cubemap:
height += SingleLineHeight();
break;
case Data.ReflectionSettings.Type.ReflectionProbe:
height += SingleLineHeight();
break;
case Data.ReflectionSettings.Type.PlanarReflection:
height += EditorGUI.GetPropertyHeight(
refSettings.FindPropertyRelative(nameof(Data.ReflectionSettings.planarSettings)));
break;
case Data.ReflectionSettings.Type.ScreenSpaceReflection:
height += EditorGUI.GetPropertyHeight(
property.FindPropertyRelative(nameof(WaterQualitySettings.ssrSettings)));
break;
}

height += EditorGUI.GetPropertyHeight(
property.FindPropertyRelative(nameof(WaterQualitySettings.lightingSettings)));

height += EditorGUI.GetPropertyHeight(
property.FindPropertyRelative(nameof(WaterQualitySettings.causticSettings)));

return height;
}
}

[CustomPropertyDrawer(typeof(Settings.Resources))]
public class WaterResourcesDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
position.height = SingleLineHeight(false);
var enumerator = property.GetEnumerator();
while (enumerator.MoveNext()) {
var prop = enumerator.Current as SerializedProperty;
if (prop == null) continue;

EditorGUI.PropertyField(position, prop);
position.y += SingleLineHeight();
}
EditorGUI.EndProperty();
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return property.isExpanded ? SingleLineHeight() * (property.CountInProperty() - 1) : 0;
}
}

public static float SingleLineHeight(bool withSpacing = true)
{
return EditorGUIUtility.singleLineHeight + (withSpacing ? EditorGUIUtility.standardVerticalSpacing : 0);
}
}
}
4 changes: 2 additions & 2 deletions Editor/ShaderPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void OnProcessShader(
var refType = 0;
foreach (var oceanGuid in oceans)
{
var ocean = AssetDatabase.LoadAssetAtPath<Ocean>(AssetDatabase.GUIDToAssetPath(oceanGuid));
refType |= (int)ocean.settingsData.refType;
//var ocean = AssetDatabase.LoadAssetAtPath<Ocean>(AssetDatabase.GUIDToAssetPath(oceanGuid));
//refType |= (int)ocean.settingsData.refType;
}

/*
Expand Down
Loading

0 comments on commit 68db52d

Please sign in to comment.