浏览代码

[PlanarReflection] Render only visible probes

/main
Frédéric Vauchelles 7 年前
当前提交
bb3a6683
共有 5 个文件被更改,包括 81 次插入95 次删除
  1. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  2. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystem.cs
  3. 132
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystemInternal.cs
  4. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionProbeType.cs
  5. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionProbeType.cs.meta

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


m_FrameCount = Time.frameCount;
}
// TODO: Render only visible probes
var isReflection = cameras.Any(c => c.cameraType == CameraType.Reflection);
if (!isReflection)
ReflectionSystem.RenderAllRealtimeProbes(ReflectionProbeType.PlanarReflection);
// We first update the state of asset frame settings as they can be use by various camera
// but we keep the dirty state to correctly reset other camera that use RenderingPath.Default.
bool assetFrameSettingsIsDirty = m_Asset.frameSettingsIsDirty;

{
if (camera == null)
continue;
if (camera.cameraType != CameraType.Reflection)
// TODO: Render only visible probes
ReflectionSystem.RenderAllRealtimeViewerDependentProbesFor(ReflectionProbeType.PlanarReflection, camera);
// First, get aggregate of frame settings base on global settings, camera frame settings and debug settings
// Note: the SceneView camera will never have additionalCameraData

}
m_ReflectionProbeCullResults.Cull();
if (camera.cameraType != CameraType.Reflection)
ReflectionSystem.RenderVisiblePlanarProbes(m_ReflectionProbeCullResults, camera);
m_DbufferManager.vsibleDecalCount = 0;
if (m_FrameSettings.enableDBuffer)

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystem.cs


s_Instance.RequestRealtimeRender(probe);
}
public static void RenderAllRealtimeProbes(ReflectionProbeType probeTypes)
public static void RenderVisiblePlanarProbes(ReflectionProbeCullResults cullResults, Camera viewer = null)
s_Instance.RenderAllRealtimeProbes(probeTypes);
s_Instance.RenderVisiblePlanarProbes(cullResults, viewer);
}
public static RenderTexture NewRenderTarget(PlanarReflectionProbe probe)

public static void PrepareCull(Camera camera, ReflectionProbeCullResults results)
{
s_Instance.PrepareCull(camera, results);
}
public static void RenderAllRealtimeViewerDependentProbesFor(ReflectionProbeType probeType, Camera camera)
{
s_Instance.RenderAllRealtimeProbesFor(probeType, camera);
}
public static void CalculateCaptureCameraProperties(PlanarReflectionProbe probe, out float nearClipPlane, out float farClipPlane, out float aspect, out float fov, out CameraClearFlags clearFlags, out Color backgroundColor, out Matrix4x4 worldToCamera, out Matrix4x4 projection, out Vector3 capturePosition, out Quaternion captureRotation, Camera viewerCamera = null)

132
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystemInternal.cs


using System.Collections.Generic;
using System.Linq;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline.Internal

HashSet<PlanarReflectionProbe> m_PlanarReflectionProbes;
HashSet<PlanarReflectionProbe> m_PlanarReflectionProbe_DirtyBounds;
HashSet<PlanarReflectionProbe> m_PlanarReflectionProbe_RequestRealtimeRender;
int m_LastUpdatedFrame = -1;
HashSet<PlanarReflectionProbe> m_LastUpdatedStaticProbes = new HashSet<PlanarReflectionProbe>();
Dictionary<PlanarReflectionProbe, BoundingSphere> m_PlanarReflectionProbeBounds;
PlanarReflectionProbe[] m_PlanarReflectionProbesArray;
BoundingSphere[] m_PlanarReflectionProbeBoundsArray;

// Persistent collections
m_PlanarReflectionProbes = new HashSet<PlanarReflectionProbe>();
m_PlanarReflectionProbe_DirtyBounds = new HashSet<PlanarReflectionProbe>();
m_PlanarReflectionProbe_RequestRealtimeRender = new HashSet<PlanarReflectionProbe>();
m_PlanarReflectionProbe_RealtimeUpdate = new HashSet<PlanarReflectionProbe>();
m_PlanarReflectionProbe_PerCamera_RealtimeUpdate = new HashSet<PlanarReflectionProbe>();

m_PlanarReflectionProbe_DirtyBounds.UnionWith(m_PlanarReflectionProbes);
m_PlanarReflectionProbe_RequestRealtimeRender.UnionWith(previous.m_PlanarReflectionProbe_RequestRealtimeRender);
m_PlanarReflectionProbe_RealtimeUpdate.UnionWith(previous.m_PlanarReflectionProbe_RealtimeUpdate);
m_PlanarReflectionProbe_PerCamera_RealtimeUpdate.UnionWith(previous.m_PlanarReflectionProbe_PerCamera_RealtimeUpdate);
}

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

m_PlanarReflectionProbes.Remove(planarProbe);
m_PlanarReflectionProbeBounds.Remove(planarProbe);
m_PlanarReflectionProbe_DirtyBounds.Remove(planarProbe);
m_PlanarReflectionProbe_RequestRealtimeRender.Remove(planarProbe);
m_PlanarReflectionProbe_RealtimeUpdate.Remove(planarProbe);
m_PlanarReflectionProbe_PerCamera_RealtimeUpdate.Remove(planarProbe);
}

results.PrepareCull(cullingGroup, m_PlanarReflectionProbesArray);
}
public void RenderAllRealtimeProbesFor(ReflectionProbeType probeType, Camera viewerCamera)
public void RenderVisiblePlanarProbes(ReflectionProbeCullResults cullResults, Camera viewer = null)
if ((probeType & ReflectionProbeType.PlanarReflection) != 0)
{
var length = Mathf.Min(m_PlanarReflectionProbe_PerCamera_RealtimeUpdate.Count, m_PlanarReflectionProbe_RealtimeUpdate_WorkArray.Length);
m_PlanarReflectionProbe_PerCamera_RealtimeUpdate.CopyTo(m_PlanarReflectionProbe_RealtimeUpdate_WorkArray);
RenderRealtimeStaticPlanarProbes(cullResults.visiblePlanarReflectionProbes, cullResults.visiblePlanarReflectionProbeCount);
if (viewer != null)
RenderRealtimePerViewerProbes(
cullResults.visiblePlanarReflectionProbes,
cullResults.visiblePlanarReflectionProbeCount,
viewer);
}
// 1. Allocate if necessary target texture
var renderCamera = GetRenderCamera();
for (var i = 0; i < length; i++)
{
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
var hdCamera = HDCamera.Get(renderCamera, null, probe.frameSettings);
if (!IsRealtimeTextureValid(probe.realtimeTexture, hdCamera))
{
if (probe.realtimeTexture != null)
probe.realtimeTexture.Release();
probe.realtimeTexture = NewRenderTarget(probe);
}
}
HashSet<PlanarReflectionProbe> m_RenderRealtimePerViewerProbes_WorkingProbes = new HashSet<PlanarReflectionProbe>();
void RenderRealtimePerViewerProbes(PlanarReflectionProbe[] probes, int probeCount, Camera viewerCamera)
{
m_RenderRealtimePerViewerProbes_WorkingProbes.Clear();
for (var i = 0; i < probeCount; i++)
m_RenderRealtimePerViewerProbes_WorkingProbes.Add(probes[i]);
// Discard non registered nor disabled probes
m_RenderRealtimePerViewerProbes_WorkingProbes.IntersectWith(m_PlanarReflectionProbe_PerCamera_RealtimeUpdate);
// 2. Render
for (var i = 0; i < length; i++)
var length = Mathf.Min(m_RenderRealtimePerViewerProbes_WorkingProbes.Count, m_PlanarReflectionProbe_RealtimeUpdate_WorkArray.Length);
m_RenderRealtimePerViewerProbes_WorkingProbes.CopyTo(m_PlanarReflectionProbe_RealtimeUpdate_WorkArray);
// 1. Allocate if necessary target texture
var renderCamera = GetRenderCamera();
for (var i = 0; i < length; i++)
{
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
var hdCamera = HDCamera.Get(renderCamera, null, probe.frameSettings);
if (!IsRealtimeTextureValid(probe.realtimeTexture, hdCamera))
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
Render(probe, probe.realtimeTexture, viewerCamera);
if (probe.realtimeTexture != null)
probe.realtimeTexture.Release();
probe.realtimeTexture = NewRenderTarget(probe);
// 2. Render
for (var i = 0; i < length; i++)
{
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
Render(probe, probe.realtimeTexture, viewerCamera);
}
public void RenderAllRealtimeProbes(ReflectionProbeType probeTypes)
HashSet<PlanarReflectionProbe> m_RenderRealtimeStaticPlanarProbes_WorkingProbes = new HashSet<PlanarReflectionProbe>();
void RenderRealtimeStaticPlanarProbes(PlanarReflectionProbe[] probes, int probeCount)
if ((probeTypes & ReflectionProbeType.PlanarReflection) != 0)
{
// 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();
m_RenderRealtimeStaticPlanarProbes_WorkingProbes.Clear();
for (var i = 0; i < probeCount; i++)
m_RenderRealtimeStaticPlanarProbes_WorkingProbes.Add(probes[i]);
// 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();
probe.realtimeTexture = NewRenderTarget(probe);
}
}
// Discard non registered nor disabled probes
m_RenderRealtimeStaticPlanarProbes_WorkingProbes.IntersectWith(m_PlanarReflectionProbes);
// 2. Render
for (var i = 0; i < length; i++)
// Discard probes already rendered this frame
if (m_LastUpdatedFrame != Time.frameCount)
m_LastUpdatedStaticProbes.Clear();
m_RenderRealtimeStaticPlanarProbes_WorkingProbes.ExceptWith(m_LastUpdatedStaticProbes);
var length = Mathf.Min(m_RenderRealtimeStaticPlanarProbes_WorkingProbes.Count, m_PlanarReflectionProbe_RealtimeUpdate_WorkArray.Length);
m_RenderRealtimeStaticPlanarProbes_WorkingProbes.CopyTo(m_PlanarReflectionProbe_RealtimeUpdate_WorkArray);
m_LastUpdatedStaticProbes.UnionWith(m_RenderRealtimeStaticPlanarProbes_WorkingProbes);
m_RenderRealtimeStaticPlanarProbes_WorkingProbes.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))
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
Render(probe, probe.realtimeTexture);
if (probe.realtimeTexture != null)
probe.realtimeTexture.Release();
probe.realtimeTexture = NewRenderTarget(probe);
}
// 2. Render
for (var i = 0; i < length; i++)
{
var probe = m_PlanarReflectionProbe_RealtimeUpdate_WorkArray[i];
Render(probe, probe.realtimeTexture);
}
}

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionProbeType.cs


using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Flags]
public enum ReflectionProbeType
{
None = 0,
ReflectionProbe = 1 << 0,
PlanarReflection = 1 << 1
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionProbeType.cs.meta


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