浏览代码

Renamed XRGConfig to adhere to coding style standards. Added a way to

update UI before hitting Play.
/main
Nerites 7 年前
当前提交
d1f4f8d3
共有 7 个文件被更改,包括 156 次插入163 次删除
  1. 16
      com.unity.render-pipelines.lightweight/LWRP/Data/LightweightPipelineAsset.cs
  2. 6
      com.unity.render-pipelines.lightweight/LWRP/Editor/LightweightPipelineAssetEditor.cs
  3. 2
      com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs
  4. 8
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
  5. 143
      com.unity.render-pipelines.core/CoreRP/XR/XRGraphicsConfig.cs
  6. 144
      com.unity.render-pipelines.core/CoreRP/XR/XRGConfig.cs
  7. 0
      /com.unity.render-pipelines.core/CoreRP/XR/XRGraphicsConfig.cs.meta

16
com.unity.render-pipelines.lightweight/LWRP/Data/LightweightPipelineAsset.cs


[SerializeField] bool m_KeepSoftShadowVariants = true;
[SerializeField] LightweightPipelineResources m_ResourcesAsset;
[SerializeField] XRGConfig m_savedXRConfig = XRGConfig.defaultXRConfig;
[SerializeField] XRGraphicsConfig m_SavedXRConfig = XRGraphicsConfig.s_DefaultXRConfig;
// Deprecated
[SerializeField] ShadowType m_ShadowType = ShadowType.HARD_SHADOWS;

public float renderScale
{
get
{
return m_RenderScale;
}
set
{
m_RenderScale = value;
}
get { return m_RenderScale; }
set { m_RenderScale = value; }
}
public bool supportsDynamicBatching

get { return resources != null ? resources.SamplingShader : null; }
}
public XRGConfig XRGConfig
public XRGraphicsConfig savedXRGraphicsConfig
get { return m_savedXRConfig; }
get { return m_SavedXRConfig; }
}
public void OnBeforeSerialize()

6
com.unity.render-pipelines.lightweight/LWRP/Editor/LightweightPipelineAssetEditor.cs


m_ShowSoftParticles.value = m_RequireSoftParticlesProp.boolValue;
m_ShowOpaqueTextureScale.valueChanged.AddListener(Repaint);
m_ShowOpaqueTextureScale.value = m_RequireOpaqueTextureProp.boolValue;
m_XRConfig = serializedObject.FindProperty("m_savedXRConfig");
m_XRConfig = serializedObject.FindProperty("m_SavedXRConfig");
}

