浏览代码

Added XRGConfig struct which should be used as SRP's interface with XR

/main
Nerites 6 年前
当前提交
386f0a0d
共有 7 个文件被更改,包括 145 次插入8 次删除
  1. 8
      com.unity.render-pipelines.lightweight/LWRP/Data/LightweightPipelineAsset.cs
  2. 18
      com.unity.render-pipelines.lightweight/LWRP/Editor/LightweightPipelineAssetEditor.cs
  3. 8
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
  4. 3
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipelineCore.cs
  5. 105
      com.unity.render-pipelines.core/CoreRP/XR/XRGConfig.cs
  6. 11
      com.unity.render-pipelines.core/CoreRP/XR/XRGConfig.cs.meta

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


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

return null;
#endif
}
public int GetAssetVersion()
{
return k_AssetVersion;

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

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


public static string[] shadowCascadeOptions = {"No Cascades", "Two Cascades", "Four Cascades"};
public static string[] opaqueDownsamplingOptions = {"None", "2x (Bilinear)", "4x (Box)", "4x (Bilinear)"};
public static GUIContent XRConfig = new GUIContent("XR Graphics Settings", "SRP will attempt to set this configuration to the VRDevice.");
}
public static class StrippingStyles

SerializedProperty m_CustomShaderVariantStripSettingsProp;
SerializedProperty m_XRConfig;
public override void OnInspectorGUI()
{
serializedObject.Update();

DrawGeneralSettings();
DrawXRSettings();
}
void DrawXRSettings()
{
EditorGUILayout.PropertyField(m_XRConfig);
{
{
m_RenderScale = serializedObject.FindProperty("m_RenderScale");
m_MaxPixelLights = serializedObject.FindProperty("m_MaxPixelLights");
m_SupportsVertexLightProp = serializedObject.FindProperty("m_SupportsVertexLight");

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

{
EditorGUILayout.LabelField(Styles.generalSettingsLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(!XRGConfig.Enabled);
EditorGUI.EndDisabledGroup();
m_MaxPixelLights.intValue = EditorGUILayout.IntSlider(Styles.maxPixelLightsLabel, m_MaxPixelLights.intValue, 0, k_MaxSupportedPixelLights);
EditorGUILayout.Space();

if (directionalShadows || localShadows)
EditorGUILayout.PropertyField(m_SoftShadowsSupportedProp, Styles.supportsSoftShadows);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();

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


#endif
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.XR;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{

Debug.LogWarning("Nested camera rendering is forbidden. If you are calling camera.Render inside OnWillRenderObject callback, use BeginCameraRender callback instead.");
return;
}
pipelineAsset.XRGConfig.SetConfig();
base.Render(context, cameras);
BeginFrameRendering(cameras);

#if !UNITY_SWITCH
// 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 && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
if (cameraData.isStereoEnabled && pipelineAsset.XRGConfig.EyeTextureDesc.dimension == TextureDimension.Tex2DArray)
cameraData.msaaSamples = 1;
#endif

#if !UNITY_SWITCH
if (cameraData.isStereoEnabled)
{
cameraData.renderScale = XRSettings.eyeTextureResolutionScale;
cameraData.renderScale = pipelineAsset.XRGConfig.renderScale;
}
else
#endif

{
#if !UNITY_SWITCH
bool isSceneViewCamera = camera.cameraType == CameraType.SceneView;
return XRSettings.isDeviceActive && !isSceneViewCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
return XRGConfig.Enabled && !isSceneViewCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
#else
return false;
#endif

3
com.unity.render-pipelines.lightweight/LWRP/LightweightPipelineCore.cs


using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.XR;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{

if (pipelineAsset.keepSoftShadowVariants)
s_PipelineCapabilities |= PipelineCapabilities.SoftShadows;
}
}
}
public static void DrawFullScreen(CommandBuffer commandBuffer, Material material,
MaterialPropertyBlock properties = null, int shaderPassId = 0)

105
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
{
public void SetConfig()
{ // If XR is enabled, sets XRSettings from our saved config
if (!XRSettings.enabled)
return;
XRSettings.eyeTextureResolutionScale = renderScale;
XRSettings.renderViewportScale = viewportScale;
XRSettings.useOcclusionMesh = useOcclusionMesh;
XRSettings.occlusionMaskScale = occlusionMaskScale;
XRSettings.showDeviceView = showDeviceView;
XRSettings.gameViewRenderMode = gameViewRenderMode;
}
public float renderScale;
public float viewportScale;
public bool useOcclusionMesh;
public float occlusionMaskScale;
public bool showDeviceView;
public GameViewRenderMode gameViewRenderMode;
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 bool Enabled
{
get
{
return XRSettings.enabled;
}
}
public static StereoRenderingPath StereoRenderingMode
{
get
{
return (StereoRenderingPath)XRSettings.stereoRenderingMode;
}
}
public RenderTextureDescriptor EyeTextureDesc
{
get
{
return XRSettings.eyeTextureDesc;
}
}
}
[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 Settings");
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");
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();
}
}
}

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


fileFormatVersion: 2
guid: 5133c1dbdb17436449b17269e791cb3a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存