浏览代码

(wip) SSR for deferred

Toggle for SSR
/main
Frédéric Vauchelles 7 年前
当前提交
b6f0098d
共有 17 个文件被更改,包括 202 次插入168 次删除
  1. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader
  3. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDScreenSpaceReflectionEditor.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ScreenSpaceLightingEditor.cs
  5. 31
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs
  6. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  7. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  8. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/Deferred.compute
  9. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  10. 13
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceReflection.cs
  11. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl
  12. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
  13. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl
  14. 230
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  15. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
  16. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader
  17. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs


{
// Used to debug SSRay model
// 1x32 bits
public Lit.SSRayModel tracingModel;
public Lit.ProjectionModel tracingModel;
// 6x32 bits
public uint loopStartPositionSSX; // Proxy, HiZ

public static GUIContent[] debugScreenSpaceTracingHiZStrings = null;
public static int[] debugScreenSpaceTracingHiZValues = null;
Lit.SSRayModel m_LastSSRayModel = Lit.SSRayModel.None;
Lit.ProjectionModel m_LastProjectionModel = Lit.ProjectionModel.None;
ScreenSpaceTracingDebug m_ScreenSpaceTracingDebugData;
public ScreenSpaceTracingDebug screenSpaceTracingDebugData
{

m_ScreenSpaceTracingDebugData = value;
if (m_LastSSRayModel != m_ScreenSpaceTracingDebugData.tracingModel)
if (m_LastProjectionModel != m_ScreenSpaceTracingDebugData.tracingModel)
m_LastSSRayModel = m_ScreenSpaceTracingDebugData.tracingModel;
RefreshScreenSpaceTracingDebug<Lit.SSRayModel>(null, m_LastSSRayModel);
m_LastProjectionModel = m_ScreenSpaceTracingDebugData.tracingModel;
RefreshScreenSpaceTracingDebug<Lit.ProjectionModel>(null, m_LastProjectionModel);
if (m_ScreenSpaceTracingDebugData.tracingModel != Lit.SSRayModel.HiZ)
if (m_ScreenSpaceTracingDebugData.tracingModel != Lit.ProjectionModel.HiZ)
{
showSSRayDepthPyramid = false;
showSSRayGrid = false;

switch (screenSpaceTracingDebugData.tracingModel)
{
case Lit.SSRayModel.Proxy:
case Lit.ProjectionModel.Proxy:
{
debugSettingsContainer.children.Add(
new DebugUI.EnumField { displayName = "Debug Mode", getter = GetDebugLightingSubMode, setter = SetScreenSpaceTracingDebugMode, enumNames = debugScreenSpaceTracingProxyStrings, enumValues = debugScreenSpaceTracingProxyValues, onValueChanged = RefreshScreenSpaceTracingDebug }

);
break;
}
case Lit.SSRayModel.HiZ:
case Lit.ProjectionModel.HiZ:
{
debugSettingsContainer.children.Insert(1, new DebugUI.Value { displayName = string.Empty, getter = () => "Press PageUp/PageDown to Increase/Decrease the HiZ step." });
debugSettingsContainer.children.Add(

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugFullScreen.shader


float cellSDF = 0;
float debugLinearDepth = 0;
if (debug.tracingModel == SSRAYMODEL_HI_Z)
if (debug.tracingModel == PROJECTION_MODEL_HI_Z)
{
const uint2 iterationCellSize = uint2(debug.iterationCellSizeW, debug.iterationCellSizeH);
const float hasData = iterationCellSize.x != 0 || iterationCellSize.y != 0;

18
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDScreenSpaceReflectionEditor.cs


[VolumeComponentEditor(typeof(ScreenSpaceReflection))]
public class HDScreenSpaceReflectionEditor : ScreenSpaceLightingEditor
{
SerializedDataParameter m_DeferredProjectionModel;
public override void OnEnable()
{
base.OnEnable();
var o = new PropertyFetcher<ScreenSpaceReflection>(serializedObject);
m_DeferredProjectionModel = Unpack(o.Find(x => x.deferredProjectionModel));
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.LabelField(CoreEditorUtils.GetContent("Deferred Settings"));
PropertyField(m_DeferredProjectionModel, CoreEditorUtils.GetContent("Projection Model"));
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ScreenSpaceLightingEditor.cs


public override void OnEnable()
{
var o = new PropertyFetcher<ScreenSpaceRefraction>(serializedObject);
var o = new PropertyFetcher<ScreenSpaceLighting>(serializedObject);
m_RayMinLevel = Unpack(o.Find(x => x.rayMinLevel));
m_RayMaxLevel = Unpack(o.Find(x => x.rayMaxLevel));

31
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs


public static GUIContent UVBaseMappingText = new GUIContent("Base UV mapping", "");
public static GUIContent texWorldScaleText = new GUIContent("World scale", "Tiling factor applied to Planar/Trilinear mapping");
// SSReflection
public static GUIContent reflectionSSRayModelText = new GUIContent("SSRay Model", "Screen Space Ray Model");
public static GUIContent reflectionProjectionModelText = new GUIContent("Projection Model", "Screen Space Projection Model");
// Details
public static string detailText = "Detail Inputs";

// Transparency
public static string refractionModelText = "Refraction Model";
public static GUIContent refractionSSRayModelText = new GUIContent("SSRay Model", "Screen Space Ray Model");
public static GUIContent refractionProjectionModelText = new GUIContent("SSRay Model", "Screen Space Ray Model");
public static GUIContent refractionIorText = new GUIContent("Index of refraction", "Index of refraction");
public static GUIContent refractionThicknessText = new GUIContent("Refraction Thickness", "Thickness for rough refraction");
public static GUIContent refractionThicknessMultiplierText = new GUIContent("Refraction Thickness multiplier (m)", "Thickness multiplier");

protected const string kThicknessMultiplier = "_ThicknessMultiplier";
protected MaterialProperty refractionModel = null;
protected const string kRefractionModel = "_RefractionModel";
protected MaterialProperty refractionSSRayModel = null;
protected const string kRefractionSSRayModel = "_RefractionSSRayModel";
protected MaterialProperty reflectionSSRayModel = null;
protected const string kReflectionSSRayModel = "_ReflectionSSRayModel";
protected MaterialProperty refractionProjectionModel = null;
protected const string kRefractionProjectionModel = "_RefractionProjectionModel";
protected MaterialProperty reflectionProjectionModel = null;
protected const string kReflectionProjectionModel = "_ReflectionProjectionModel";
protected override bool showBlendModePopup
{

// Transparency
refractionModel = FindProperty(kRefractionModel, props, false);
refractionSSRayModel = FindProperty(kRefractionSSRayModel, props, false);
reflectionSSRayModel = FindProperty(kReflectionSSRayModel, props, false);
refractionProjectionModel = FindProperty(kRefractionProjectionModel, props, false);
reflectionProjectionModel = FindProperty(kReflectionProjectionModel, props, false);
transmittanceColor = FindProperty(kTransmittanceColor, props, false);
transmittanceColorMap = FindProperty(kTransmittanceColorMap, props, false);
atDistance = FindProperty(kATDistance, props, false);

var mode = (Lit.RefractionModel)refractionModel.floatValue;
if (mode != Lit.RefractionModel.None)
{
m_MaterialEditor.ShaderProperty(refractionSSRayModel, Styles.refractionSSRayModelText);
m_MaterialEditor.ShaderProperty(refractionProjectionModel, Styles.refractionProjectionModelText);
m_MaterialEditor.ShaderProperty(ior, Styles.refractionIorText);
blendMode.floatValue = (float)BlendMode.Alpha;

}
else if (surfaceTypeValue == SurfaceType.Opaque)
{
m_MaterialEditor.ShaderProperty(reflectionSSRayModel, Styles.reflectionSSRayModelText);
m_MaterialEditor.ShaderProperty(reflectionProjectionModel, Styles.reflectionProjectionModelText);
}
}

CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_SPECULAR_COLOR", materialId == BaseLitGUI.MaterialId.LitSpecular);
var refractionModelValue = (Lit.RefractionModel)material.GetFloat(kRefractionModel);
var refractionSSRayModelValue = (Lit.SSRayModel)material.GetFloat(kRefractionSSRayModel);
var refractionProjectionModelValue = (Lit.ProjectionModel)material.GetFloat(kRefractionProjectionModel);
CoreUtils.SetKeyword(material, "_REFRACTION_SSRAY_PROXY", (refractionSSRayModelValue == Lit.SSRayModel.Proxy) && canHaveRefraction);
CoreUtils.SetKeyword(material, "_REFRACTION_SSRAY_HIZ", (refractionSSRayModelValue == Lit.SSRayModel.HiZ) && canHaveRefraction);
// SS Reflection
var reflectionSSRayModelValue = (Lit.SSRayModel)material.GetFloat(kReflectionSSRayModel);
CoreUtils.SetKeyword(material, "_REFLECTION_SSRAY_PROXY", (reflectionSSRayModelValue == Lit.SSRayModel.Proxy));
CoreUtils.SetKeyword(material, "_REFLECTION_SSRAY_HIZ", (reflectionSSRayModelValue == Lit.SSRayModel.HiZ));
CoreUtils.SetKeyword(material, "_REFRACTION_SSRAY_PROXY", (refractionProjectionModelValue == Lit.ProjectionModel.Proxy) && canHaveRefraction);
CoreUtils.SetKeyword(material, "_REFRACTION_SSRAY_HIZ", (refractionProjectionModelValue == Lit.ProjectionModel.HiZ) && canHaveRefraction);
}
}
} // namespace UnityEditor

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


hdCamera.SetupGlobalParams(cmd, m_Time, m_LastTime);
if (m_FrameSettings.enableStereo) hdCamera.SetupGlobalStereoParams(cmd);
cmd.SetGlobalInt(HDShaderIDs._SSReflectionEnabled, m_FrameSettings.enableSSR ? 1 : 0);
var previousDepthPyramidRT = hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.DepthPyramid);
if (previousDepthPyramidRT != null)
{

Mathf.Log(Mathf.Min(previousColorPyramidRT.rt.width, previousColorPyramidRT.rt.height), 2),
0.0f
));
}
}
}
}

}
if (camera.cameraType != CameraType.Reflection)
{
// Frame settings state was updated by previous render, we must recalculate it
FrameSettings.InitializeFrameSettings(camera, m_Asset.GetRenderPipelineSettings(), srcFrameSettings, ref m_FrameSettings);
}
// Init material if needed
// TODO: this should be move outside of the camera loop but we have no command buffer, ask details to Tim or Julien to do this

