浏览代码

HDRenderPipeline: Add support for camera features flags

/main
Sebastien Lagarde 7 年前
当前提交
32b1fe35
共有 6 个文件被更改,包括 95 次插入20 次删除
  1. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs
  2. 36
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
  3. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraUI.cs
  4. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/SerializedHDCamera.cs
  5. 24
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  6. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyRenderingContext.cs

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs


Unlit // Hard coded path
};
public enum ClearColorMode
{
Sky,
BackgroundColor,
None
};
public ClearColorMode clearColorMode = ClearColorMode.Sky;
[ColorUsage(true, true)]
public Color backgroundColorHDR = new Color(0.025f, 0.07f, 0.19f, 0.0f);
public bool clearDepth = true;
public RenderingPath renderingPath;
[Tooltip("Layer Mask used for the volume interpolation for this camera.")]
public LayerMask volumeLayerMask = -1;

36
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs


// happen, but you never know...
int m_LastFrameActive;
public bool clearDepth
{
get { return m_AdditionalCameraData != null ? m_AdditionalCameraData.clearDepth : camera.clearFlags != CameraClearFlags.Nothing; }
}
public HDAdditionalCameraData.ClearColorMode clearColorMode
{
get
{
if (m_AdditionalCameraData != null)
{
return m_AdditionalCameraData.clearColorMode;
}
if (camera.clearFlags == CameraClearFlags.Skybox)
return HDAdditionalCameraData.ClearColorMode.Sky;
else if (camera.clearFlags == CameraClearFlags.SolidColor)
return HDAdditionalCameraData.ClearColorMode.BackgroundColor;
else // None
return HDAdditionalCameraData.ClearColorMode.None;
}
}
public Color backgroundColorHDR
{
get
{
if (m_AdditionalCameraData != null)
{
return m_AdditionalCameraData.backgroundColorHDR;
}
return camera.backgroundColor.linear;
}
}
static Dictionary<Camera, HDCamera> s_Cameras = new Dictionary<Camera, HDCamera>();
static List<Camera> s_Cleanup = new List<Camera>(); // Recycled to reduce GC pressure

18
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraUI.cs


public static readonly CED.IDrawer[] Inspector = null;
public static readonly CED.IDrawer SectionPrimarySettings = CED.Group(
CED.Action(Drawer_FieldBackgroundColor),
CED.Action(Drawer_FieldClearColorMode),
CED.Action(Drawer_FieldBackgroundColorHDR),
CED.Action(Drawer_FieldClearDepth),
CED.Action(Drawer_FieldCullingMask),
CED.Action(Drawer_FieldVolumeLayerMask),
CED.space,

frameSettingsUI.Update();
}
static void Drawer_FieldBackgroundColor(HDCameraUI s, SerializedHDCamera p, Editor owner)
static void Drawer_FieldBackgroundColorHDR(HDCameraUI s, SerializedHDCamera p, Editor owner)
EditorGUILayout.PropertyField(p.backgroundColor, _.GetContent("Background Color|The Camera clears the screen to this color before rendering."));
EditorGUILayout.PropertyField(p.backgroundColorHDR, _.GetContent("Background Color|The BackgroundColor use to clear screen when selecting BackgrounColor before rendering."));
}
static void Drawer_FieldVolumeLayerMask(HDCameraUI s, SerializedHDCamera p, Editor owner)

EditorGUILayout.PropertyField(p.depth, _.GetContent("Depth"));
}
static void Drawer_FieldClearColorMode(HDCameraUI s, SerializedHDCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.clearColorMode, _.GetContent("Clear Mode|The Camera clears the screen to selected mode."));
}
}
static void Drawer_FieldClearDepth(HDCameraUI s, SerializedHDCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.clearDepth, _.GetContent("ClearDepth|The Camera clears the depth buffer before rendering."));
}
static void Drawer_FieldRenderTarget(HDCameraUI s, SerializedHDCamera p, Editor owner)

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/SerializedHDCamera.cs


public SerializedObject serializedObject;
public SerializedObject serializedAdditionalDataObject;
public SerializedProperty backgroundColor;
//public SerializedProperty backgroundColor;
public SerializedProperty normalizedViewPortRect;
public SerializedProperty fieldOfView;
public SerializedProperty orthographic;

