Skip to content

Commit

Permalink
com.unity.render-pipelines.core@5.0.0-preview
Browse files Browse the repository at this point in the history
## [5.0.0-preview] - 2018-09-28
### Changed
- XRGraphicConfig has been changed from a read-write control of XRSettings to XRGraphics, a read-only accessor to XRSettings. This improves consistency of XR behavior between the legacy render pipeline and SRP.
- XRGraphics members have been renamed to match XRSettings, and XRGraphics has been modified to only contain accessors potentially useful to SRP
- You can now have up to 16 additional shadow-casting lights.
### Fixed
- LWRP no longer executes shadow passes when there are no visible shadow casters in a Scene. Previously, this made the Scene render as too dark, overall.
  • Loading branch information
Unity Technologies committed Sep 27, 2018
1 parent 6a72128 commit bfa51d6
Show file tree
Hide file tree
Showing 29 changed files with 640 additions and 302 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.0.1-preview] - 2018-10-01
## [5.0.0-preview] - 2018-09-28
### Changed
- XRGraphicConfig has been changed from a read-write control of XRSettings to XRGraphics, a read-only accessor to XRSettings. This improves consistency of XR behavior between the legacy render pipeline and SRP.
- XRGraphics members have been renamed to match XRSettings, and XRGraphics has been modified to only contain accessors potentially useful to SRP
- You can now have up to 16 additional shadow-casting lights.
### Fixed
- Fixed compiler warnings on new mono
- LWRP no longer executes shadow passes when there are no visible shadow casters in a Scene. Previously, this made the Scene render as too dark, overall.


## [4.0.0-preview] - 2018-09-28
### Added
Expand Down
8 changes: 5 additions & 3 deletions Editor/CoreEditorDrawers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public enum FoldoutOption
{
None = 0,
Indent = 1 << 0,
Animate = 1 << 1
Animate = 1 << 1,
Boxed = 1 << 2
}

[Flags]
Expand Down Expand Up @@ -182,6 +183,7 @@ class FoldoutDrawerInternal : IDrawer

bool animate { get { return (m_Options & FoldoutOption.Animate) != 0; } }
bool indent { get { return (m_Options & FoldoutOption.Indent) != 0; } }
bool boxed { get { return (m_Options & FoldoutOption.Boxed) != 0; } }