{
EditorGUILayout.LabelField(Styles.generalSettingsLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(XRGConfig.Enabled);
EditorGUI.BeginDisabledGroup(XRGraphicsConfig.tryEnable); // Begin XR-overridden values
EditorGUI.EndDisabledGroup();
EditorGUI.EndDisabledGroup(); // End XR-overridden values
m_MaxPixelLights.intValue = EditorGUILayout.IntSlider(Styles.maxPixelLightsLabel, m_MaxPixelLights.intValue, 0, k_MaxSupportedPixelLights);
EditorGUILayout.Space();

2
com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs


if (cameraData.isStereoEnabled)
{
return XRGConfig.EyeTextureDesc;
return XRGraphicsConfig.eyeTextureDesc;
}
else
{

8
com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs


return;
}
// Apply any changes to XRGConfig prior to this point
pipelineAsset.XRGConfig.SetConfig();
pipelineAsset.savedXRGraphicsConfig.SetConfig();
base.Render(context, cameras);
BeginFrameRendering(cameras);

// TODO: There's currently an issue in engine side that breaks MSAA with texture2DArray.
// for now we force msaa disabled when using texture2DArray. This fixes VR multiple and single pass instanced modes.
if (cameraData.isStereoEnabled && XRGConfig.EyeTextureDesc.dimension == TextureDimension.Tex2DArray)
if (cameraData.isStereoEnabled && XRGraphicsConfig.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
cameraData.msaaSamples = 1;
cameraData.isHdrEnabled = camera.allowHDR && pipelineAsset.supportsHDR;

// If XR is enabled, use XR renderScale.
// Discard variations lesser than kRenderScaleThreshold.
// Scale is only enabled for gameview.
float usedRenderScale = XRGConfig.Enabled ? pipelineAsset.XRGConfig.renderScale : pipelineAsset.renderScale;
float usedRenderScale = XRGraphicsConfig.enabled ? pipelineAsset.savedXRGraphicsConfig.renderScale : pipelineAsset.renderScale;
cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale;
cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f;

bool IsStereoEnabled(Camera camera)
{
bool isSceneViewCamera = camera.cameraType == CameraType.SceneView;
return XRGConfig.Enabled && !isSceneViewCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
return XRGraphicsConfig.enabled && !isSceneViewCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
}
}
}

143
com.unity.render-pipelines.core/CoreRP/XR/XRGraphicsConfig.cs


using System;
using UnityEditor;
using UnityEngine.XR;
using UnityEngine.Assertions;
namespace UnityEngine.Experimental.Rendering
{
[Serializable]
public struct XRGraphicsConfig
{ // XRGConfig stores the desired XR settings for a given SRP asset.
public float renderScale;
public float viewportScale;
public bool useOcclusionMesh;
public float occlusionMaskScale;
public bool showDeviceView;
public GameViewRenderMode gameViewRenderMode;
public void SetConfig()
{ // If XR is enabled, sets XRSettings from our saved config
if (!enabled)
Assert.IsFalse(enabled);
XRSettings.eyeTextureResolutionScale = renderScale;
XRSettings.renderViewportScale = viewportScale;
XRSettings.useOcclusionMesh = useOcclusionMesh;
XRSettings.occlusionMaskScale = occlusionMaskScale;
XRSettings.showDeviceView = showDeviceView;
XRSettings.gameViewRenderMode = gameViewRenderMode;
}
public void SetViewportScale(float viewportScale)
{ // Only sets viewport- since this is probably the only thing getting updated every frame
if (!enabled)
Assert.IsFalse(enabled);
XRSettings.renderViewportScale = viewportScale;
}
public static readonly XRGraphicsConfig s_DefaultXRConfig = new XRGraphicsConfig
{
renderScale = 1.0f,
viewportScale = 1.0f,
useOcclusionMesh = true,
occlusionMaskScale = 1.0f,
showDeviceView = true,
gameViewRenderMode = GameViewRenderMode.BothEyes
};
public static XRGraphicsConfig GetActualXRSettings()
{
XRGraphicsConfig getXRSettings = new XRGraphicsConfig();
if (!enabled)
Assert.IsFalse(enabled);
getXRSettings.renderScale = XRSettings.eyeTextureResolutionScale;
getXRSettings.viewportScale = XRSettings.renderViewportScale;
getXRSettings.useOcclusionMesh = XRSettings.useOcclusionMesh;
getXRSettings.occlusionMaskScale = XRSettings.occlusionMaskScale;
getXRSettings.showDeviceView = XRSettings.showDeviceView;
getXRSettings.gameViewRenderMode = XRSettings.gameViewRenderMode;
return getXRSettings;
}
public static bool tryEnable
{ // TryEnable gets updated before "play" is pressed- we use this for updating GUI.
get { return PlayerSettings.virtualRealitySupported; }
}
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 RenderTextureDescriptor eyeTextureDesc
{
get
{
if (!enabled)
Assert.IsFalse(enabled);
return XRSettings.eyeTextureDesc;
}
}
public static string[] supportedDevices
{
get
{
if (!enabled)
Assert.IsFalse(enabled);
return XRSettings.supportedDevices;
}
}
}
[CustomPropertyDrawer(typeof(XRGraphicsConfig))]
public class XRGraphicsConfigDrawer : PropertyDrawer
{
private float k_MinRenderScale = 0.01f;
private float k_MaxRenderScale = 4.0f;
internal class Styles
{
public static GUIContent XRSettingsLabel = new GUIContent("XR Config", "Enable XR in Player Settings. Then SetConfig can be used to set this configuration to XRSettings.");
public static GUIContent XREnabledLabel = new GUIContent("Enable XR", "Enables stereo rendering");
public static GUIContent renderScaleLabel = new GUIContent("Render Scale", "Scales (and reallocates) the camera render target allowing the game to render at a resolution different than native resolution. Can't be modified in play mode.");
public static GUIContent viewportScaleLabel = new GUIContent("Viewport Scale", "Scales the section of the render target being rendered. Use for dynamic resolution adjustments.");
public static GUIContent stereoRenderModeLabel = new GUIContent("Stereo Rendering Mode", "Use Player Settings to select between supported stereo rendering paths for current VR device.");
public static GUIContent showDeviceViewLabel = new GUIContent("Show Device View", "If possible, mirror the render target of the VR device to the main display.");
public static GUIContent gameViewRenderModeLabel = new GUIContent("Game View Render Mode", "Select how to reflect stereo display to game view");
public static GUIContent useOcclusionMeshLabel = new GUIContent("Use Occlusion Mesh", "Determines whether or not to draw the occlusion mesh (goggles-shaped overlay) when rendering");
public static GUIContent occlusionScaleLabel = new GUIContent("Occlusion Mesh Scale", "Scales the occlusion mesh");
}
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var drawRenderScale = property.FindPropertyRelative("renderScale");
var drawViewportScale = property.FindPropertyRelative("viewportScale");
var drawShowDeviceView = property.FindPropertyRelative("showDeviceView");
var drawGameViewRenderMode = property.FindPropertyRelative("gameViewRenderMode");
var drawUseOcclusionMesh = property.FindPropertyRelative("useOcclusionMesh");
var drawOcclusionMaskScale = property.FindPropertyRelative("occlusionMaskScale");
EditorGUI.BeginDisabledGroup(!XRGraphicsConfig.tryEnable);
EditorGUILayout.LabelField(Styles.XRSettingsLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
drawRenderScale.floatValue = EditorGUILayout.Slider(Styles.renderScaleLabel, drawRenderScale.floatValue, k_MinRenderScale, k_MaxRenderScale);
drawViewportScale.floatValue = EditorGUILayout.Slider(Styles.viewportScaleLabel, drawViewportScale.floatValue, k_MinRenderScale, k_MaxRenderScale);
EditorGUILayout.PropertyField(drawUseOcclusionMesh, Styles.useOcclusionMeshLabel);
EditorGUILayout.PropertyField(drawOcclusionMaskScale, Styles.occlusionScaleLabel);
EditorGUILayout.PropertyField(drawShowDeviceView, Styles.showDeviceViewLabel);
EditorGUILayout.PropertyField(drawGameViewRenderMode, Styles.gameViewRenderModeLabel);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUI.EndDisabledGroup();
}
}
}

144
com.unity.render-pipelines.core/CoreRP/XR/XRGConfig.cs


using UnityEngine.XR;
#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
#endif
namespace UnityEngine.Experimental.Rendering
{
[Serializable]
public struct XRGConfig
{ // XRGConfig stores the desired XR settings for a given SRP asset.
public float renderScale;
public float viewportScale;
public bool useOcclusionMesh;
public float occlusionMaskScale;
public bool showDeviceView;
public GameViewRenderMode gameViewRenderMode;
public void SetConfig()
{ // If XR is enabled, sets XRSettings from our saved config
if (!Enabled)
return;
XRSettings.eyeTextureResolutionScale = renderScale;
XRSettings.renderViewportScale = viewportScale;
XRSettings.useOcclusionMesh = useOcclusionMesh;
XRSettings.occlusionMaskScale = occlusionMaskScale;
XRSettings.showDeviceView = showDeviceView;
XRSettings.gameViewRenderMode = gameViewRenderMode;
}
public void SetViewportScale(float viewportScale)
{ // Only sets viewport- since this is probably the only thing getting updated every frame
if (!Enabled)
return;
XRSettings.renderViewportScale = viewportScale;
}
public static readonly XRGConfig defaultXRConfig = new XRGConfig
{
renderScale = 1.0f,
viewportScale = 1.0f,
useOcclusionMesh = true,
occlusionMaskScale = 1.0f,
showDeviceView = true,
gameViewRenderMode = GameViewRenderMode.BothEyes
};
public static XRGConfig ActualXRSettings()
{
XRGConfig getXRSettings = new XRGConfig();
// Just to make it obvious if getting XR settings failed
getXRSettings.renderScale = 0.0f;
getXRSettings.viewportScale = 0.0f;
if (Enabled)
{
getXRSettings.renderScale = XRSettings.eyeTextureResolutionScale;
getXRSettings.viewportScale = XRSettings.renderViewportScale;
getXRSettings.useOcclusionMesh = XRSettings.useOcclusionMesh;
getXRSettings.occlusionMaskScale = XRSettings.occlusionMaskScale;
getXRSettings.showDeviceView = XRSettings.showDeviceView;
getXRSettings.gameViewRenderMode = XRSettings.gameViewRenderMode;
}
return getXRSettings;
}
public static bool Enabled
{ // SRP should use this to safely determine whether XR is enabled
get
{
#if ENABLE_VR
return XRSettings.enabled;
#else
return false;
#endif
}
}
public static RenderTextureDescriptor EyeTextureDesc
{
get
{
if (Enabled)
return XRSettings.eyeTextureDesc;
return new RenderTextureDescriptor(1, 1); // Should be easy to tell if this failed
}
}
public static string[] SupportedDevices
{
get
{
if (Enabled)
return XRSettings.supportedDevices;
string[] empty = {"XR disabled"};
return empty;
}
}
}
[CustomPropertyDrawer(typeof(XRGConfig))]
public class XRGConfigDrawer : PropertyDrawer
{
private float k_MinRenderScale = 0.01f;
private float k_MaxRenderScale = 4.0f;
internal class Styles
{
public static GUIContent XRSettingsLabel = new GUIContent("XR Config", "Enable XR in Player Settings. Then SetConfig can be used to set this configuration to XRSettings.");
public static GUIContent XREnabledLabel = new GUIContent("Enable XR", "Enables stereo rendering");
public static GUIContent renderScaleLabel = new GUIContent("Render Scale", "Scales (and reallocates) the camera render target allowing the game to render at a resolution different than native resolution. UI is always rendered at native resolution.");
public static GUIContent viewportScaleLabel = new GUIContent("Viewport Scale", "Scales the section of the render target being rendered. Use for dynamic resolution adjustments.");
public static GUIContent stereoRenderModeLabel = new GUIContent("Stereo Rendering Mode", "Use Player Settings to select between supported stereo rendering paths for current VR device.");
public static GUIContent showDeviceViewLabel = new GUIContent("Show Device View", "If possible, mirror the render target of the VR device to the main display.");
public static GUIContent gameViewRenderModeLabel = new GUIContent("Game View Render Mode", "Select how to reflect stereo display to game view");
public static GUIContent useOcclusionMeshLabel = new GUIContent("Use Occlusion Mesh", "Determines whether or not to draw the occlusion mesh (goggles-shaped overlay) when rendering");
public static GUIContent occlusionScaleLabel = new GUIContent("Occlusion Mesh Scale", "Scales the occlusion mesh");
}
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var m_RenderScale = property.FindPropertyRelative("renderScale");
var m_ViewportScale = property.FindPropertyRelative("viewportScale");
var m_ShowDeviceView = property.FindPropertyRelative("showDeviceView");
var m_GameViewRenderMode = property.FindPropertyRelative("gameViewRenderMode");
var m_UseOcclusionMesh = property.FindPropertyRelative("useOcclusionMesh");
var m_OcclusionMaskScale = property.FindPropertyRelative("occlusionMaskScale");
EditorGUI.BeginDisabledGroup(!XRGConfig.Enabled);
EditorGUILayout.LabelField(Styles.XRSettingsLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_RenderScale.floatValue = EditorGUILayout.Slider(Styles.renderScaleLabel, m_RenderScale.floatValue, k_MinRenderScale, k_MaxRenderScale);
m_ViewportScale.floatValue = EditorGUILayout.Slider(Styles.viewportScaleLabel, m_ViewportScale.floatValue, k_MinRenderScale, k_MaxRenderScale);
EditorGUILayout.PropertyField(m_UseOcclusionMesh, Styles.useOcclusionMeshLabel);
EditorGUILayout.PropertyField(m_OcclusionMaskScale, Styles.occlusionScaleLabel);
EditorGUILayout.PropertyField(m_ShowDeviceView, Styles.showDeviceViewLabel);
EditorGUILayout.PropertyField(m_GameViewRenderMode, Styles.gameViewRenderModeLabel);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUI.EndDisabledGroup();
}
}
}

/com.unity.render-pipelines.core/CoreRP/XR/XRGConfig.cs.meta → /com.unity.render-pipelines.core/CoreRP/XR/XRGraphicsConfig.cs.meta

正在加载...
取消
保存