浏览代码
Merge branch 'master' into decals/texture_atlas
Merge branch 'master' into decals/texture_atlas
# Conflicts: # ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.compute # ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Light/HDAdditionalLightData.cs/main
Paul Melamed
7 年前
当前提交
5e4ad2d7
共有 144 个文件被更改,包括 6107 次插入 和 3537 次删除
-
8CHANGELOG.md
-
999ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1102_Unlit_Distortion.unity.png
-
998ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1103_Unlit_Distortion_DepthTest.unity.png
-
998ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1203_Lit_Transparent.unity.png
-
999ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction.unity.png
-
999ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1206_Lit_Transparent_Distortion.unity.png
-
999ImageTemplates/HDRenderPipeline/Scenes/9xxx_Other/9002_Deferred-and-Forward.unity.png
-
4ScriptableRenderPipeline/Core/CHANGELOG.md
-
1ScriptableRenderPipeline/Core/CoreRP/CoreResources/GPUCopy.compute
-
1ScriptableRenderPipeline/Core/CoreRP/CoreResources/GPUCopyAsset.cs
-
5ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.compute
-
10ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.cs
-
1ScriptableRenderPipeline/Core/CoreRP/Debugging/DebugUI.Panel.cs
-
3ScriptableRenderPipeline/Core/CoreRP/Debugging/DebugUI.cs
-
15ScriptableRenderPipeline/Core/CoreRP/Editor/Debugging/DebugWindow.cs
-
5ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/CSharpToHLSL.cs
-
2ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/EntityLighting.hlsl
-
15ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs
-
275ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
-
121ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
-
84ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
-
18ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs
-
16ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs.hlsl
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/SerializedHDCamera.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/EditorRenderPipelineResources/ReflectionProbesPreview.shader
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.Drawers.cs
-
17ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.Handles.cs
-
45ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/LayeredLit/LayeredLitUI.cs
-
34ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/HDRenderPipelineEditor.cs
-
133ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
-
22ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Light/HDAdditionalLightData.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
-
157ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild-bigtile.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild-clustered.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/materialflags.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/scrbound.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/DiffusionProfile/DiffusionProfileSettings.cs
-
79ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/GGXConvolution/RuntimeFilterIBL.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLit.shader
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
-
19ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
-
15ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl
-
177ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/ShaderPass/LitDepthPass.hlsl
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/ShaderPass/LitVelocityPass.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Unlit/Unlit.shader
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/ApplyDistorsion.compute
-
167ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramid.cs
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/CopyDepthBuffer.shader
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
-
4Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/Materials/PreRefractionPassTester.mat
-
30Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/SkySettings/HDRP_Default_Sky.asset
-
926Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction.unity
-
5Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Plane_NM.mat
-
6Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Plane_NM_Thickness.mat
-
5Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Plane_Thickness.mat
-
5Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Sphere_NM.mat
-
6Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Sphere_NM_Thickness.mat
-
5Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Sphere_Thickness.mat
-
6Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Sphere_HiZ.mat
-
6Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction/Lit_Refraction_Plane_HiZ.mat
-
16Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/9xxx_Other/9002_Deferred-and-Forward/ComplexMaterial_Flipped/ComplexMaterial_Flipped.mat
-
46Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/9xxx_Other/9002_Deferred-and-Forward/ComplexMaterial_Flipped/Textures/ComplexMat_H.png.meta
-
4Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/9xxx_Other/9002_Deferred-and-Forward/ComplexMaterial_Flipped/Textures/ComplexMat__N.png.meta
-
4Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/9xxx_Other/9002_Deferred-and-Forward/GlassLike.mat
-
3Tests/Scripts/GraphicTests/Framework/TestFrameworkTools.cs
-
49ScriptableRenderPipeline/Core/CoreRP/Debugging/MousePositionDebug.cs
-
8ScriptableRenderPipeline/Core/CoreRP/Common.meta
-
8ScriptableRenderPipeline/Core/CoreRP/Textures.meta
-
8ScriptableRenderPipeline/Core/CoreRP/Utilities.meta
-
14ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDAdditionalCameraEditor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Camera/HDAdditionalCameraEditor.cs.meta
-
14ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/AdditionalShadowDataEditor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/AdditionalShadowDataEditor.cs.meta
-
14ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDAdditionalLightDataEditor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDAdditionalLightDataEditor.cs.meta
-
42ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ScreenSpaceRefractionEditor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ScreenSpaceRefractionEditor.cs.meta
-
38ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceRefraction.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceRefraction.cs.meta
-
498ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl.meta
-
235ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramidProcessor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/BufferPyramidProcessor.cs.meta
999
ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1102_Unlit_Distortion.unity.png
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
998
ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1103_Unlit_Distortion_DepthTest.unity.png
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
998
ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1203_Lit_Transparent.unity.png
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
999
ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction.unity.png
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
999
ImageTemplates/HDRenderPipeline/Scenes/1xxx_Materials/1206_Lit_Transparent_Distortion.unity.png
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
999
ImageTemplates/HDRenderPipeline/Scenes/9xxx_Other/9002_Deferred-and-Forward.unity.png
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
926
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/1xxx_Materials/1205_Lit_Transparent_Refraction.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: e58bd4f13d26cde488393d3a2e9bf9cd |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 89be4d313c8b0fa4c8d2449dbbbf13f0 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f57623255fe8c064bb8297404521464a |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[CustomEditor(typeof(HDAdditionalCameraData))] |
|||
class HDAdditionalCameraDataEditor : Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7d13c99eb3063b943ad3ff72bb597a40 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[CustomEditor(typeof(AdditionalShadowData))] |
|||
class AdditionalShadowDataEditor : Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a4c41e6de0507a14487dd227f7d08b5f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[CustomEditor(typeof(HDAdditionalLightData))] |
|||
class HDAdditionalLightDataEditor : Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bf761ccb3da263c4cbcfa1c0ecbd05fc |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.Experimental.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[VolumeComponentEditor(typeof(ScreenSpaceRefraction))] |
|||
public class ScreenSpaceRefractionEditor : VolumeComponentEditor |
|||
{ |
|||
SerializedDataParameter m_RayMinLevel; |
|||
SerializedDataParameter m_RayMaxLevel; |
|||
SerializedDataParameter m_RayMaxIterations; |
|||
SerializedDataParameter m_RayDepthSuccessBias; |
|||
SerializedDataParameter m_ScreenWeightDistance; |
|||
|
|||
public override void OnEnable() |
|||
{ |
|||
var o = new PropertyFetcher<ScreenSpaceRefraction>(serializedObject); |
|||
|
|||
m_RayMinLevel = Unpack(o.Find(x => x.rayMinLevel)); |
|||
m_RayMaxLevel = Unpack(o.Find(x => x.rayMaxLevel)); |
|||
m_RayMaxIterations = Unpack(o.Find(x => x.rayMaxIterations)); |
|||
m_RayDepthSuccessBias = Unpack(o.Find(x => x.rayDepthSuccessBias)); |
|||
m_ScreenWeightDistance = Unpack(o.Find(x => x.screenWeightDistance)); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
EditorGUILayout.LabelField(CoreEditorUtils.GetContent("HiZ Settings")); |
|||
PropertyField(m_RayMinLevel, CoreEditorUtils.GetContent("Ray Min Level")); |
|||
PropertyField(m_RayMaxLevel, CoreEditorUtils.GetContent("Ray Max Level")); |
|||
PropertyField(m_RayMaxIterations, CoreEditorUtils.GetContent("Ray Max Iterations")); |
|||
PropertyField(m_RayDepthSuccessBias, CoreEditorUtils.GetContent("Ray Depth Success Bias")); |
|||
|
|||
EditorGUILayout.Separator(); |
|||
EditorGUILayout.LabelField(CoreEditorUtils.GetContent("Common Settings")); |
|||
PropertyField(m_ScreenWeightDistance, CoreEditorUtils.GetContent("Screen Weight Distance")); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5b3212fe1b5bb3c4397c9427bb77c207 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[Serializable] |
|||
public class ScreenSpaceRefraction : VolumeComponent |
|||
{ |
|||
static ScreenSpaceRefraction s_Default = null; |
|||
public static ScreenSpaceRefraction @default |
|||
{ |
|||
get |
|||
{ |
|||
if (s_Default == null) |
|||
{ |
|||
s_Default = ScriptableObject.CreateInstance<ScreenSpaceRefraction>(); |
|||
s_Default.hideFlags = HideFlags.HideAndDontSave; |
|||
} |
|||
return s_Default; |
|||
} |
|||
} |
|||
|
|||
public IntParameter rayMinLevel = new IntParameter(2); |
|||
public IntParameter rayMaxLevel = new IntParameter(6); |
|||
public IntParameter rayMaxIterations = new IntParameter(32); |
|||
public FloatParameter rayDepthSuccessBias = new FloatParameter(0.1f); |
|||
public ClampedFloatParameter screenWeightDistance = new ClampedFloatParameter(0.1f, 0, 1); |
|||
|
|||
public void PushShaderParameters(CommandBuffer cmd) |
|||
{ |
|||
cmd.SetGlobalInt(HDShaderIDs._SSRefractionRayMinLevel, rayMinLevel.value); |
|||
cmd.SetGlobalInt(HDShaderIDs._SSRefractionRayMaxLevel, rayMaxLevel.value); |
|||
cmd.SetGlobalInt(HDShaderIDs._SSRefractionRayMaxIterations, rayMaxIterations.value); |
|||
cmd.SetGlobalFloat(HDShaderIDs._SSRefractionRayDepthSuccessBias, rayDepthSuccessBias.value); |
|||
cmd.SetGlobalFloat(HDShaderIDs._SSRefractionInvScreenWeightDistance, 1f / screenWeightDistance.value); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e17fad69ea181b4483974138b566975 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_SCREEN_SPACE_TRACING_INCLUDED |
|||
#define UNITY_SCREEN_SPACE_TRACING_INCLUDED |
|||
|
|||
// ------------------------------------------------- |
|||
// Algorithm uniform parameters |
|||
// ------------------------------------------------- |
|||
|
|||
const float DepthPlaneBias = 1E-5; |
|||
|
|||
// ------------------------------------------------- |
|||
// Output |
|||
// ------------------------------------------------- |
|||
|
|||
struct ScreenSpaceRayHit |
|||
{ |
|||
uint2 positionSS; // Position of the hit point (SS) |
|||
float2 positionNDC; // Position of the hit point (NDC) |
|||
float linearDepth; // Linear depth of the hit point |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
float3 debugOutput; |
|||
#endif |
|||
}; |
|||
|
|||
struct ScreenSpaceHiZRaymarchInput |
|||
{ |
|||
float3 rayOriginWS; // Ray origin (WS) |
|||
float3 rayDirWS; // Ray direction (WS) |
|||
uint maxIterations; // Number of iterations before failing |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
bool debug; |
|||
#endif |
|||
}; |
|||
|
|||
struct ScreenSpaceProxyRaycastInput |
|||
{ |
|||
float3 rayOriginWS; // Ray origin (WS) |
|||
float3 rayDirWS; // Ray direction (WS) |
|||
EnvLightData proxyData; |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
bool debug; |
|||
#endif |
|||
}; |
|||
|
|||
// ------------------------------------------------- |
|||
// Utilities |
|||
// ------------------------------------------------- |
|||
|
|||
// Calculate the ray origin and direction in SS |
|||
// out positionSS : (x, y, 1/depth) |
|||
// out raySS : (x, y, 1/depth) |
|||
void CalculateRaySS( |
|||
float3 rayOriginWS, |
|||
float3 rayDirWS, |
|||
uint2 bufferSize, |
|||
out float3 positionSS, |
|||
out float3 raySS |
|||
) |
|||
{ |
|||
float3 positionWS = rayOriginWS; |
|||
float3 rayEndWS = rayOriginWS + rayDirWS * 10; |
|||
|
|||
float4 positionCS = ComputeClipSpacePosition(positionWS, GetWorldToHClipMatrix()); |
|||
float4 rayEndCS = ComputeClipSpacePosition(rayEndWS, GetWorldToHClipMatrix()); |
|||
|
|||
float2 positionNDC = ComputeNormalizedDeviceCoordinates(positionWS, GetWorldToHClipMatrix()); |
|||
float2 rayEndNDC = ComputeNormalizedDeviceCoordinates(rayEndWS, GetWorldToHClipMatrix()); |
|||
|
|||
float3 rayStartSS = float3( |
|||
positionNDC.xy * bufferSize, |
|||
1.0 / positionCS.w); // Screen space depth interpolate properly in 1/z |
|||
|
|||
float3 rayEndSS = float3( |
|||
rayEndNDC.xy * bufferSize, |
|||
1.0 / rayEndCS.w); // Screen space depth interpolate properly in 1/z |
|||
|
|||
positionSS = rayStartSS; |
|||
raySS = rayEndSS - rayStartSS; |
|||
} |
|||
|
|||
// Check whether the depth of the ray is above the sampled depth |
|||
// Arguments are inversed linear depth |
|||
bool IsPositionAboveDepth(float rayDepth, float invLinearDepth) |
|||
{ |
|||
// as depth is inverted, we must invert the check as well |
|||
// rayZ > HiZ <=> 1/rayZ < 1/HiZ |
|||
return rayDepth > invLinearDepth; |
|||
} |
|||
|
|||
// Sample the Depth buffer at a specific mip and linear depth |
|||
float LoadDepth(float2 positionSS, int level) |
|||
{ |
|||
float pyramidDepth = LOAD_TEXTURE2D_LOD(_DepthPyramidTexture, int2(positionSS.xy) >> level, level).r; |
|||
float linearDepth = LinearEyeDepth(pyramidDepth, _ZBufferParams); |
|||
return linearDepth; |
|||
} |
|||
|
|||
// Sample the Depth buffer at a specific mip and return 1/linear depth |
|||
float LoadInvDepth(float2 positionSS, int level) |
|||
{ |
|||
float linearDepth = LoadDepth(positionSS, level); |
|||
float invLinearDepth = 1 / linearDepth; |
|||
return invLinearDepth; |
|||
} |
|||
|
|||
bool CellAreEquals(int2 cellA, int2 cellB) |
|||
{ |
|||
return cellA.x == cellB.x && cellA.y == cellB.y; |
|||
} |
|||
|
|||
// Calculate intersection between the ray and the depth plane |
|||
// positionSS.z is 1/depth |
|||
// raySS.z is 1/depth |
|||
float3 IntersectDepthPlane(float3 positionSS, float3 raySS, float invDepth) |
|||
{ |
|||
// The depth of the intersection with the depth plane is: positionSS.z + raySS.z * t = invDepth |
|||
float t = (invDepth - positionSS.z) / raySS.z; |
|||
|
|||
// (t<0) When the ray is going away from the depth plane, |
|||
// put the intersection away. |
|||
// Instead the intersection with the next tile will be used. |
|||
// (t>=0) Add a small distance to go through the depth plane. |
|||
t = t >= 0.0f ? (t + DepthPlaneBias) : 1E5; |
|||
|
|||
// Return the point on the ray |
|||
return positionSS + raySS * t; |
|||
} |
|||
|
|||
// Calculate intersection between a ray and a cell |
|||
float3 IntersectCellPlanes( |
|||
float3 positionSS, |
|||
float3 raySS, |
|||
float2 invRaySS, |
|||
int2 cellId, |
|||
uint2 cellSize, |
|||
int2 cellPlanes, |
|||
float2 crossOffset |
|||
) |
|||
{ |
|||
const float SQRT_2 = sqrt(2); |
|||
const float CellPlaneBias = 1E-2; |
|||
|
|||
// Planes to check |
|||
int2 planes = (cellId + cellPlanes) * cellSize; |
|||
// Hit distance to each planes |
|||
float2 distanceToCellAxes = float2(planes - positionSS.xy) * invRaySS; // (distance to x axis, distance to y axis) |
|||
float t = min(distanceToCellAxes.x, distanceToCellAxes.y) |
|||
// Offset by 1E-3 to ensure cell boundary crossing |
|||
// This assume that length(raySS.xy) == 1; |
|||
+ CellPlaneBias; |
|||
// Interpolate screen space to get next test point |
|||
float3 testHitPositionSS = positionSS + raySS * t; |
|||
|
|||
return testHitPositionSS; |
|||
} |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
// ------------------------------------------------- |
|||
// Debug Utilities |
|||
// ------------------------------------------------- |
|||
|
|||
void DebugComputeCommonOutput( |
|||
float3 rayDirWS, |
|||
bool hitSuccessful, |
|||
inout ScreenSpaceRayHit hit |
|||
) |
|||
{ |
|||
switch (_DebugLightingSubMode) |
|||
{ |
|||
case DEBUGSCREENSPACETRACING_RAY_DIR_WS: |
|||
hit.debugOutput = rayDirWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGSCREENSPACETRACING_HIT_DEPTH: |
|||
hit.debugOutput = frac(hit.linearDepth * 0.1); |
|||
break; |
|||
case DEBUGSCREENSPACETRACING_HIT_SUCCESS: |
|||
hit.debugOutput = hitSuccessful; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void DebugComputeHiZOutput( |
|||
int iteration, |
|||
float3 startPositionSS, |
|||
float3 rayDirSS, |
|||
int maxIterations, |
|||
int maxUsedLevel, |
|||
int maxMipLevel, |
|||
int intersectionKind, |
|||
inout ScreenSpaceRayHit hit |
|||
) |
|||
{ |
|||
switch (_DebugLightingSubMode) |
|||
{ |
|||
case DEBUGSCREENSPACETRACING_HI_ZPOSITION_NDC: |
|||
hit.debugOutput = float3(float2(startPositionSS.xy) * _ScreenSize.zw, 0); |
|||
break; |
|||
case DEBUGSCREENSPACETRACING_HI_ZITERATION_COUNT: |
|||
hit.debugOutput = float(iteration) / float(maxIterations); |
|||
break; |
|||
case DEBUGSCREENSPACETRACING_HI_ZRAY_DIR_NDC: |
|||
hit.debugOutput = float3(rayDirSS.xy * 0.5 + 0.5, frac(0.1 / rayDirSS.z)); |
|||
break; |
|||
case DEBUGSCREENSPACETRACING_HI_ZMAX_USED_MIP_LEVEL: |
|||
hit.debugOutput = float(maxUsedLevel) / float(maxMipLevel); |
|||
break; |
|||
case DEBUGSCREENSPACETRACING_HI_ZINTERSECTION_KIND: |
|||
hit.debugOutput = GetIndexColor(intersectionKind); |
|||
break; |
|||
} |
|||
} |
|||
#endif |
|||
#endif |
|||
|
|||
// ------------------------------------------------- |
|||
// Algorithm: Proxy raycast |
|||
// ------------------------------------------------- |
|||
|
|||
#ifdef SSRTID |
|||
|
|||
#define SSRT_SETTING(name, SSRTID) _SS ## SSRTID ## name |
|||
#define SSRT_FUNC(name, SSRTID) name ## SSRTID |
|||
|
|||
CBUFFER_START(SSRT_FUNC(UnityScreenSpaceRaymarching, SSRTID)) |
|||
int SSRT_SETTING(RayMinLevel, SSRTID); |
|||
int SSRT_SETTING(RayMaxLevel, SSRTID); |
|||
int SSRT_SETTING(RayMaxIterations, SSRTID); |
|||
float SSRT_SETTING(RayDepthSuccessBias, SSRTID); |
|||
CBUFFER_END |
|||
|
|||
bool SSRT_FUNC(ScreenSpaceProxyRaycast, SSRTID)( |
|||
ScreenSpaceProxyRaycastInput input, |
|||
out ScreenSpaceRayHit hit |
|||
) |
|||
{ |
|||
ZERO_INITIALIZE(ScreenSpaceRayHit, hit); |
|||
|
|||
float3x3 worldToPS = WorldToProxySpace(input.proxyData); |
|||
float3 rayOriginPS = WorldToProxyPosition(input.proxyData, worldToPS, input.rayOriginWS); |
|||
float3 rayDirPS = mul(input.rayDirWS, worldToPS); |
|||
|
|||
float projectionDistance = 0.0; |
|||
|
|||
switch(input.proxyData.influenceShapeType) |
|||
{ |
|||
case ENVSHAPETYPE_SPHERE: |
|||
case ENVSHAPETYPE_SKY: |
|||
{ |
|||
projectionDistance = IntersectSphereProxy(input.proxyData, rayDirPS, rayOriginPS); |
|||
break; |
|||
} |
|||
case ENVSHAPETYPE_BOX: |
|||
projectionDistance = IntersectBoxProxy(input.proxyData, rayDirPS, rayOriginPS); |
|||
break; |
|||
} |
|||
|
|||
float3 hitPositionWS = input.rayOriginWS + input.rayDirWS * projectionDistance; |
|||
float4 hitPositionCS = ComputeClipSpacePosition(hitPositionWS, GetWorldToHClipMatrix()); |
|||
float4 rayOriginCS = ComputeClipSpacePosition(input.rayOriginWS, GetWorldToHClipMatrix()); |
|||
float2 hitPositionNDC = ComputeNormalizedDeviceCoordinates(hitPositionWS, GetWorldToHClipMatrix()); |
|||
uint2 hitPositionSS = uint2(hitPositionNDC *_ScreenSize.xy); |
|||
float hitLinearDepth = hitPositionCS.w; |
|||
|
|||
hit.positionNDC = hitPositionNDC; |
|||
hit.positionSS = hitPositionSS; |
|||
hit.linearDepth = hitLinearDepth; |
|||
|
|||
bool hitSuccessful = true; |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
DebugComputeCommonOutput(input.rayDirWS, hitSuccessful, hit); |
|||
|
|||
if (input.debug) |
|||
{ |
|||
ScreenSpaceTracingDebug debug; |
|||
ZERO_INITIALIZE(ScreenSpaceTracingDebug, debug); |
|||
|
|||
float2 rayOriginNDC = ComputeNormalizedDeviceCoordinates(input.rayOriginWS, GetWorldToHClipMatrix()); |
|||
uint2 rayOriginSS = uint2(rayOriginNDC * _ScreenSize.xy); |
|||
|
|||
debug.tracingModel = REFRACTIONSSRAYMODEL_PROXY; |
|||
debug.loopStartPositionSSX = rayOriginSS.x; |
|||
debug.loopStartPositionSSY = rayOriginSS.y; |
|||
debug.loopStartLinearDepth = rayOriginCS.w; |
|||
debug.endHitSuccess = hitSuccessful; |
|||
debug.endLinearDepth = hitLinearDepth; |
|||
debug.endPositionSSX = hitPositionSS.x; |
|||
debug.endPositionSSY = hitPositionSS.y; |
|||
debug.proxyShapeType = input.proxyData.influenceShapeType; |
|||
debug.projectionDistance = projectionDistance; |
|||
|
|||
_DebugScreenSpaceTracingData[0] = debug; |
|||
} |
|||
#endif |
|||
|
|||
return hitSuccessful; |
|||
} |
|||
|
|||
// ------------------------------------------------- |
|||
// Algorithm: HiZ raymarching |
|||
// ------------------------------------------------- |
|||
|
|||
// Based on Yasin Uludag, 2014. "Hi-Z Screen-Space Cone-Traced Reflections", GPU Pro5: Advanced Rendering Techniques |
|||
|
|||
bool SSRT_FUNC(ScreenSpaceHiZRaymarch, SSRTID)( |
|||
ScreenSpaceHiZRaymarchInput input, |
|||
out ScreenSpaceRayHit hit |
|||
) |
|||
{ |
|||
const float2 CROSS_OFFSET = float2(1, 1); |
|||
|
|||
// Initialize loop |
|||
ZERO_INITIALIZE(ScreenSpaceRayHit, hit); |
|||
bool hitSuccessful = true; |
|||
uint iteration = 0u; |
|||
int minMipLevel = max(SSRT_SETTING(RayMinLevel, SSRTID), 0); |
|||
int maxMipLevel = min(SSRT_SETTING(RayMaxLevel, SSRTID), int(_DepthPyramidScale.z)); |
|||
uint2 bufferSize = uint2(_DepthPyramidSize.xy); |
|||
uint maxIterations = min(input.maxIterations, SSRT_SETTING(RayMaxIterations, SSRTID)); |
|||
|
|||
float3 startPositionSS; |
|||
float3 raySS; |
|||
CalculateRaySS( |
|||
input.rayOriginWS, |
|||
input.rayDirWS, |
|||
bufferSize, |
|||
startPositionSS, |
|||
raySS |
|||
); |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
// Initialize debug variables |
|||
int debugLoopMipMaxUsedLevel = minMipLevel; |
|||
int debugIterationMipLevel = minMipLevel; |
|||
uint2 debugIterationCellSize = uint2(0u, 0u); |
|||
float3 debugIterationPositionSS = float3(0, 0, 0); |
|||
uint debugIteration = 0u; |
|||
uint debugIterationIntersectionKind = 0u; |
|||
float debugIterationLinearDepthBuffer = 0; |
|||
#endif |
|||
|
|||
int intersectionKind = 0; |
|||
float raySSLength = length(raySS.xy); |
|||
raySS /= raySSLength; |
|||
// Initialize raymarching |
|||
float2 invRaySS = float2(1, 1) / raySS.xy; |
|||
|
|||
// Calculate planes to intersect for each cell |
|||
int2 cellPlanes = sign(raySS.xy); |
|||
float2 crossOffset = CROSS_OFFSET * cellPlanes; |
|||
cellPlanes = clamp(cellPlanes, 0, 1); |
|||
|
|||
int currentLevel = minMipLevel; |
|||
uint2 cellCount = bufferSize >> currentLevel; |
|||
uint2 cellSize = uint2(1, 1) << currentLevel; |
|||
|
|||
float3 positionSS = startPositionSS; |
|||
float invHiZDepth = 0; |
|||
|
|||
while (currentLevel >= minMipLevel) |
|||
{ |
|||
if (iteration >= maxIterations) |
|||
{ |
|||
hitSuccessful = false; |
|||
break; |
|||
} |
|||
|
|||
cellCount = bufferSize >> currentLevel; |
|||
cellSize = uint2(1, 1) << currentLevel; |
|||
|
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
// Fetch pre iteration debug values |
|||
if (input.debug && _DebugStep >= iteration) |
|||
debugIterationMipLevel = currentLevel; |
|||
#endif |
|||
|
|||
// Go down in HiZ levels by default |
|||
int mipLevelDelta = -1; |
|||
|
|||
// Sampled as 1/Z so it interpolate properly in screen space. |
|||
invHiZDepth = LoadInvDepth(positionSS.xy, currentLevel); |
|||
intersectionKind = HIZINTERSECTIONKIND_NONE; |
|||
|
|||
if (IsPositionAboveDepth(positionSS.z, invHiZDepth)) |
|||
{ |
|||
float3 candidatePositionSS = IntersectDepthPlane(positionSS, raySS, invHiZDepth); |
|||
|
|||
intersectionKind = HIZINTERSECTIONKIND_DEPTH; |
|||
|
|||
const int2 cellId = int2(positionSS.xy) / cellSize; |
|||
const int2 candidateCellId = int2(candidatePositionSS.xy) / cellSize; |
|||
|
|||
// If we crossed the current cell |
|||
if (!CellAreEquals(cellId, candidateCellId)) |
|||
{ |
|||
candidatePositionSS = IntersectCellPlanes( |
|||
positionSS, |
|||
raySS, |
|||
invRaySS, |
|||
cellId, |
|||
cellSize, |
|||
cellPlanes, |
|||
crossOffset); |
|||
|
|||
intersectionKind = HIZINTERSECTIONKIND_CELL; |
|||
|
|||
// Go up a level to go faster |
|||
mipLevelDelta = 1; |
|||
} |
|||
|
|||
positionSS = candidatePositionSS; |
|||
} |
|||
|
|||
currentLevel = min(currentLevel + mipLevelDelta, maxMipLevel); |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
// Fetch post iteration debug values |
|||
if (input.debug && _DebugStep >= iteration) |
|||
{ |
|||
debugLoopMipMaxUsedLevel = max(debugLoopMipMaxUsedLevel, currentLevel); |
|||
debugIterationPositionSS = positionSS; |
|||
debugIterationLinearDepthBuffer = 1 / invHiZDepth; |
|||
debugIteration = iteration; |
|||
debugIterationIntersectionKind = intersectionKind; |
|||
debugIterationCellSize = cellSize; |
|||
} |
|||
#endif |
|||
|
|||
// Check if we are out of the buffer |
|||
if (any(int2(positionSS.xy) > int2(bufferSize)) |
|||
|| any(positionSS.xy < 0) |
|||
) |
|||
{ |
|||
hitSuccessful = false; |
|||
break; |
|||
} |
|||
|
|||
++iteration; |
|||
} |
|||
|
|||
hit.linearDepth = 1 / positionSS.z; |
|||
hit.positionNDC = float2(positionSS.xy) / float2(bufferSize); |
|||
hit.positionSS = uint2(positionSS.xy); |
|||
|
|||
if (hit.linearDepth > (1 / invHiZDepth) + SSRT_SETTING(RayDepthSuccessBias, SSRTID)) |
|||
hitSuccessful = false; |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
DebugComputeCommonOutput(input.rayDirWS, hitSuccessful, hit); |
|||
DebugComputeHiZOutput( |
|||
iteration, |
|||
startPositionSS, |
|||
raySS, |
|||
SSRT_SETTING(RayMaxIterations, SSRTID), |
|||
debugLoopMipMaxUsedLevel, |
|||
maxMipLevel, |
|||
intersectionKind, |
|||
hit |
|||
); |
|||
|
|||
if (input.debug) |
|||
{ |
|||
// Build debug structure |
|||
ScreenSpaceTracingDebug debug; |
|||
ZERO_INITIALIZE(ScreenSpaceTracingDebug, debug); |
|||
|
|||
debug.tracingModel = REFRACTIONSSRAYMODEL_HI_Z; |
|||
debug.loopStartPositionSSX = uint(startPositionSS.x); |
|||
debug.loopStartPositionSSY = uint(startPositionSS.y); |
|||
debug.loopStartLinearDepth = 1 / startPositionSS.z; |
|||
debug.loopRayDirectionSS = raySS; |
|||
debug.loopMipLevelMax = debugLoopMipMaxUsedLevel; |
|||
debug.loopIterationMax = iteration; |
|||
debug.iterationPositionSS = debugIterationPositionSS; |
|||
debug.iterationMipLevel = debugIterationMipLevel; |
|||
debug.iteration = debugIteration; |
|||
debug.iterationLinearDepthBuffer = debugIterationLinearDepthBuffer; |
|||
debug.iterationIntersectionKind = debugIterationIntersectionKind; |
|||
debug.iterationCellSizeW = debugIterationCellSize.x; |
|||
debug.iterationCellSizeH = debugIterationCellSize.y; |
|||
debug.endHitSuccess = hitSuccessful; |
|||
debug.endLinearDepth = hit.linearDepth; |
|||
debug.endPositionSSX = hit.positionSS.x; |
|||
debug.endPositionSSY = hit.positionSS.y; |
|||
|
|||
_DebugScreenSpaceTracingData[0] = debug; |
|||
} |
|||
#endif |
|||
|
|||
return hitSuccessful; |
|||
} |
|||
|
|||
#undef SSRT_SETTING |
|||
#undef SSRT_FUNC |
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: aee64cd8304a9fa46a29f5533aa77b29 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine.Assertions; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class BufferPyramidProcessor |
|||
{ |
|||
static readonly int _Size = Shader.PropertyToID("_Size"); |
|||
static readonly int _Source = Shader.PropertyToID("_Source"); |
|||
static readonly int _Result = Shader.PropertyToID("_Result"); |
|||
static readonly int _SrcSize = Shader.PropertyToID("_SrcSize"); |
|||
const int k_DepthBlockSize = 4; |
|||
|
|||
GPUCopy m_GPUCopy; |
|||
TexturePadding m_TexturePadding; |
|||
ComputeShader m_ColorPyramidCS; |
|||
int m_ColorPyramidKernel; |
|||
|
|||
ComputeShader m_DepthPyramidCS; |
|||
int[] m_DepthKernels = null; |
|||
int depthKernel8 { get { return m_DepthKernels[0]; } } |
|||
int depthKernel1 { get { return m_DepthKernels[1]; } } |
|||
|
|||
List<RenderTexture> m_RenderColorPyramid_CastTmp = new List<RenderTexture>(); |
|||
|
|||
public BufferPyramidProcessor( |
|||
ComputeShader colorPyramidCS, |
|||
ComputeShader depthPyramidCS, |
|||
GPUCopy gpuCopy, |
|||
TexturePadding texturePadding |
|||
) |
|||
{ |
|||
m_ColorPyramidCS = colorPyramidCS; |
|||
m_ColorPyramidKernel = m_ColorPyramidCS.FindKernel("KMain"); |
|||
|
|||
m_DepthPyramidCS = depthPyramidCS; |
|||
m_GPUCopy = gpuCopy; |
|||
m_DepthKernels = new int[] |
|||
{ |
|||
m_DepthPyramidCS.FindKernel("KDepthDownSample8"), |
|||
m_DepthPyramidCS.FindKernel("KDepthDownSample1") |
|||
}; |
|||
|
|||
m_TexturePadding = texturePadding; |
|||
} |
|||
|
|||
public void RenderDepthPyramid( |
|||
int width, int height, |
|||
CommandBuffer cmd, |
|||
RTHandle sourceTexture, |
|||
RTHandle targetTexture, |
|||
List<RTHandle> mips, |
|||
int lodCount, |
|||
Vector2 scale |
|||
) |
|||
{ |
|||
m_GPUCopy.SampleCopyChannel_xyzw2x(cmd, sourceTexture, targetTexture, new RectInt(0, 0, width, height)); |
|||
|
|||
RTHandle src = targetTexture; |
|||
for (var i = 0; i < lodCount; i++) |
|||
{ |
|||
RTHandle dest = mips[i]; |
|||
|
|||
var srcMip = new RectInt(0, 0, width >> i, height >> i); |
|||
var dstMip = new RectInt(0, 0, srcMip.width >> 1, srcMip.height >> 1); |
|||
|
|||
var kernel = depthKernel1; |
|||
var kernelSize = 1; |
|||
var srcWorkMip = srcMip; |
|||
var dstWorkMip = dstMip; |
|||
|
|||
if (dstWorkMip.width >= 8 && dstWorkMip.height >= 8) |
|||
{ |
|||
srcWorkMip.width = Mathf.CeilToInt(srcWorkMip.width / 16.0f) * 16; |
|||
srcWorkMip.height = Mathf.CeilToInt(srcWorkMip.height / 16.0f) * 16; |
|||
dstWorkMip.width = srcWorkMip.width >> 1; |
|||
dstWorkMip.height = srcWorkMip.height >> 1; |
|||
|
|||
m_TexturePadding.Pad(cmd, src, srcMip, srcWorkMip); |
|||
kernel = depthKernel8; |
|||
kernelSize = 8; |
|||
} |
|||
else |
|||
{ |
|||
m_TexturePadding.Pad(cmd, src, srcMip, new RectInt(0, 0, src.rt.width, src.rt.height)); |
|||
} |
|||
|
|||
cmd.SetComputeTextureParam(m_DepthPyramidCS, kernel, _Source, src); |
|||
cmd.SetComputeTextureParam(m_DepthPyramidCS, kernel, _Result, dest); |
|||
cmd.SetComputeVectorParam(m_DepthPyramidCS, _SrcSize, new Vector4( |
|||
srcWorkMip.width, srcWorkMip.height, |
|||
(1.0f / srcWorkMip.width) * scale.x, (1.0f / srcWorkMip.height) * scale.y) |
|||
); |
|||
|
|||
cmd.DispatchCompute( |
|||
m_DepthPyramidCS, |
|||
kernel, |
|||
Mathf.CeilToInt(dstWorkMip.width / (float)kernelSize), |
|||
Mathf.CeilToInt(dstWorkMip.height / (float)kernelSize), |
|||
1 |
|||
); |
|||
|
|||
var dstMipWidthToCopy = Mathf.Min(dest.rt.width, dstWorkMip.width); |
|||
var dstMipHeightToCopy = Mathf.Min(dest.rt.height, dstWorkMip.height); |
|||
|
|||
// If we could bind texture mips as UAV we could avoid this copy...(which moreover copies more than the needed viewport if not fullscreen)
|
|||
cmd.CopyTexture(mips[i], 0, 0, 0, 0, dstMipWidthToCopy, dstMipHeightToCopy, targetTexture, 0, i + 1, 0, 0); |
|||
src = dest; |
|||
} |
|||
} |
|||
|
|||
public void RenderColorPyramid( |
|||
HDCamera hdCamera, |
|||
CommandBuffer cmd, |
|||
RTHandle sourceTexture, |
|||
RTHandle targetTexture, |
|||
List<RTHandle> mips, |
|||
int lodCount, |
|||
Vector2 scale |
|||
) |
|||
{ |
|||
// Copy mip 0
|
|||
// Here we blit a "camera space" texture into a square texture but we want to keep the original viewport.
|
|||
// Other BlitCameraTexture version will setup the viewport based on the destination RT scale (square here) so we need override it here.
|
|||
HDUtils.BlitCameraTexture(cmd, hdCamera, sourceTexture, targetTexture, new Rect(0.0f, 0.0f, hdCamera.actualWidth, hdCamera.actualHeight)); |
|||
|
|||
m_RenderColorPyramid_CastTmp.Clear(); |
|||
for (var i = 0 ; i < mips.Count; ++i) |
|||
m_RenderColorPyramid_CastTmp.Add(mips[i]); |
|||
RenderColorPyramidMips( |
|||
new RectInt(0, 0, hdCamera.actualWidth, hdCamera.actualHeight), |
|||
cmd, |
|||
targetTexture, |
|||
m_RenderColorPyramid_CastTmp, |
|||
lodCount, |
|||
scale |
|||
); |
|||
} |
|||
|
|||
public void RenderColorPyramid( |
|||
RectInt srcRect, |
|||
CommandBuffer cmd, |
|||
Texture sourceTexture, |
|||
RenderTexture targetTexture, |
|||
List<RenderTexture> mips, |
|||
int lodCount |
|||
) |
|||
{ |
|||
Assert.AreEqual(0, srcRect.x, "Offset are not supported"); |
|||
Assert.AreEqual(0, srcRect.y, "Offset are not supported"); |
|||
Assert.IsTrue(srcRect.width > 0); |
|||
Assert.IsTrue(srcRect.height > 0); |
|||
|
|||
var scale = new Vector2( |
|||
sourceTexture.width / (float)srcRect.width, |
|||
sourceTexture.height / (float)srcRect.height |
|||
); |
|||
|
|||
cmd.Blit(sourceTexture, targetTexture, scale, Vector2.zero); |
|||
|
|||
RenderColorPyramidMips( |
|||
srcRect, |
|||
cmd, |
|||
targetTexture, |
|||
mips, |
|||
lodCount, |
|||
scale |
|||
); |
|||
} |
|||
|
|||
void RenderColorPyramidMips( |
|||
RectInt srcRect, |
|||
CommandBuffer cmd, |
|||
RenderTexture targetTexture, |
|||
List<RenderTexture> mips, |
|||
int lodCount, |
|||
Vector2 scale |
|||
) |
|||
{ |
|||
Assert.AreEqual(0, srcRect.x, "Offset are not supported"); |
|||
Assert.AreEqual(0, srcRect.y, "Offset are not supported"); |
|||
Assert.IsTrue(srcRect.width > 0); |
|||
Assert.IsTrue(srcRect.height > 0); |
|||
|
|||
var src = targetTexture; |
|||
for (var i = 0; i < lodCount; i++) |
|||
{ |
|||
var dest = mips[i]; |
|||
|
|||
var srcMip = new RectInt(0, 0, srcRect.width >> i, srcRect.height >> i); |
|||
//var dstMip = new RectInt(0, 0, srcMip.width >> 1, srcMip.height >> 1);
|
|||
var srcWorkMip = new RectInt( |
|||
0, |
|||
0, |
|||
Mathf.CeilToInt(srcMip.width / 16.0f) * 16, |
|||
Mathf.CeilToInt(srcMip.height / 16.0f) * 16 |
|||
); |
|||
var dstWorkMip = new RectInt(0, 0, srcWorkMip.width >> 1, srcWorkMip.height >> 1); |
|||
|
|||
m_TexturePadding.Pad(cmd, src, srcMip, srcWorkMip); |
|||
|
|||
// TODO: Add proper stereo support to the compute job
|
|||
|
|||
cmd.SetComputeTextureParam(m_ColorPyramidCS, m_ColorPyramidKernel, _Source, src); |
|||
cmd.SetComputeTextureParam(m_ColorPyramidCS, m_ColorPyramidKernel, _Result, dest); |
|||
// _Size is used as a scale inside the whole render target so here we need to keep the full size (and not the scaled size depending on the current camera)
|
|||
cmd.SetComputeVectorParam( |
|||
m_ColorPyramidCS, |
|||
_Size, |
|||
new Vector4(dest.width, dest.height, 1f / dest.width, 1f / dest.height) |
|||
); |
|||
cmd.DispatchCompute( |
|||
m_ColorPyramidCS, |
|||
m_ColorPyramidKernel, |
|||
dstWorkMip.width / 8, |
|||
dstWorkMip.height / 8, |
|||
1 |
|||
); |
|||
|
|||
var dstMipWidthToCopy = Mathf.Min(dest.width, dstWorkMip.width); |
|||
var dstMipHeightToCopy = Mathf.Min(dest.height, dstWorkMip.height); |
|||
|
|||
// If we could bind texture mips as UAV we could avoid this copy...(which moreover copies more than the needed viewport if not fullscreen)
|
|||
cmd.CopyTexture( |
|||
mips[i], |
|||
0, 0, 0, 0, |
|||
dstMipWidthToCopy, dstMipHeightToCopy, targetTexture, 0, i + 1, 0, 0 |
|||
); |
|||
|
|||
src = dest; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5555ed542465a3a42aa9f58eccc62c68 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue