|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |