浏览代码

Fixed integration of XRGConfig into LWRP

/main
Nerites 6 年前
当前提交
4f7a3f70
共有 6 个文件被更改,包括 86 次插入139 次删除
  1. 81
      com.unity.render-pipelines.core/CoreRP/XR/XRGConfig.cs
  2. 48
      com.unity.render-pipelines.lightweight/LWRP/Data/LightweightPipelineAsset.cs
  3. 38
      com.unity.render-pipelines.lightweight/LWRP/Editor/LightweightPipelineAssetEditor.cs
  4. 11
      com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs
  5. 45
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
  6. 2
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipelineCore.cs

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


{
[Serializable]
public struct XRGConfig
{
{ // XRGConfig stores the desired XR settings for a given SRP asset.
if (!XRSettings.enabled)
if (!Enabled)
return;
XRSettings.eyeTextureResolutionScale = renderScale;
XRSettings.renderViewportScale = viewportScale;

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;
}
{
{ // SRP should use this to safely determine whether XR is enabled
#if !UNITY_SWITCH // FIXME find the right way of safely checking if XR is supported
#else
return false;
#endif
public static StereoRenderingPath StereoRenderingMode
public static RenderTextureDescriptor EyeTextureDesc
return (StereoRenderingPath)XRSettings.stereoRenderingMode;
if (Enabled)
return XRSettings.eyeTextureDesc;
return new RenderTextureDescriptor(1, 1); // Should be easy to tell if this failed
public RenderTextureDescriptor EyeTextureDesc
public static string[] SupportedDevices
return XRSettings.eyeTextureDesc;
if (Enabled)
return XRSettings.supportedDevices;
string[] empty = {"XR disabled"};
return empty;
}
}
}

// 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();
if (XRGConfig.Enabled)
{
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();
}
}
}
}

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


[SerializeField] Downsampling m_OpaqueDownsampling = Downsampling._2xBilinear;
[SerializeField] bool m_SupportsHDR = false;
[SerializeField] MSAAQuality m_MSAA = MSAAQuality._4x;
[SerializeField] float m_TargetScale = 1.0f;
[SerializeField] float m_ViewportScale = 1.0f;
[SerializeField] float m_RenderScale = 1.0f;
[SerializeField] bool m_SupportsDynamicBatching = true;
[SerializeField] bool m_DirectionalShadowsSupported = true;

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

set { m_MSAA = (MSAAQuality)value; }
}
public float TargetScale
public float renderScale
get // FIXME race conditions?
get
//if (m_XREnabled)
// m_TargetScale = UnityEngine.XR.XRSettings.eyeTextureResolutionScale;
return m_TargetScale;
return m_RenderScale;
if (m_XREnabled)
UnityEngine.XR.XRSettings.eyeTextureResolutionScale = value;
m_TargetScale = value;
}
}
public float ViewportScale
{
get // FIXME race conditions?
{
//if (m_XREnabled)
// m_ViewportScale = UnityEngine.XR.XRSettings.renderViewportScale;
return m_ViewportScale;
}
set
{
if (m_XREnabled)
UnityEngine.XR.XRSettings.renderViewportScale = value;
m_ViewportScale = value;
}
}
public bool XREnabled
{
get
{
return m_XREnabled;
}
set
{
UnityEngine.XR.XRSettings.enabled = value;
m_XREnabled = value;
m_RenderScale = value;
}
}

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


public static GUIContent localShadowLabel = new GUIContent("Local Shadows");
public static GUIContent capabilitiesLabel = new GUIContent("Capabilities");
public static GUIContent TargetScaleLabel = new GUIContent("Target Scale", "Scales the camera render target allowing the game to render at a resolution different than native resolution. UI is always rendered at native resolution. When in VR mode, analogous to XRSettings.eyeTextureResolutionScale.");
public static GUIContent ViewportScaleLabel = new GUIContent("Viewport Scale", "Scales the camera render viewport without resizing camera render target. When in VR mode, analogous to XRSettings.renderViewportScale.");
public static GUIContent renderScaleLabel = new GUIContent("Target Scale", "Scales the camera render target allowing the game to render at a resolution different than native resolution. UI is always rendered at native resolution. When in VR mode, uses value set in XRGraphicsConfig instead.");
public static GUIContent maxPixelLightsLabel = new GUIContent("Pixel Lights",
"Controls the amount of pixel lights that run in fragment light loop. Lights are sorted and culled per-object.");

AnimBool m_ShowXREnabled = new AnimBool();
int k_MaxSupportedPixelLights = 8;
float k_MinTargetScale = 0.1f;
float k_MaxTargetScale = 4.0f;
float k_MinViewportScale = 0.1f;
float k_MaxViewportScale = 1.0f;
SerializedProperty m_TargetScale;
SerializedProperty m_ViewportScale;
float k_MinRenderScale = 0.1f;
float k_MaxRenderScale = 4.0f;
SerializedProperty m_RenderScale;
SerializedProperty m_MaxPixelLights;
SerializedProperty m_SupportsVertexLightProp;
SerializedProperty m_RequireDepthTextureProp;

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

m_HDR = serializedObject.FindProperty("m_SupportsHDR");
m_MSAA = serializedObject.FindProperty("m_MSAA");
m_SupportsDynamicBatching = serializedObject.FindProperty("m_SupportsDynamicBatching");
m_XREnabledProp = serializedObject.FindProperty("m_XREnabled");
m_DirectionalShadowsSupportedProp = serializedObject.FindProperty("m_DirectionalShadowsSupported");
m_ShadowDistanceProp = serializedObject.FindProperty("m_ShadowDistance");
m_DirectionalShadowAtlasResolutionProp = serializedObject.FindProperty("m_ShadowAtlasResolution");