public SerializedProperty targetDisplay;
#endif
public SerializedProperty clearColorMode;
public SerializedProperty backgroundColorHDR;
public SerializedProperty clearDepth;
public SerializedProperty volumeLayerMask;
public SerializedFrameSettings frameSettings;

hideFlags.intValue = (int)HideFlags.HideInInspector;
serializedAdditionalDataObject.ApplyModifiedProperties();
backgroundColor = serializedObject.FindProperty("m_BackGroundColor");
//backgroundColor = serializedObject.FindProperty("m_BackGroundColor");
normalizedViewPortRect = serializedObject.FindProperty("m_NormalizedViewPortRect");
nearClippingPlane = serializedObject.FindProperty("near clip plane");
farClippingPlane = serializedObject.FindProperty("far clip plane");

targetEye = serializedObject.FindProperty("m_TargetEye");
clearColorMode = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.clearColorMode);
backgroundColorHDR = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.backgroundColorHDR);
clearDepth = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.clearDepth);
volumeLayerMask = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.volumeLayerMask);
frameSettings = new SerializedFrameSettings(serializedAdditionalDataObject.FindProperty("m_FrameSettings"));
}

24
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


// Clear depth/stencil and init buffers
using (new ProfilingSample(cmd, "Clear Depth/Stencil", CustomSamplerId.ClearDepthStencil.GetSampler()))
{
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraColorBuffer, m_CameraDepthStencilBuffer, ClearFlag.Depth);
if (hdCamera.clearDepth)
{
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraColorBuffer, m_CameraDepthStencilBuffer, ClearFlag.Depth);
}
}
// Clear the HDR target
using (new ProfilingSample(cmd, "Clear HDR target", CustomSamplerId.ClearHDRTarget.GetSampler()))
{
if (hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.BackgroundColor ||
// If we want the sky but the sky don't exist, still clear with background color
(hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.Sky && !m_SkyManager.IsSkyValid()))
{
Color clearColor = hdCamera.backgroundColorHDR;
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraColorBuffer, m_CameraDepthStencilBuffer, ClearFlag.Color, clearColor);
}
}
// Clear the diffuse SSS lighting target

}
// TODO: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
// Clear the HDR target
using (new ProfilingSample(cmd, "Clear HDR target", CustomSamplerId.ClearHDRTarget.GetSampler()))
{
Color clearColor = hdCamera.camera.backgroundColor.linear; // Need it in linear because we clear a linear fp16 texture.
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraColorBuffer, m_CameraDepthStencilBuffer, ClearFlag.Color, clearColor);
}
// Clear GBuffers
if (!m_FrameSettings.enableForwardRenderingOnly)

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyRenderingContext.cs


return result;
}
public void RenderSky(SkyUpdateContext skyContext, HDCamera camera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, CommandBuffer cmd)
public void RenderSky(SkyUpdateContext skyContext, HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, CommandBuffer cmd)
if (skyContext.IsValid())
if (skyContext.IsValid() && hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.Sky)
m_BuiltinParameters.pixelCoordToViewDirMatrix = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(camera.camera.fieldOfView * Mathf.Deg2Rad, camera.screenSize, camera.viewMatrix, false);
m_BuiltinParameters.invViewProjMatrix = camera.viewProjMatrix.inverse;
m_BuiltinParameters.screenSize = camera.screenSize;
m_BuiltinParameters.cameraPosWS = camera.camera.transform.position;
m_BuiltinParameters.pixelCoordToViewDirMatrix = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(hdCamera.camera.fieldOfView * Mathf.Deg2Rad, hdCamera.screenSize, hdCamera.viewMatrix, false);
m_BuiltinParameters.invViewProjMatrix = hdCamera.viewProjMatrix.inverse;
m_BuiltinParameters.screenSize = hdCamera.screenSize;
m_BuiltinParameters.cameraPosWS = hdCamera.camera.transform.position;
m_BuiltinParameters.hdCamera = camera;
m_BuiltinParameters.hdCamera = hdCamera;
skyContext.renderer.SetRenderTargets(m_BuiltinParameters);
skyContext.renderer.RenderSky(m_BuiltinParameters, false);

正在加载...
取消
保存