// Assign -1 in tracing model to notifiy we took the data.
// When debugging in forward, we want only the first time the pixel is drawn
data.tracingModel = (Lit.SSRayModel)(-1);
data.tracingModel = (Lit.ProjectionModel)(-1);
m_DebugScreenSpaceTracingDataArray[0] = data;
m_DebugScreenSpaceTracingData.SetData(m_DebugScreenSpaceTracingDataArray);
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _SSReflectionRayMaxIterations = Shader.PropertyToID("_SSReflectionRayMaxIterations");
public static readonly int _SSReflectionRayDepthSuccessBias = Shader.PropertyToID("_SSReflectionRayDepthSuccessBias");
public static readonly int _SSReflectionInvScreenWeightDistance = Shader.PropertyToID("_SSReflectionInvScreenWeightDistance");
public static readonly int _SSReflectionProjectionModel = Shader.PropertyToID("_SSReflectionProjectionModel");
public static readonly int _SSReflectionEnabled = Shader.PropertyToID("_SSReflectionEnabled");
public static readonly int _VelocityTexture = Shader.PropertyToID("_VelocityTexture");
public static readonly int _ShadowMaskTexture = Shader.PropertyToID("_ShadowMaskTexture");

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/Deferred.compute


#define LIGHTLOOP_TILE_PASS 1
// deferred opaque always use FPTL
#define USE_FPTL_LIGHTLIST 1
#define _REFLECTION_SSRAY_PROXY
//#pragma enable_d3d11_debug_symbols

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


{
var camera = hdCamera.camera;
var ssReflection = VolumeManager.instance.stack.GetComponent<ScreenSpaceReflection>() ?? ScreenSpaceReflection.@default;
// Compute path
if (m_FrameSettings.lightLoopSettings.enableTileAndCluster && m_FrameSettings.lightLoopSettings.enableComputeLightEvaluation)
{

// TODO: Is it possible to setup this outside the loop ? Can figure out how, get this: Property (specularLightingUAV) at kernel index (21) is not set
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs.specularLightingUAV, colorBuffers[0]);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs.diffuseLightingUAV, colorBuffers[1]);
cmd.SetComputeIntParam(deferredComputeShader, HDShaderIDs._SSReflectionProjectionModel, (int)ssReflection.deferredProjectionModel.value);
if (debugDisplaySettings.lightingDebugSettings.debugLightingMode == DebugLightingMode.ScreenSpaceTracingReflection)
cmd.SetComputeBufferParam(deferredComputeShader, kernel, HDShaderIDs._DebugScreenSpaceTracingData, debugSSTBuffer);

13
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceReflection.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public sealed class LitProjectionModelParameter : VolumeParameter<Lit.ProjectionModel> { }
[Serializable]
public class ScreenSpaceReflection : ScreenSpaceLighting
{
static ScreenSpaceReflection s_Default = null;

return s_Default;
}
}
int m_DeferredProjectionModel;
public LitProjectionModelParameter deferredProjectionModel = new LitProjectionModelParameter();
protected override void FetchIDs(
out int rayMinLevelID,

rayMaxIterationsID = HDShaderIDs._SSReflectionRayMaxIterations;
rayDepthSuccessBiasID = HDShaderIDs._SSReflectionRayDepthSuccessBias;
screenWeightDistanceID = HDShaderIDs._SSReflectionInvScreenWeightDistance;
}
public override void PushShaderParameters(CommandBuffer cmd)
{
base.PushShaderParameters(cmd);
cmd.SetGlobalInt(HDShaderIDs._SSReflectionProjectionModel, (int)deferredProjectionModel.value);
}
}
}

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl


