浏览代码

[PlanarReflection] Updated test scene and planar cache

/main
Frédéric Vauchelles 7 年前
当前提交
4baf2005
共有 3 个文件被更改,包括 345 次插入36 次删除
  1. 161
      SampleScenes/HDTest/PlanarReflectionTests.unity
  2. 209
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbeCache.cs
  3. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbeCache.cs.meta

161
SampleScenes/HDTest/PlanarReflectionTests.unity


debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &64497190
GameObject:
m_ObjectHideFlags: 19
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 64497192}
- component: {fileID: 64497191}
m_Layer: 0
m_Name: Reflection System Dictionary
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!114 &64497191
MonoBehaviour:
m_ObjectHideFlags: 19
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 64497190}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: deb5229fc0604de4cb529aedf764520f, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ObjectList: []
--- !u!4 &64497192
Transform:
m_ObjectHideFlags: 19
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 64497190}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &98702533
GameObject:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 117176698}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.057}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1595156406}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 242203120}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.057}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1248132958}

serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 1
m_AreaSize: {x: 6, y: 2}
m_AreaSize: {x: 18, y: 0.5}
m_BounceIntensity: 0.1
m_ColorTemperature: 6570
m_UseColorTemperature: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 303688506}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.057}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1324310549}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 343287173}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.057}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1882799007}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 547467865}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 5, z: 0}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1596124444}

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 547467865}
m_Enabled: 1
m_Enabled: 0
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 547467865}
m_Enabled: 1
m_Enabled: 0
m_Mode: 1
m_Mode: 0
m_BoxSize: {x: 21, y: 11, z: 21}
m_BoxOffset: {x: 0, y: 0, z: 0}
m_BoxSize: {x: 20.1, y: 10.1, z: 20.1}
m_BoxOffset: {x: 0, y: 2, z: 0}
m_NearClip: 0.3
m_FarClip: 1000
m_ShadowDistance: 100

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 584435984}
m_LocalRotation: {x: -0, y: 0.7071024, z: -0, w: 0.7071111}
m_LocalPosition: {x: -9.85, y: 1.87, z: 5.92}
m_LocalPosition: {x: -9.99, y: 1.87, z: 5.92}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 578402206}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 804768700}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -6.45, y: 1.87, z: -9.95}
m_LocalPosition: {x: -6.45, y: 1.87, z: -9.99}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 612211409}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 821409524}
m_LocalRotation: {x: -0, y: 0.70710343, z: -0, w: 0.7071102}
m_LocalPosition: {x: -9.95, y: 3.4, z: 0.1}
m_LocalPosition: {x: -9.99, y: 3.4, z: 0.1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 643605852}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1248132957}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0.000012055039}
m_LocalPosition: {x: 6.21, y: 1.87, z: 9.72}
m_LocalPosition: {x: 6.21, y: 1.87, z: 9.99}
m_LocalScale: {x: 0.99999976, y: 1, z: 0.99999976}
m_Children:
- {fileID: 1662809621}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1324310548}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0.000012055039}
m_LocalPosition: {x: 0.06, y: 3.4, z: 9.95}
m_LocalPosition: {x: 0.06, y: 3.4, z: 9.99}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1812264226}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1361720433}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.057}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 584435985}

serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 1
m_AreaSize: {x: 6, y: 2}
m_AreaSize: {x: 18, y: 0.5}
m_BounceIntensity: 0.1
m_ColorTemperature: 6570
m_UseColorTemperature: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1561776757}
m_LocalRotation: {x: -0, y: -0.7071065, z: -0, w: 0.7071072}
m_LocalPosition: {x: -6.76, y: 2.751, z: 3.33}
m_LocalPosition: {x: -4.987, y: 2.751, z: 3.33}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1596124444}

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1561776757}
m_Enabled: 0
m_Enabled: 1
m_ProxyVolumeReference: {fileID: 0}
m_ProxyVolumeReference: {fileID: 1654939277}
m_BoxBaseSize: {x: 1.7052255, y: 0.9908645, z: 0.95528436}
m_BoxBaseOffset: {x: 0.02969706, y: -0.0045677423, z: -0.022357821}
m_BoxInfluencePositiveFade: {x: 0, y: 0, z: 0.33511347}
m_BoxInfluenceNegativeFade: {x: 0, y: 0, z: 0.067846164}
m_BoxInfluenceNormalPositiveFade: {x: 0, y: 0.28144193, z: 0}
m_BoxInfluenceNormalNegativeFade: {x: 0, y: 0.07764101, z: 0}
m_BoxBaseSize: {x: 3.5541687, y: 3.9430876, z: 0.93649197}
m_BoxBaseOffset: {x: 0.23527569, y: -0.3748026, z: -0.08520496}
m_BoxInfluencePositiveFade: {x: 0, y: 0, z: 0}
m_BoxInfluenceNegativeFade: {x: 0, y: 0, z: 0}
m_BoxInfluenceNormalPositiveFade: {x: 0, y: 0, z: 0}
m_BoxInfluenceNormalNegativeFade: {x: 0, y: 0, z: 0}
m_BoxPositiveFaceFade: {x: 0, y: 0, z: 0}
m_BoxNegativeFaceFade: {x: 0, y: 0, z: 0}
m_SphereBaseRadius: 1.0270488

m_CenterOffset: {x: 0, y: 0, z: 0}
m_CaptureLocalPosition: {x: 0.30307975, y: 0.18300438, z: 4.7699223}
m_Mode: 0
m_Mode: 2
m_RefreshMode: 0
m_CustomTexture: {fileID: 2800000, guid: 624b8c3a613121244b071ae2f92c971b, type: 3}
m_BakedTexture: {fileID: 2800000, guid: 78df8455ea6df3949940f01d0907a72c, type: 2}
m_RealtimeTexture: {fileID: 0}
m_FrameSettings:
enableShadow: 1
enableSSR: 1
enableSSAO: 1
enableSubsurfaceScattering: 1
enableTransmission: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0
enableDepthPrepassWithDeferredRendering: 0
enableAlphaTestOnlyInDeferredPrepass: 0
enableTransparentPrepass: 1
enableMotionVectors: 1
enableObjectMotionVectors: 1
enableDBuffer: 1
enableAtmosphericScattering: 1
enableRoughRefraction: 1
enableTransparentPostpass: 1
enableDistortion: 1
enablePostprocess: 1
enableStereo: 1
enableAsyncCompute: 0
enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableShadowMask: 0
lightLoopSettings:
enableTileAndCluster: 1
enableComputeLightEvaluation: 1
enableComputeLightVariants: 1
enableComputeMaterialVariants: 1
enableFptlForForwardOpaque: 1
enableBigTilePrepass: 1
isFptlEnabled: 1
m_CaptureNearPlane: 4.73
m_CaptureFarPlane: 99.96
--- !u!1 &1562837666
GameObject:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1595156405}
m_LocalRotation: {x: -0, y: -0.707104, z: -0, w: 0.70710963}
m_LocalPosition: {x: 9.91, y: 3.4, z: 0.1}
m_LocalPosition: {x: 9.99, y: 3.4, z: 0.1}
m_LocalScale: {x: 1.0000005, y: 1, z: 1.0000005}
m_Children:
- {fileID: 1583375559}

- component: {fileID: 1654939276}
- component: {fileID: 1654939277}
m_Layer: 0
m_Name: Projection Volume
m_Name: Proxy Volume
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1654939275}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 0, y: 5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1596124444}

m_GameObject: {fileID: 1654939275}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 86d2527ad2205af4b9326464d02c7642, type: 3}
m_Script: {fileID: 11500000, guid: d5c61b7a04f29ad49a0985f4fb6c436d, type: 3}
m_ProxyVolume:
m_ShapeType: 0
m_BoxSize: {x: 20, y: 10, z: 20}
m_BoxOffset: {x: 0, y: 0, z: 0}
m_BoxInfiniteProjection: 0
m_SphereRadius: 1
m_SphereOffset: {x: 0, y: 0, z: 0}
m_SphereInfiniteProjection: 0
--- !u!1 &1662809620
GameObject:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1790557342}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.057}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 821409525}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1882799006}
m_LocalRotation: {x: -0, y: 0.0000012107193, z: -0, w: 1}
m_LocalPosition: {x: 0.06, y: 3.4, z: -9.93}
m_LocalPosition: {x: 0.06, y: 3.4, z: -9.99}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 856438490}

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1933755903}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.057}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 804768701}

209
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbeCache.cs


using System;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class PlanarReflectionProbeCache
{
internal static readonly int s_InputTexID = Shader.PropertyToID("_InputTex");
internal static readonly int s_LoDID = Shader.PropertyToID("_LoD");
internal static readonly int s_FaceIndexID = Shader.PropertyToID("_FaceIndex");
enum ProbeFilteringState
{
Convolving,
Ready
}
int m_ProbeSize;
int m_CacheSize;
IBLFilterGGX m_IBLFilterGGX;
TextureCache2D m_TextureCache;
RenderTexture m_TempRenderTexture;
RenderTexture m_ConvolutionTargetTexture;
ProbeFilteringState[] m_ProbeBakingState;
Material m_ConvertTextureMaterial;
MaterialPropertyBlock m_ConvertTextureMPB;
bool m_PerformBC6HCompression;
public PlanarReflectionProbeCache(IBLFilterGGX iblFilter, int cacheSize, int probeSize, TextureFormat probeFormat, bool isMipmaped)
{
// BC6H requires CPP feature not yet available
probeFormat = TextureFormat.RGBAHalf;
Debug.Assert(probeFormat == TextureFormat.BC6H || probeFormat == TextureFormat.RGBAHalf, "Reflection Probe Cache format for HDRP can only be BC6H or FP16.");
m_ProbeSize = probeSize;
m_CacheSize = cacheSize;
m_TextureCache = new TextureCache2D();
m_TextureCache.AllocTextureArray(cacheSize, probeSize, probeSize, probeFormat, isMipmaped);
m_IBLFilterGGX = iblFilter;
m_PerformBC6HCompression = probeFormat == TextureFormat.BC6H;
InitializeProbeBakingStates();
}
void Initialize()
{
if(m_TempRenderTexture == null)
{
// Temporary RT used for convolution and compression
m_TempRenderTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
m_TempRenderTexture.dimension = TextureDimension.Tex2D;
m_TempRenderTexture.useMipMap = true;
m_TempRenderTexture.autoGenerateMips = false;
m_TempRenderTexture.Create();
m_ConvolutionTargetTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);
m_ConvolutionTargetTexture.dimension = TextureDimension.Tex2D;
m_ConvolutionTargetTexture.useMipMap = true;
m_ConvolutionTargetTexture.autoGenerateMips = false;
m_ConvolutionTargetTexture.Create();
m_ConvertTextureMaterial = CoreUtils.CreateEngineMaterial("Hidden/SRP/BlitCubeTextureFace");
m_ConvertTextureMPB = new MaterialPropertyBlock();
InitializeProbeBakingStates();
}
}
void InitializeProbeBakingStates()
{
m_ProbeBakingState = new ProbeFilteringState[m_CacheSize];
for (int i = 0; i < m_CacheSize; ++i)
m_ProbeBakingState[i] = ProbeFilteringState.Convolving;
}
public void Release()
{
if(m_TextureCache != null)
{
m_TextureCache.Release();
m_TextureCache = null;
}
if(m_TempRenderTexture != null)
{
m_TempRenderTexture.Release();
m_TempRenderTexture = null;
}
m_ProbeBakingState = null;
}
public void NewFrame()
{
Initialize();
m_TextureCache.NewFrame();
}
// This method is used to convert inputs that are either compressed or not of the right size.
// We can't use Graphics.ConvertTexture here because it does not work with a RenderTexture as destination.
void ConvertTexture(CommandBuffer cmd, Texture input, RenderTexture target)
{
m_ConvertTextureMPB.SetTexture(s_InputTexID, input);
m_ConvertTextureMPB.SetFloat(s_LoDID, 0.0f); // We want to convert mip 0 to whatever the size of the destination cache is.
CoreUtils.SetRenderTarget(cmd, target, ClearFlag.None, Color.black, 0, 0);
CoreUtils.DrawFullScreen(cmd, m_ConvertTextureMaterial, m_ConvertTextureMPB);
}
Texture ConvolveProbeTexture(CommandBuffer cmd, Texture texture)
{
// Probes can be either Cubemaps (for baked probes) or RenderTextures (for realtime probes)
Texture2D texture2D = texture as Texture2D;
RenderTexture renderTexture = texture as RenderTexture;
RenderTexture convolutionSourceTexture = null;
if (texture2D != null)
{
// if the size if different from the cache probe size or if the input texture format is compressed, we need to convert it
// 1) to a format for which we can generate mip maps
// 2) to the proper reflection probe cache size
var sizeMismatch = texture2D.width != m_ProbeSize || texture2D.height != m_ProbeSize;
var formatMismatch = texture2D.format != TextureFormat.RGBAHalf; // Temporary RT for convolution is always FP16
if (formatMismatch || sizeMismatch)
{
if (sizeMismatch)
{
Debug.LogWarningFormat("Baked Planar Reflection Probe {0} does not match HDRP Planar Reflection Probe Cache size of {1}. Consider baking it at the same size for better loading performance.", texture.name, m_ProbeSize);
}
else if (texture2D.format == TextureFormat.BC6H)
{
Debug.LogWarningFormat("Baked Planar Reflection Probe {0} is compressed but the HDRP Planar Reflection Probe Cache is not. Consider removing compression from the input texture for better quality.", texture.name);
}
ConvertTexture(cmd, texture2D, m_TempRenderTexture);
}
else
cmd.CopyTexture(texture2D, 0, 0, m_TempRenderTexture, 0, 0);
// Ideally if input is not compressed and has mipmaps, don't do anything here. Problem is, we can't know if mips have been already convolved offline...
cmd.GenerateMips(m_TempRenderTexture);
convolutionSourceTexture = m_TempRenderTexture;
}
else
{
Debug.Assert(renderTexture != null);
if (renderTexture.dimension != TextureDimension.Tex2D)
{
Debug.LogError("Planar Realtime reflection probe should always be a 2D RenderTexture.");
return null;
}
// TODO: Do a different case for downsizing, in this case, instead of doing ConvertTexture just use the relevant mipmaps.
var sizeMismatch = renderTexture.width != m_ProbeSize || renderTexture.height != m_ProbeSize;
if (sizeMismatch)
{
ConvertTexture(cmd, renderTexture, m_TempRenderTexture);
convolutionSourceTexture = m_TempRenderTexture;
}
else
convolutionSourceTexture = renderTexture;
// Generate unfiltered mipmaps as a base for convolution
// TODO: Make sure that we don't first convolve everything on the GPU with the legacy code path executed after rendering the probe.
cmd.GenerateMips(convolutionSourceTexture);
}
m_IBLFilterGGX.FilterPlanarTexture(cmd, convolutionSourceTexture, m_ConvolutionTargetTexture);
return m_ConvolutionTargetTexture;
}
public int FetchSlice(CommandBuffer cmd, Texture texture)
{
bool needUpdate;
var sliceIndex = m_TextureCache.ReserveSlice(texture, out needUpdate);
if (sliceIndex != -1)
{
if(needUpdate || m_ProbeBakingState[sliceIndex] != ProbeFilteringState.Ready)
{
using (new ProfilingSample(cmd, "Convolve Planar Reflection Probe"))
{
// For now baking is done directly but will be time sliced in the future. Just preparing the code here.
m_ProbeBakingState[sliceIndex] = ProbeFilteringState.Convolving;
Texture result = ConvolveProbeTexture(cmd, texture);
if (result == null)
return -1;
if (m_PerformBC6HCompression)
{
throw new NotImplementedException("BC6H Support not implemented for PlanarReflectionProbeCache");
}
else
{
m_TextureCache.UpdateSlice(cmd, sliceIndex, result, m_TextureCache.GetTextureHash(texture)); // Be careful to provide the update count from the input texture, not the temporary one used for convolving.
}
m_ProbeBakingState[sliceIndex] = ProbeFilteringState.Ready;
}
}
}
return sliceIndex;
}
public Texture GetTexCache()
{
return m_TextureCache.GetTexCache();
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbeCache.cs.meta


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