{
m_ShowSoftParticles.target = m_RequireDepthTextureProp.boolValue;
m_ShowOpaqueTextureScale.target = m_RequireOpaqueTextureProp.boolValue;
m_ShowXREnabled.target = UnityEngine.XR.XRSettings.enabled;
}
void DrawGeneralSettings()

EditorGUILayout.Space();
EditorGUILayout.Space();
}
void DrawXRSettings()
{
EditorGUILayout.LabelField(Styles.xrSettingsLabel, EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_XREnabledProp, Styles.xrEnabled);
EditorGUI.BeginDisabledGroup(m_ShowXREnabled.value);
EditorGUI.indentLevel++;
EditorGUI.indentLevel--;
EditorGUI.EndDisabledGroup();
}
}
}
}

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


{
Camera camera = cameraData.camera;
RenderTextureDescriptor desc;
float renderScale = cameraData.targetScale;
#if !UNITY_SWITCH
float renderScale = cameraData.renderScale;
XRSettings.eyeTextureResolutionScale = renderScale;
return XRSettings.eyeTextureDesc; // FIXME Any adjustments needed before using eyeTextureDesc?
return XRGConfig.EyeTextureDesc;
#endif
{
desc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
}

if (cameraData.isOffscreenRender)
return false;
bool isScaledRender = !Mathf.Approximately(cameraData.targetScale, 1.0f);
bool isScaledRender = !Mathf.Approximately(cameraData.renderScale, 1.0f);
bool isTargetTexture2DArray = baseDescriptor.dimension == TextureDimension.Tex2DArray;
return requiresCameraDepth || cameraData.isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
cameraData.postProcessEnabled || cameraData.requiresOpaqueTexture || isTargetTexture2DArray || !cameraData.isDefaultViewport;

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


Debug.LogWarning("Nested camera rendering is forbidden. If you are calling camera.Render inside OnWillRenderObject callback, use BeginCameraRender callback instead.");
return;
}
// Apply any changes to XRGConfig prior to this point
pipelineAsset.XRGConfig.SetConfig();
base.Render(context, cameras);

void InitializeCameraData(Camera camera, out CameraData cameraData)
{
const float kTargetScaleThreshold = 0.05f;
const float kRenderScaleThreshold = 0.05f;
cameraData.camera = camera;
bool msaaEnabled = camera.allowMSAA && pipelineAsset.msaaSampleCount > 1;

cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView;
cameraData.isOffscreenRender = camera.targetTexture != null && !cameraData.isSceneViewCamera;
cameraData.isStereoEnabled = IsStereoEnabled(camera);
#if !UNITY_SWITCH
if (cameraData.isStereoEnabled && pipelineAsset.XRGConfig.EyeTextureDesc.dimension == TextureDimension.Tex2DArray)
if (cameraData.isStereoEnabled && XRGConfig.EyeTextureDesc.dimension == TextureDimension.Tex2DArray)
#endif
cameraData.isHdrEnabled = camera.allowHDR && pipelineAsset.supportsHDR;

cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f ||
Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f));
// If XR is enabled, use XR renderScale.
// Scale is only enabled for gameview
cameraData.targetScale = (Mathf.Abs(1.0f - pipelineAsset.TargetScale) < kTargetScaleThreshold) ? 1.0f : pipelineAsset.TargetScale;
cameraData.targetScale = (camera.cameraType == CameraType.Game) ? cameraData.targetScale : 1.0f;
if (camera.cameraType == CameraType.Game)
{
#if !UNITY_SWITCH
if (cameraData.isStereoEnabled)
{
cameraData.renderScale = pipelineAsset.XRGConfig.renderScale;
}
else
#endif
{
cameraData.renderScale = pipelineAsset.renderScale;
}
}
else
{
cameraData.renderScale = 1.0f;
}
cameraData.renderScale = (Mathf.Abs(1.0f - cameraData.renderScale) < kRenderScaleThreshold) ? 1.0f : cameraData.renderScale;
// Scale is only enabled for gameview.
float usedRenderScale = XRGConfig.Enabled ? pipelineAsset.XRGConfig.renderScale : pipelineAsset.renderScale;
cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale;
cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f;
cameraData.requiresDepthTexture = pipelineAsset.supportsCameraDepthTexture || cameraData.isSceneViewCamera;
cameraData.requiresSoftParticles = pipelineAsset.supportsSoftParticles;

void SetupPerCameraShaderConstants(CameraData cameraData)
{
float cameraWidth = (float)cameraData.camera.pixelWidth * cameraData.targetScale;
float cameraHeight = (float)cameraData.camera.pixelHeight * cameraData.targetScale;
float cameraWidth = (float)cameraData.camera.pixelWidth * cameraData.renderScale;
float cameraHeight = (float)cameraData.camera.pixelHeight * cameraData.renderScale;
#if !UNITY_SWITCH
#else
return false;
#endif
}
}
}

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


public struct CameraData
{
public Camera camera;
public float targetScale;
public float renderScale;
public int msaaSamples;
public bool isSceneViewCamera;
public bool isDefaultViewport;

正在加载...
取消
保存