float2 rayOriginNDC = ComputeNormalizedDeviceCoordinates(input.rayOriginWS, GetWorldToHClipMatrix());
uint2 rayOriginSS = uint2(rayOriginNDC * _ScreenSize.xy);
debug.tracingModel = SSRAYMODEL_PROXY;
debug.tracingModel = PROJECTION_MODEL_PROXY;
debug.loopStartPositionSSX = rayOriginSS.x;
debug.loopStartPositionSSY = rayOriginSS.y;
debug.loopStartLinearDepth = rayOriginCS.w;

ScreenSpaceTracingDebug debug;
ZERO_INITIALIZE(ScreenSpaceTracingDebug, debug);
debug.tracingModel = SSRAYMODEL_HI_Z;
debug.tracingModel = PROJECTION_MODEL_HI_Z;
debug.loopStartPositionSSX = uint(startPositionSS.x);
debug.loopStartPositionSSY = uint(startPositionSS.y);
debug.loopStartLinearDepth = 1 / startPositionSS.z;

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs


};
[GenerateHLSL]
public enum SSRayModel
public enum ProjectionModel
{
None = 0,
Proxy = 1,

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl


#define MATERIALFEATUREFLAGS_LIT_CLEAR_COAT (64)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+SSRayModel: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+ProjectionModel: static fields
#define SSRAYMODEL_NONE (0)
#define SSRAYMODEL_PROXY (1)
#define SSRAYMODEL_HI_Z (2)
#define PROJECTION_MODEL_NONE (0)
#define PROJECTION_MODEL_PROXY (1)
#define PROJECTION_MODEL_HI_Z (2)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+HiZIntersectionKind: static fields

230
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


// Helper functions/variable specific to this material
//-----------------------------------------------------------------------------
#if HAS_SSREFLECTION || HAS_REFRACTION
#include "HDRP/Lighting/LightDefinition.cs.hlsl"
#include "HDRP/Lighting/Reflection/VolumeProjection.hlsl"
#endif
// SSReflection
#include "HDRP/Lighting/LightDefinition.cs.hlsl"
#include "HDRP/Lighting/Reflection/VolumeProjection.hlsl"
#define SSRTID Reflection
#include "HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl"
#undef SSRTID
#if HAS_REFRACTION
#include "CoreRP/ShaderLibrary/Refraction.hlsl"

#elif defined(_REFRACTION_SPHERE)
#define REFRACTION_MODEL(V, posInputs, bsdfData) RefractionModelSphere(V, posInputs.positionWS, bsdfData.normalWS, bsdfData.ior, bsdfData.thickness)
#endif
#if defined(_REFRACTION_SSRAY_PROXY)
#define REFRACTION_SSRAY_IN ScreenSpaceProxyRaycastInput
#define REFRACTION_SSRAY_QUERY(input, hit) ScreenSpaceProxyRaycastRefraction(input, hit)
#elif defined(_REFRACTION_SSRAY_HIZ)
#define REFRACTION_SSRAY_IN ScreenSpaceHiZRaymarchInput
#define REFRACTION_SSRAY_QUERY(input, hit) ScreenSpaceHiZRaymarchRefraction(input, hit)
#endif
#endif
#if HAS_SSREFLECTION
# define SSRTID Reflection
# include "HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl"
# undef SSRTID
# if defined(_REFLECTION_SSRAY_PROXY)
# define REFLECTION_SSRAY_IN ScreenSpaceProxyRaycastInput
# define REFLECTION_SSRAY_QUERY(input, hit) ScreenSpaceProxyRaycastReflection(input, hit)
# elif defined(_REFLECTION_SSRAY_HIZ)
# define REFLECTION_SSRAY_IN ScreenSpaceHiZRaymarchInput
# define REFLECTION_SSRAY_QUERY(input, hit) ScreenSpaceHiZRaymarchReflection(input, hit)
# endif
#endif
// This method allows us to know at compile time what material features should be removed from the code by Tile (Indepenently of the value of material feature flag per pixel).

return lighting;
}
#endif
#if !HAS_SSREFLECTION
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION)
{
return lighting;
}
#endif
// Setup macro helpers
// Choose projection model
int projectionModel = PROJECTION_MODEL_NONE;
# define SSRAY_INPUT REFRACTION_SSRAY_IN
# define SSRAY_QUERY REFRACTION_SSRAY_QUERY
# if defined(_REFRACTION_SSRAY_HIZ)
# define SSRAY_MODEL SSRAYMODEL_HI_Z
# elif defined(_REFRACTION_SSRAY_PROXY)
# define SSRAY_MODEL SSRAYMODEL_PROXY
# endif
#elif HAS_SSREFLECTION
# define SSRAY_INPUT REFLECTION_SSRAY_IN
# define SSRAY_QUERY REFLECTION_SSRAY_QUERY
# if defined(_REFLECTION_SSRAY_HIZ)
# define SSRAY_MODEL SSRAYMODEL_HI_Z
# elif defined(_REFLECTION_SSRAY_PROXY)
# define SSRAY_MODEL SSRAYMODEL_PROXY
# endif
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
{
#if defined(_REFRACTION_SSRAY_HIZ)
projectionModel = PROJECTION_MODEL_HI_Z;
#else defined(_REFRACTION_SSRAY_PROXY)
projectionModel = PROJECTION_MODEL_PROXY;
#endif
}
#else
if (_SSReflectionEnabled != 0)
projectionModel = _SSReflectionProjectionModel;
#if defined(SSRAY_INPUT) && defined(SSRAY_QUERY) && defined(SSRAY_MODEL)
if (projectionModel == PROJECTION_MODEL_NONE)
return lighting;
// -------------------------------
// Initialize screen space tracing
// -------------------------------

# if DEBUG_DISPLAY
#if DEBUG_DISPLAY
# endif
#endif
// Refraction process:
// 1. Depending on the shape model, we calculate the refracted point in world space and the optical depth
// 2. We calculate the screen space position of the refracted point
// 3. If this point is available (ie: in color buffer and point is not in front of the object)
// a. Get the corresponding color depending on the roughness from the gaussian pyramid of the color buffer
// b. Multiply by the transmittance for absorption (depends on the optical depth)
// Refraction process:
// 1. Depending on the shape model, we calculate the refracted point in world space and the optical depth
// 2. We calculate the screen space position of the refracted point
// 3. If this point is available (ie: in color buffer and point is not in front of the object)
// a. Get the corresponding color depending on the roughness from the gaussian pyramid of the color buffer
// b. Multiply by the transmittance for absorption (depends on the optical depth)
rayOriginWS = preLightData.transparentPositionWS;
rayDirWS = preLightData.transparentRefractV;

}
#if DEBUG_DISPLAY
bool debug = _DebugLightingMode == debugMode
&& !any(int2(_MouseClickPixelCoord.xy) - int2(posInput.positionSS));
bool debug = _DebugLightingMode == debugMode
&& !any(int2(_MouseClickPixelCoord.xy) - int2(posInput.positionSS));
ScreenSpaceRayHit hit;
ZERO_INITIALIZE(ScreenSpaceRayHit, hit);
bool hitSuccessful = false;
// Initialize screen space tracing
SSRAY_INPUT ssRayInput;
ZERO_INITIALIZE(SSRAY_INPUT, ssRayInput);
// -------------------------------
// Proxy raycasting
// -------------------------------
if (projectionModel == PROJECTION_MODEL_PROXY)
{
ScreenSpaceProxyRaycastInput ssRayInput;
ZERO_INITIALIZE(ScreenSpaceProxyRaycastInput, ssRayInput);
// Common initialization
ssRayInput.rayOriginWS = rayOriginWS;
ssRayInput.rayDirWS = rayDirWS;
ssRayInput.rayOriginWS = rayOriginWS;
ssRayInput.rayDirWS = rayDirWS;
ssRayInput.debug = debug;
ssRayInput.debug = debug;
#endif
ssRayInput.proxyData = envLightData;
#if HAS_REFRACTION
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
hitSuccessful = ScreenSpaceProxyRaycastRefraction(ssRayInput, hit);
else
// Algorithm specific initialization
#if SSRAY_MODEL == SSRAYMODEL_HI_Z
ssRayInput.maxIterations = uint(-1);
#elif SSRAY_MODEL == SSRAYMODEL_PROXY
ssRayInput.proxyData = envLightData;
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION)
hitSuccessful = ScreenSpaceProxyRaycastReflection(ssRayInput, hit);
}
// -------------------------------
// HiZ raymarching
// -------------------------------
else if (projectionModel == PROJECTION_MODEL_HI_Z)
{
ScreenSpaceHiZRaymarchInput ssRayInput;
ZERO_INITIALIZE(ScreenSpaceHiZRaymarchInput, ssRayInput);
ssRayInput.rayOriginWS = rayOriginWS;
ssRayInput.rayDirWS = rayDirWS;
#if DEBUG_DISPLAY
ssRayInput.debug = debug;
ssRayInput.maxIterations = uint(-1);
// Perform ray query
ScreenSpaceRayHit hit;
ZERO_INITIALIZE(ScreenSpaceRayHit, hit);
bool hitSuccessful = SSRAY_QUERY(ssRayInput, hit);
#if HAS_REFRACTION
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
hitSuccessful = ScreenSpaceHiZRaymarchRefraction(ssRayInput, hit);
else
#endif
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION)
hitSuccessful = ScreenSpaceHiZRaymarchReflection(ssRayInput, hit);
}
// Debug screen space tracing
// Debug screen space tracing
if (_DebugLightingMode == debugMode
&& _DebugLightingSubMode != DEBUGSCREENSPACETRACING_COLOR)
{
float weight = 1.0;
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
if (_DebugLightingMode == debugMode
&& _DebugLightingSubMode != DEBUGSCREENSPACETRACING_COLOR)
{
float weight = 1.0;
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
lighting.specularTransmitted = hit.debugOutput;
lighting.specularTransmitted = hit.debugOutput;
return lighting;
}
return lighting;
}
if (!hitSuccessful)
return lighting;
if (!hitSuccessful)
return lighting;
// -------------------------------
// Resolve weight and color
// -------------------------------
weightNDC = weightNDC * weightNDC * (3 - 2 * weightNDC);
float weight = weightNDC.x * weightNDC.y;
weightNDC = weightNDC * weightNDC * (3 - 2 * weightNDC);
float weight = weightNDC.x * weightNDC.y;
float hitDeviceDepth = LOAD_TEXTURE2D_LOD(_DepthPyramidTexture, hit.positionSS, 0).r;
float hitLinearDepth = LinearEyeDepth(hitDeviceDepth, _ZBufferParams);
float hitDeviceDepth = LOAD_TEXTURE2D_LOD(_DepthPyramidTexture, hit.positionSS, 0).r;
float hitLinearDepth = LinearEyeDepth(hitDeviceDepth, _ZBufferParams);
// Exit if texel is out of color buffer
// Or if the texel is from an object in front of the object
if (hitLinearDepth < posInput.linearDepth
|| weight == 0)
{
// Do nothing and don't update the hierarchy weight so we can fall back on refraction probe
return lighting;
}
// Exit if texel is out of color buffer
// Or if the texel is from an object in front of the object
if (hitLinearDepth < posInput.linearDepth
|| weight == 0)
{
// Do nothing and don't update the hierarchy weight so we can fall back on refraction probe
return lighting;
}
UpdateLightingHierarchyWeights(hierarchyWeight, weight); // Shouldn't be needed, but safer in case we decide to change hierarchy priority
UpdateLightingHierarchyWeights(hierarchyWeight, weight); // Shouldn't be needed, but safer in case we decide to change hierarchy priority
float3 preLD = SAMPLE_TEXTURE2D_LOD(
_ColorPyramidTexture,
s_trilinear_clamp_sampler,
hit.positionNDC * _ColorPyramidScale.xy,
float3 preLD = SAMPLE_TEXTURE2D_LOD(
_ColorPyramidTexture,
s_trilinear_clamp_sampler,
hit.positionNDC * _ColorPyramidScale.xy,
).rgb;
).rgb;
float3 F = preLightData.specularFGD;
float3 F = preLightData.specularFGD;
// -------------------------------
// Assign color
// -------------------------------
lighting.specularTransmitted = (1.0 - F) * preLD.rgb * preLightData.transparentTransmittance * weight;
lighting.specularTransmitted = (1.0 - F) * preLD.rgb * preLightData.transparentTransmittance * weight;
#endif
// -------------------------------
// Cleanup macros
// -------------------------------
#undef SSRAY_INPUT
#undef SSRAY_QUERY
#undef SSRAY_MODEL
return lighting;
}

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader


