浏览代码

[PlanarReflection] Several fixes

/main
Frédéric Vauchelles 7 年前
当前提交
d6ce9c49
共有 7 个文件被更改,包括 51 次插入34 次删除
  1. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs
  2. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
  3. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/GlobalLightLoopSettingsUI.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedGlobalLightLoopSettings.cs
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.cs
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs
  7. 57
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs


[RequireComponent(typeof(Camera))]
public class HDAdditionalCameraData : MonoBehaviour, ISerializationCallbackReceiver
{
// The light culling use standard projection matrices (non-oblique)
// If the user overrides the projection matrix with an oblique one
// He must also provide a callback to get the equivalent non oblique for the culling
public delegate Matrix4x4 NonObliqueProjectionGetter(Camera camera);
#pragma warning disable 414 // CS0414 The private field '...' is assigned but its value is never used

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs


public PostProcessRenderContext postprocessRenderContext;
// Non oblique projection matrix (RHS)
public Matrix4x4 nonObliqueProjMatrix { get { return m_AdditionalCameraData.GetNonObliqueProjection(camera); } }
public Matrix4x4 nonObliqueProjMatrix
{
get
{
return m_AdditionalCameraData != null
? m_AdditionalCameraData.GetNonObliqueProjection(camera)
: GeometryUtils.CalculateProjectionMatrix(camera);
}
}
public Matrix4x4 viewProjMatrix
{

frustumPlanes = new Plane[6];
frustumPlaneEquations = new Vector4[6];
postprocessRenderContext = new PostProcessRenderContext();
m_AdditionalCameraData = cam.GetComponent<HDAdditionalCameraData>() ?? ComponentSingleton<HDAdditionalCameraData>.instance;
m_AdditionalCameraData = cam.GetComponent<HDAdditionalCameraData>();
Reset();
}

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/GlobalLightLoopSettingsUI.cs


namespace UnityEditor.Experimental.Rendering
using UnityEngine;
namespace UnityEditor.Experimental.Rendering
{
using _ = CoreEditorUtils;
using CED = CoreEditorDrawer<GlobalLightLoopSettingsUI, SerializedGlobalLightLoopSettings>;

EditorGUILayout.PropertyField(d.reflectionCubemapSize, _.GetContent("Reflection Cubemap Size"));
EditorGUILayout.PropertyField(d.reflectionProbeCacheSize, _.GetContent("Probe Cache Size"));
EditorGUILayout.Space();
EditorGUILayout.PropertyField(d.maxPlanarReflectionProbes, _.GetContent("Max Planar Probe Per Frame"));
d.maxPlanarReflectionProbes.intValue = Mathf.Max(1, d.maxPlanarReflectionProbes.intValue);
--EditorGUI.indentLevel;
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedGlobalLightLoopSettings.cs


public SerializedProperty planarReflectionProbeCacheSize;
public SerializedProperty planarReflectionCubemapSize;
public SerializedProperty planarReflectionCacheCompressed;
public SerializedProperty maxPlanarReflectionProbes;
public SerializedProperty skyReflectionSize;
public SerializedProperty skyLightingOverrideLayerMask;

planarReflectionProbeCacheSize = root.Find((GlobalLightLoopSettings s) => s.planarReflectionProbeCacheSize);
planarReflectionCubemapSize = root.Find((GlobalLightLoopSettings s) => s.planarReflectionTextureSize);
planarReflectionCacheCompressed = root.Find((GlobalLightLoopSettings s) => s.planarReflectionCacheCompressed);
maxPlanarReflectionProbes = root.Find((GlobalLightLoopSettings s) => s.maxPlanarReflectionProbes);
skyReflectionSize = root.Find((GlobalLightLoopSettings s) => s.skyReflectionSize);
skyLightingOverrideLayerMask = root.Find((GlobalLightLoopSettings s) => s.skyLightingOverrideLayerMask);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.cs


{
return new ReflectionSystemParameters
{
maxPlanarReflectionProbes = 128,
maxPlanarReflectionProbes = renderPipelineSettings.lightLoopSettings.maxPlanarReflectionProbes,
planarReflectionProbeSize = renderPipelineSettings.lightLoopSettings.planarReflectionTextureSize
};
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs


public int planarReflectionTextureSize = 128;
public bool reflectionCacheCompressed = false;
public bool planarReflectionCacheCompressed = false;
public int maxPlanarReflectionProbes = 128;
public SkyResolution skyReflectionSize = SkyResolution.SkyResolution256;
public LayerMask skyLightingOverrideLayerMask = 0;
}

57
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


// 31 bits index, 1 bit cache type
var envIndex = -1;
switch (probe.texture.dimension)
if (probe.planarReflectionProbe != null)
case TextureDimension.Tex2D:
{
envIndex = m_ReflectionPlanarProbeCache.FetchSlice(cmd, probe.texture);
envIndex = envIndex << 1 | (int)EnvCacheType.Texture2D;
envIndex = m_ReflectionPlanarProbeCache.FetchSlice(cmd, probe.texture);
envIndex = envIndex << 1 | (int)EnvCacheType.Texture2D;
float nearClipPlane, farClipPlane, aspect, fov;
Color backgroundColor;
CameraClearFlags clearFlags;
Quaternion captureRotation;
Matrix4x4 worldToCamera, projection;
float nearClipPlane, farClipPlane, aspect, fov;
Color backgroundColor;
CameraClearFlags clearFlags;
Quaternion captureRotation;
Matrix4x4 worldToCamera, projection;
ReflectionSystem.CalculateCaptureCameraProperties(
probe.planarReflectionProbe,
out nearClipPlane, out farClipPlane,
out aspect, out fov, out clearFlags, out backgroundColor,
out worldToCamera, out projection, out capturePosition, out captureRotation,
camera);
ReflectionSystem.CalculateCaptureCameraProperties(
probe.planarReflectionProbe,
out nearClipPlane, out farClipPlane,
out aspect, out fov, out clearFlags, out backgroundColor,
out worldToCamera, out projection, out capturePosition, out captureRotation,
camera);
var gpuProj = GL.GetGPUProjectionMatrix(projection, true); // Had to change this from 'false'
var gpuView = worldToCamera;
var gpuProj = GL.GetGPUProjectionMatrix(projection, true); // Had to change this from 'false'
var gpuView = worldToCamera;
// We transform it to object space by translating the capturePosition
var vp = gpuProj * gpuView * Matrix4x4.Translate(capturePosition);
m_Env2DCaptureVP.Add(vp);
sampleDirectionDiscardWS = captureRotation * Vector3.forward;
break;
}
case TextureDimension.Cube:
envIndex = m_ReflectionProbeCache.FetchSlice(cmd, probe.texture);
envIndex = envIndex << 1 | (int)EnvCacheType.Cubemap;
capturePosition = (Vector3)influenceToWorld.GetColumn(3) - probe.reflectionProbe.center;
break;
// We transform it to object space by translating the capturePosition
var vp = gpuProj * gpuView * Matrix4x4.Translate(capturePosition);
m_Env2DCaptureVP.Add(vp);
sampleDirectionDiscardWS = captureRotation * Vector3.forward;
}
else if (probe.reflectionProbe != null)
{
envIndex = m_ReflectionProbeCache.FetchSlice(cmd, probe.texture);
envIndex = envIndex << 1 | (int)EnvCacheType.Cubemap;
capturePosition = (Vector3)influenceToWorld.GetColumn(3) - probe.reflectionProbe.center;
}
// -1 means that the texture is not ready yet (ie not convolved/compressed yet)
if (envIndex == -1)

}
LightVolumeType lightVolumeType = LightVolumeType.Box;
if (additional != null && additional.influenceShape == ShapeType.Sphere)
if (additional != null && additional.influenceShape == ShapeType.Sphere)
lightVolumeType = LightVolumeType.Sphere;
++envLightCount;

正在加载...
取消
保存