浏览代码

[HDCameraEditor] Properly instantiate ColorTarget for preview camera

/main
Frédéric Vauchelles 7 年前
当前提交
7f9cfba3
共有 4 个文件被更改,包括 35 次插入31 次删除
  1. 15
      ScriptableRenderPipeline/Core/CoreRP/CoreUtils.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.Data.cs
  3. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.Handlers.cs
  4. 35
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.cs

15
ScriptableRenderPipeline/Core/CoreRP/CoreUtils.cs


using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Rendering;

}
public static void CreateCmdTemporaryRT(CommandBuffer cmd, int nameID, RenderTextureDescriptor baseDesc,
int depthBufferBits, FilterMode filter, RenderTextureFormat format,
RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int msaaSamples = 1, bool enableRandomWrite = false)
int depthBufferBits, FilterMode filter, RenderTextureFormat format,
RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int msaaSamples = 1, bool enableRandomWrite = false)
{
UpdateRenderTextureDescriptor(ref baseDesc, depthBufferBits, format, readWrite, msaaSamples, enableRandomWrite);
cmd.GetTemporaryRT(nameID, baseDesc, filter);
}
public static void UpdateRenderTextureDescriptor(ref RenderTextureDescriptor baseDesc, int depthBufferBits, RenderTextureFormat format, RenderTextureReadWrite readWrite, int msaaSamples, bool enableRandomWrite)
{
baseDesc.depthBufferBits = depthBufferBits;
baseDesc.colorFormat = format;

cmd.GetTemporaryRT(nameID, baseDesc, filter);
}
public static void ClearCubemap(CommandBuffer cmd, RenderTargetIdentifier buffer, Color clearColor)

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.Data.cs


// SRP settings are available only if the rendering path is not the Default one (configured by the SRP asset)
var renderingPath = (HDAdditionalCameraData.RenderingPath)m_SerializedHdCamera.renderingPath.intValue;
isSectionExpandedRenderLoopSettings.target = renderingPath != HDAdditionalCameraData.RenderingPath.Default;
isSectionExpandedRenderLoopSettings.target = renderingPath == HDAdditionalCameraData.RenderingPath.Custom;
}
}
}

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.Handlers.cs


using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering.PostProcessing;
using Object = UnityEngine.Object;
namespace UnityEditor.Experimental.Rendering

Handles.color = orgHandlesColor;
}
RenderTexture GetPreviewTextureWithSize(int width, int height)
{
if (m_PreviewTexture == null || m_PreviewTexture.width != width || m_PreviewTexture.height != height)
{
if (m_PreviewTexture != null)
m_PreviewTexture.Release();
m_PreviewTexture = new RenderTexture(width, height, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Linear);
}
return m_PreviewTexture;
}
public void OnOverlayGUI(Object target, SceneView sceneView)
{
if (target == null) return;

m_PreviewCamera.CopyFrom(c);
var previewTexture = GetPreviewTextureWithSize((int)cameraRect.width, (int)cameraRect.height);
previewTexture.antiAliasing = QualitySettings.antiAliasing;
m_PreviewCamera.targetTexture = previewTexture;
m_PreviewCamera.pixelRect = new Rect(0, 0, cameraRect.width, cameraRect.height);

35
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDCameraEditor.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
[CustomEditorForRenderPipeline(typeof(Camera), typeof(HDRenderPipelineAsset))]
//[CustomEditorForRenderPipeline(typeof(Camera), typeof(HDRenderPipelineAsset))]
[CanEditMultipleObjects]
partial class HDCameraEditor : Editor
{

Camera m_PreviewCamera;
HDAdditionalCameraData m_PreviewAdditionalCameraData;
PostProcessLayer m_PreviewPostProcessLayer;
HDCamera m_PreviewHDCamera;
void OnEnable()
{

m_PreviewAdditionalCameraData = m_PreviewCamera.gameObject.AddComponent<HDAdditionalCameraData>();
m_PreviewPostProcessLayer = m_PreviewCamera.gameObject.AddComponent<PostProcessLayer>();
m_PreviewCamera.enabled = false;
m_PreviewHDCamera = new HDCamera(m_PreviewCamera);
m_PreviewHDCamera.Update(m_PreviewPostProcessLayer, m_PreviewAdditionalCameraData.GetFrameSettings());
}
void OnDisable()

void SynchronizePreviewCameraWithCamera(Camera c)
{
EditorUtility.CopySerialized(c, m_PreviewCamera);
var layer = c.GetComponent<PostProcessLayer>();
if (layer != null)
var layer = c.GetComponent<PostProcessLayer>() ?? Assets.ScriptableRenderLoop.PostProcessing.PostProcessing.Runtime.Utils.ComponentSingleton<PostProcessLayer>.instance;
EditorUtility.CopySerialized(layer, m_PreviewPostProcessLayer);
m_PreviewCamera.cameraType = CameraType.SceneView;
m_PreviewHDCamera.Update(m_PreviewPostProcessLayer, m_PreviewAdditionalCameraData.GetFrameSettings());
}
RenderTexture GetPreviewTextureWithSize(int width, int height)
{
if (m_PreviewTexture == null || m_PreviewTexture.width != width || m_PreviewTexture.height != height)
if (m_PreviewPostProcessLayer == null)
m_PreviewPostProcessLayer = c.gameObject.AddComponent<PostProcessLayer>();
EditorUtility.CopySerialized(layer, m_PreviewPostProcessLayer);
if (m_PreviewTexture != null)
m_PreviewTexture.Release();
var baseDesc = m_PreviewHDCamera.renderTextureDesc;
baseDesc.width = width;
baseDesc.height = height;
CoreUtils.UpdateRenderTextureDescriptor(ref baseDesc, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true);
m_PreviewTexture = new RenderTexture(baseDesc);
else if (m_PreviewPostProcessLayer != null)
{
DestroyImmediate(m_PreviewPostProcessLayer);
m_PreviewPostProcessLayer = null;
}
return m_PreviewTexture;
}
}
}
正在加载...
取消
保存