// Transparency
[Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionModel("Refraction Model", Int) = 0
[Enum(Proxy, 1, HiZ, 2)]_RefractionSSRayModel("Refraction SSRay Model", Int) = 0
[Enum(Proxy, 1, HiZ, 2)]_RefractionProjectionModel("Refraction Projection Model", Int) = 0
_Ior("Index Of Refraction", Range(1.0, 2.5)) = 1.0
_ThicknessMultiplier("Thickness Multiplier", Float) = 1.0
_TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0)

// SSReflection
[Enum(None, 0, Proxy, 1, HiZ, 2)]_ReflectionSSRayModel("Reflection SSRay Model", Int) = 0
[Enum(None, 0, Proxy, 1, HiZ, 2)]_ReflectionProjectionModel("Reflection Projection Model", Int) = 0
// Stencil state
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting (fixed at compile time)

#pragma shader_feature _VERTEX_WIND
#pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE
#pragma shader_feature _ _REFRACTION_SSRAY_PROXY _REFRACTION_SSRAY_HIZ
#pragma shader_feature _ _REFLECTION_SSRAY_PROXY _REFLECTION_SSRAY_HIZ
#pragma shader_feature _ _EMISSIVE_MAPPING_PLANAR _EMISSIVE_MAPPING_TRIPLANAR
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR
#pragma shader_feature _NORMALMAP_TANGENT_SPACE

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader


// Transparency
[Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionModel("Refraction Model", Int) = 0
[Enum(Proxy, 1, HiZ, 2)]_RefractionSSRayModel("Refraction SSRay Model", Int) = 0
[Enum(Proxy, 1, HiZ, 2)]_RefractionProjectionModel("Refraction Projection Model", Int) = 0
_Ior("Index Of Refraction", Range(1.0, 2.5)) = 1.0
_ThicknessMultiplier("Thickness Multiplier", Float) = 1.0
_TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0)

// SSReflection
[Enum(None, 0, Proxy, 1, HiZ, 2)]_ReflectionSSRayModel("Reflection SSRay Model", Int) = 0
[Enum(None, 0, Proxy, 1, HiZ, 2)]_ReflectionProjectionModel("Reflection Projection Model", Int) = 0
// Stencil state
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting (fixed at compile time)

#pragma shader_feature _ _TESSELLATION_PHONG
#pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE
#pragma shader_feature _ _REFRACTION_SSRAY_PROXY _REFRACTION_SSRAY_HIZ
#pragma shader_feature _ _REFLECTION_SSRAY_PROXY _REFLECTION_SSRAY_HIZ
#pragma shader_feature _ _EMISSIVE_MAPPING_PLANAR _EMISSIVE_MAPPING_TRIPLANAR
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl


CBUFFER_START(UnityLightingParameters)
// Buffer pyramid
float4 _ColorPyramidSize; // (x,y) = Actual Pixel Size, (z,w) = 1 / Actual Pixel Size
float4 _DepthPyramidSize; // (x,y) = Actual Pixel Size, (z,w) = 1 / Actual Pixel Size
float4 _ColorPyramidScale; // (x,y) = Screen Scale, z = lod count, w = unused
float4 _DepthPyramidScale; // (x,y) = Screen Scale, z = lod count, w = unused
float4 _ColorPyramidSize; // (x,y) = Actual Pixel Size, (z,w) = 1 / Actual Pixel Size
float4 _DepthPyramidSize; // (x,y) = Actual Pixel Size, (z,w) = 1 / Actual Pixel Size
float4 _ColorPyramidScale; // (x,y) = Screen Scale, z = lod count, w = unused
float4 _DepthPyramidScale; // (x,y) = Screen Scale, z = lod count, w = unused
float _SSRefractionInvScreenWeightDistance; // Distance for screen space smoothstep with fallback
float _SSReflectionInvScreenWeightDistance; // Distance for screen space smoothstep with fallback
float _SSRefractionInvScreenWeightDistance; // Distance for screen space smoothstep with fallback
float _SSReflectionInvScreenWeightDistance; // Distance for screen space smoothstep with fallback
int _SSReflectionEnabled;
int _SSReflectionProjectionModel;
// Ambiant occlusion
float4 _AmbientOcclusionParam; // xyz occlusion color, w directLightStrenght

正在加载...
取消
保存