浏览代码

[PlanarReflection] (wip) render execution for planar reflection

/main
Frédéric Vauchelles 7 年前
当前提交
79d8e824
共有 4 个文件被更改,包括 132 次插入33 次删除
  1. 28
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs
  2. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystem.cs
  3. 105
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs
  4. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemParameters.cs

28
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs


[SerializeField]
Texture m_CustomTexture;
[SerializeField]
Texture m_BakedTexture;
[SerializeField]
RenderTexture m_RealtimeTexture;
[SerializeField]
public Texture texture { get; private set; }
public Texture texture
{
get
{
switch (m_Mode)
{
default:
case ReflectionProbeMode.Baked:
return bakedTexture;
case ReflectionProbeMode.Custom:
return customTexture;
case ReflectionProbeMode.Realtime:
return realtimeTexture;
}
}
}
public Bounds bounds { get { return m_InfluenceVolume.GetBoundsAt(transform); } }
public Vector3 captureLocalPosition { get { return m_CaptureLocalPosition; } set { m_CaptureLocalPosition = value; } }
public float dimmer { get { return m_Dimmer; } }

}
public Vector3 influencePosition { get { return transform.position; } }
public Texture customTexture { get { return m_CustomTexture; } }
public Texture bakedTexture { get { return m_BakedTexture; } }
public RenderTexture realtimeTexture { get { return m_RealtimeTexture; } internal set { m_RealtimeTexture = value; } }
public ReflectionProbeRefreshMode refreshMode { get { return m_RefreshMode; } }
public FrameSettings frameSettings { get { return m_FrameSettings; } }

public bool infiniteProjection { get { return m_ProxyVolumeReference != null && m_ProxyVolumeReference.projectionVolume.infiniteProjection; } }
#endregion
public void SetBakeDirty()
public void RequestRealtimeRender()
ReflectionSystem.RequestRender(this);
ReflectionSystem.RequestRealtimeRender(this);
}
void OnEnable()

26
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystem.cs


using UnityEngine.Experimental.Rendering.HDPipeline.Internal;
using UnityEngine.Rendering.PostProcessing;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

static Camera s_RenderCamera = null;
static HDAdditionalCameraData s_RenderCameraData;
public static void SetParameters(ReflectionSystemParameters parameters)
{

s_Instance.Cull(camera, results);
}
public static void RequestRender(PlanarReflectionProbe probe)
public static void RequestRealtimeRender(PlanarReflectionProbe probe)
s_Instance.RequestRender(probe);
s_Instance.RequestRealtimeRender(probe);
public static void Render(PlanarReflectionProbe probe, RenderTexture target)
public static void RenderAllRealtimeProbes()
var renderCamera = GetRenderCamera(probe);
renderCamera.targetTexture = target;
s_Instance.RenderAllRealtimeProbes();
static Camera GetRenderCamera(PlanarReflectionProbe probe)
public static void Render(PlanarReflectionProbe probe, RenderTexture target)
if (s_RenderCamera == null)
{
s_RenderCamera = new GameObject("Probe Render Camera").
AddComponent<Camera>();
s_RenderCameraData = s_RenderCamera.gameObject.AddComponent<HDAdditionalCameraData>();
}
probe.frameSettings.CopyTo(s_RenderCameraData.GetFrameSettings());
return s_RenderCamera;
s_Instance.Render(probe, target);
}
}
}

105
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs


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