public FoldoutDrawerInternal(string title, AnimBoolGetter isExpanded, FoldoutOption options, params IDrawer[] bodies)
{
Expand All @@ -194,8 +196,8 @@ public FoldoutDrawerInternal(string title, AnimBoolGetter isExpanded, FoldoutOpt
public void Draw(TUIState s, TData p, Editor owner)
{
var r = m_IsExpanded(s, p, owner);
CoreEditorUtils.DrawSplitter();
r.target = CoreEditorUtils.DrawHeaderFoldout(m_Title, r.target);
CoreEditorUtils.DrawSplitter(boxed);
r.target = CoreEditorUtils.DrawHeaderFoldout(m_Title, r.target, boxed);
// We must start with a layout group here
// Otherwise, nested FadeGroup won't work
GUILayout.BeginVertical();
Expand Down
52 changes: 33 additions & 19 deletions Editor/CoreEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ public static void DrawMultipleFields(string label, SerializedProperty[] ppts, G
EditorGUIUtility.labelWidth = labelWidth;
}

public static void DrawSplitter()
public static void DrawSplitter(bool isBoxed = false)
{
var rect = GUILayoutUtility.GetRect(1f, 1f);

// Splitter rect should be full-width
rect.xMin = 0f;
rect.width += 4f;

if (isBoxed)
{
rect.xMin = EditorGUIUtility.singleLineHeight - 2;
rect.width -= 1;
}

if (Event.current.type != EventType.Repaint)
return;
Expand Down Expand Up @@ -130,7 +136,7 @@ public static void DrawHeader(string title)
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel);
}

public static bool DrawHeaderFoldout(string title, bool state)
public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = false)
{
var backgroundRect = GUILayoutUtility.GetRect(1f, 17f);

Expand All @@ -147,6 +153,14 @@ public static bool DrawHeaderFoldout(string title, bool state)
backgroundRect.xMin = 0f;
backgroundRect.width += 4f;

if (isBoxed)
{
labelRect.xMin += 5;
foldoutRect.xMin += 5;
backgroundRect.xMin = EditorGUIUtility.singleLineHeight;
backgroundRect.width -= 3;
}

// Background
float backgroundTint = EditorGUIUtility.isProSkin ? 0.1f : 1f;
EditorGUI.DrawRect(backgroundRect, new Color(backgroundTint, backgroundTint, backgroundTint, 0.2f));
Expand Down Expand Up @@ -248,39 +262,39 @@ public static bool DrawHeaderToggle(string title, SerializedProperty group, Seri
const int k_DrawVector6Slider_LabelSize = 60;
const int k_DrawVector6Slider_FieldSize = 80;

public static void DrawVector6(GUIContent label, SerializedProperty positive, SerializedProperty negative, Vector3 min, Vector3 max, Color[][] colors = null)
public static void DrawVector6(GUIContent label, ref Vector3 positive, ref Vector3 negative, Vector3 min, Vector3 max, Color[] colors = null)
{
if (colors != null && (colors.Length != 2 || colors[0].Length != 3 || colors[1].Length != 3))
throw new System.ArgumentException("Colors must be a 2x3 array.");
if (colors != null && (colors.Length != 6))
throw new System.ArgumentException("Colors must be a 6 element array. [+X, +Y, +X, -X, -Y, -Z]");

GUILayout.BeginVertical();
Rect rect = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(0, float.MaxValue, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight));
if (label != GUIContent.none)
{
var labelRect = rect;
labelRect.x -= 12f;
labelRect.x -= 11f * EditorGUI.indentLevel;
labelRect.width = EditorGUIUtility.labelWidth;
EditorGUI.LabelField(labelRect, label);
rect.x += EditorGUIUtility.labelWidth - 12f;
rect.width -= EditorGUIUtility.labelWidth - 12f;
rect.x += EditorGUIUtility.labelWidth - 1f - 11f * EditorGUI.indentLevel;
rect.width -= EditorGUIUtility.labelWidth - 1f - 11f * EditorGUI.indentLevel;
}

var v = positive.vector3Value;
var v = positive;
EditorGUI.BeginChangeCheck();
v = DrawVector3(rect, k_DrawVector6_Label, v, min, max, false, colors == null ? null : colors[0]);
v = DrawVector3(rect, k_DrawVector6_Label, v, min, max, false, colors == null ? null : new Color[] { colors[0], colors[1], colors[2] });
if (EditorGUI.EndChangeCheck())
positive.vector3Value = v;
positive = v;

GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

rect = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(0, float.MaxValue, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight));
rect.x += EditorGUIUtility.labelWidth - 12f;
rect.width -= EditorGUIUtility.labelWidth - 12f;
v = negative.vector3Value;
rect.x += EditorGUIUtility.labelWidth - 1f - 11f * EditorGUI.indentLevel;
rect.width -= EditorGUIUtility.labelWidth - 1f - 11f * EditorGUI.indentLevel;
v = negative;
EditorGUI.BeginChangeCheck();
v = DrawVector3(rect, k_DrawVector6_Label, v, min, max, true, colors == null ? null : colors[1]);
v = DrawVector3(rect, k_DrawVector6_Label, v, min, max, true, colors == null ? null : new Color[] { colors[3], colors[4], colors[5] });
if (EditorGUI.EndChangeCheck())
negative.vector3Value = v;
negative = v;
GUILayout.EndVertical();
}

Expand All @@ -301,7 +315,7 @@ static Vector3 DrawVector3(Rect rect, GUIContent[] labels, Vector3 value, Vector
//Suffix is a hack as sublabel only work with 1 character
if(addMinusPrefix)
{
Rect suffixRect = new Rect(rect.x-19, rect.y, 100, rect.height);
Rect suffixRect = new Rect(rect.x - 4 - 15 * EditorGUI.indentLevel, rect.y, 100, rect.height);
for(int i = 0; i < 3; ++i)
{
EditorGUI.LabelField(suffixRect, "-");
Expand All @@ -315,7 +329,7 @@ static Vector3 DrawVector3(Rect rect, GUIContent[] labels, Vector3 value, Vector
if (colors.Length != 3)
throw new System.ArgumentException("colors must have 3 elements.");

Rect suffixRect = new Rect(rect.x - 8, rect.y, 100, rect.height);
Rect suffixRect = new Rect(rect.x + 7 - 15 * EditorGUI.indentLevel, rect.y, 100, rect.height);
GUIStyle colorMark = new GUIStyle(EditorStyles.label);
colorMark.normal.textColor = colors[0];
EditorGUI.LabelField(suffixRect, "|", colorMark);
Expand All @@ -326,7 +340,7 @@ static Vector3 DrawVector3(Rect rect, GUIContent[] labels, Vector3 value, Vector
EditorGUI.LabelField(suffixRect, "|", colorMark);
suffixRect.x += 1;
EditorGUI.LabelField(suffixRect, "|", colorMark);
suffixRect.x += fieldWidth + .5f;
suffixRect.x += fieldWidth;
colorMark.normal.textColor = colors[2];
EditorGUI.LabelField(suffixRect, "|", colorMark);
suffixRect.x += 1;
Expand Down
8 changes: 8 additions & 0 deletions Editor/Shadow/ShadowCascadeSplitGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartition
if (s_RestoreSceneView != null)
{
s_OldSceneDrawMode = s_RestoreSceneView.cameraMode;
#if UNITY_2019_1_OR_NEWER
s_OldSceneLightingMode = s_RestoreSceneView.sceneLighting;
#else
s_OldSceneLightingMode = s_RestoreSceneView.m_SceneLighting;
#endif
s_RestoreSceneView.cameraMode = SceneView.GetBuiltinCameraMode(DrawCameraMode.ShadowCascades);
}
}
Expand All @@ -187,7 +191,11 @@ public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartition
if (s_RestoreSceneView != null)
{
s_RestoreSceneView.cameraMode = s_OldSceneDrawMode;
#if UNITY_2019_1_OR_NEWER
s_RestoreSceneView.sceneLighting = s_OldSceneLightingMode;
#else
s_RestoreSceneView.m_SceneLighting = s_OldSceneLightingMode;
#endif
s_RestoreSceneView = null;
}
break;
Expand Down
31 changes: 0 additions & 31 deletions Editor/XRGraphicsConfigDrawer.cs

This file was deleted.

164 changes: 164 additions & 0 deletions Runtime/Common/XRGraphics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using System;
using UnityEditor;
#if UNITY_2017_2_OR_NEWER
using UnityEngine.XR;
using XRSettings = UnityEngine.XR.XRSettings;
#elif UNITY_5_6_OR_NEWER
using UnityEngine.VR;
using XRSettings = UnityEngine.VR.VRSettings;
#endif

namespace UnityEngine.Experimental.Rendering
{
[Serializable]
public class XRGraphics
{ // XRGraphics insulates SRP from API changes across platforms, Editor versions, and as XR transitions into XR SDK

public enum StereoRenderingMode
{
MultiPass = 0,
SinglePass,
SinglePassInstanced,
SinglePassMultiView
};

public static float eyeTextureResolutionScale
{
get
{
if (!enabled)
return 1.0f;
else
return XRSettings.eyeTextureResolutionScale;
}
}

public static float renderViewportScale
{
get
{
if (!enabled)
return 1.0f;
else
return XRSettings.renderViewportScale;
}
}

#if UNITY_EDITOR
public static bool tryEnable
{ // TryEnable gets updated before "play" is pressed- we use this for updating GUI only.
get { return PlayerSettings.virtualRealitySupported; }
}
#endif

public static bool enabled
{ // SRP should use this to safely determine whether XR is enabled at runtime.
get
{
#if ENABLE_VR
return XRSettings.enabled;
#else
return false;
#endif
}
}

public static bool isDeviceActive
{
get
{
if (!enabled)
return false;
return XRSettings.isDeviceActive;
}
}

public static string loadedDeviceName
{
get
{
if (!enabled)
return "No XR device loaded";
return XRSettings.loadedDeviceName;
}
}

public static string[] supportedDevices
{
get
{
if (!enabled)
return new string[1];
return XRSettings.supportedDevices;
}
}

public static StereoRenderingMode stereoRenderingMode
{
get
{
if (!enabled)
return StereoRenderingMode.SinglePass;
#if UNITY_2018_3_OR_NEWER
return (StereoRenderingMode)XRSettings.stereoRenderingMode;
#else // Reverse engineer it
if (!enabled)
return StereoRenderingMode.SinglePassMultiView;
if (eyeTextureDesc.vrUsage == VRTextureUsage.TwoEyes)
{
if (eyeTextureDesc.dimension == UnityEngine.Rendering.TextureDimension.Tex2DArray)
return StereoRenderingMode.SinglePassInstanced;
return StereoRenderingMode.SinglePassDoubleWide;
}
else
return StereoRenderingMode.MultiPass;
#endif
}
}
public static uint GetPixelOffset(uint eye)
{
if (!enabled || stereoRenderingMode != StereoRenderingMode.SinglePass)
return 0;
return (uint)(Mathf.CeilToInt((eye * XRSettings.eyeTextureWidth) / 2));
}

public static RenderTextureDescriptor eyeTextureDesc
{
get
{
if (!enabled)
{
return new RenderTextureDescriptor(0, 0);
}

return XRSettings.eyeTextureDesc;
}
}

public static int eyeTextureWidth
{
get
{
if (!enabled)
{
return 0;
}

return XRSettings.eyeTextureWidth;
}
}
public static int eyeTextureHeight
{
get
{
if (!enabled)
{
return 0;
}

return XRSettings.eyeTextureHeight;
}
}

}
}
File renamed without changes.
Loading

0 comments on commit bfa51d6

Please sign in to comment.