{
static Camera s_RenderCamera = null;
static HDAdditionalCameraData s_RenderCameraData;
HashSet<PlanarReflectionProbe> m_PlanarReflectionProbe_RequestRender;
HashSet<PlanarReflectionProbe> m_PlanarReflectionProbe_RequestRealtimeRender;
PlanarReflectionProbe[] m_PlanarReflectionProbe_RealtimeUpdate_WorkArray;
ReflectionSystemParameters m_Parameters;
m_Parameters = parameters;
m_PlanarReflectionProbe_RequestRender = new HashSet<PlanarReflectionProbe>();
m_PlanarReflectionProbe_RequestRealtimeRender = new HashSet<PlanarReflectionProbe>();
m_PlanarReflectionProbe_RealtimeUpdate_WorkArray = new PlanarReflectionProbe[parameters.maxPlanarReflectionProbes];
if (previous != null)
{

switch (planarProbe.refreshMode)
{
case ReflectionProbeRefreshMode.OnAwake:
m_PlanarReflectionProbe_RequestRender.Add(planarProbe);
m_PlanarReflectionProbe_RequestRealtimeRender.Add(planarProbe);
break;
case ReflectionProbeRefreshMode.EveryFrame:
m_PlanarReflectionProbe_RealtimeUpdate.Add(planarProbe);

{
m_PlanarReflectionProbes.Remove(planarProbe);
m_PlanarReflectionProbe_DirtyBounds.Remove(planarProbe);
m_PlanarReflectionProbe_RequestRender.Remove(planarProbe);
m_PlanarReflectionProbe_RequestRealtimeRender.Remove(planarProbe);
m_PlanarReflectionProbe_RealtimeUpdate.Remove(planarProbe);
}

cullingGroup.Dispose();
}
public void RenderRequestedProbes()
public void RenderAllRealtimeProbes()
{
// Discard disabled probes in requested render probes
m_PlanarReflectionProbe_RequestRealtimeRender.IntersectWith(m_PlanarReflectionProbes);
// Include all realtime probe modes
m_PlanarReflectionProbe_RequestRealtimeRender.UnionWith(m_PlanarReflectionProbe_RealtimeUpdate);
var length = Mathf.Min(m_PlanarReflectionProbe_RequestRealtimeRender.Count, m_PlanarReflectionProbe_RealtimeUpdate_WorkArray.Length);
m_PlanarReflectionProbe_RequestRealtimeRender.CopyTo(m_PlanarReflectionProbe_RealtimeUpdate_WorkArray);
m_PlanarReflectionProbe_RequestRealtimeRender.Clear();
// 1. Allocate if necessary target texture
var camera = GetRenderCamera();
for (var i = 0; i < length; i++)
{
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
var hdCamera = HDCamera.Get(camera, null, probe.frameSettings);
if (!IsRealtimeTextureValid(probe.realtimeTexture, hdCamera))
{
if( probe.realtimeTexture != null)
probe.realtimeTexture.Release();
var desc = hdCamera.renderTextureDesc;
desc.width = m_Parameters.planarReflectionProbeSize;
desc.height = m_Parameters.planarReflectionProbeSize;
desc.colorFormat = RenderTextureFormat.ARGBHalf;
probe.realtimeTexture = new RenderTexture(desc);
}
}
// 2. Render
for (var i = 0; i < length; i++)
{
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
Render(probe, probe.realtimeTexture);
}
}
bool IsRealtimeTextureValid(RenderTexture renderTexture, HDCamera hdCamera)
return renderTexture != null
&& renderTexture.width == m_Parameters.planarReflectionProbeSize
&& renderTexture.height == m_Parameters.planarReflectionProbeSize
&& renderTexture.format == RenderTextureFormat.ARGBHalf;
}
public void RequestRealtimeRender(PlanarReflectionProbe probe)
{
m_PlanarReflectionProbe_RequestRealtimeRender.Add(probe);
}
public void Render(PlanarReflectionProbe probe, RenderTexture target)
{
var renderCamera = GetRenderCamera(probe);
renderCamera.targetTexture = target;
SetupCameraForRender(renderCamera, probe);
renderCamera.Render();
renderCamera.targetTexture = null;
}
void SetProbeBoundsDirty(PlanarReflectionProbe planarProbe)

m_PlanarReflectionProbeBounds[planarReflectionProbe] = planarReflectionProbe.boundingSphere;
}
public void RequestRender(PlanarReflectionProbe probe)
static void SetupCameraForRender(Camera camera, PlanarReflectionProbe probe)
m_PlanarReflectionProbe_RequestRender.Add(probe);
camera.transform.position = probe.capturePosition;
throw new NotImplementedException();
}
static Camera GetRenderCamera(PlanarReflectionProbe probe)
{
var camera = GetRenderCamera();
probe.frameSettings.CopyTo(s_RenderCameraData.GetFrameSettings());
return camera;
}
static Camera GetRenderCamera()
{
if (s_RenderCamera == null)
{
s_RenderCamera = new GameObject("Probe Render Camera").
AddComponent<Camera>();
s_RenderCameraData = s_RenderCamera.gameObject.AddComponent<HDAdditionalCameraData>();
s_RenderCamera.gameObject.SetActive(false);
}
return s_RenderCamera;
}
}
}

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemParameters.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
namespace UnityEngine.Experimental.Rendering.HDPipeline
maxPlanarReflectionProbes = 512
maxPlanarReflectionProbes = 512,
planarReflectionProbeSize = 128
public int planarReflectionProbeSize;
}
}
正在加载...
取消
保存