sebastienlagarde 6 年前
当前提交
2fce5809
共有 19 个文件被更改,包括 213 次插入52 次删除
  1. 1
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/Shadow.hlsl
  2. 1
      com.unity.render-pipelines.core/CoreRP/Shadow/AdditionalShadowData.cs
  3. 1
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  4. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  5. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  6. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs
  7. 4
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs
  8. 10
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl
  9. 14
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  10. 134
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  11. 3
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl
  12. 10
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  13. 55
      com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute
  14. 3
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  15. 2
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  16. 2
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  17. 8
      com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute.meta
  18. 10
      com.unity.render-pipelines.high-definition/HDRP/Lighting/DeferredDirectionalShadow.compute.meta
  19. 0
      /com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute

1
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/Shadow.hlsl


StructuredBuffer<ShadowData> shadowDatas;
StructuredBuffer<int4> payloads;
SHADOWCONTEXT_DECLARE_TEXTURES( SHADOWCONTEXT_MAX_TEX2DARRAY, SHADOWCONTEXT_MAX_TEXCUBEARRAY, SHADOWCONTEXT_MAX_COMPSAMPLER, SHADOWCONTEXT_MAX_SAMPLER )
float contactShadow;
};
SHADOW_DEFINE_SAMPLING_FUNCS( SHADOWCONTEXT_MAX_TEX2DARRAY, SHADOWCONTEXT_MAX_TEXCUBEARRAY, SHADOWCONTEXT_MAX_COMPSAMPLER, SHADOWCONTEXT_MAX_SAMPLER )

1
com.unity.render-pipelines.core/CoreRP/Shadow/AdditionalShadowData.cs


[Range(0.0f, 1.0f)]
public float shadowDimmer = 1.0f;
public float shadowFadeDistance = 10000.0f;
public bool contactShadows = false;
// bias control
public float viewBiasMin = 0.5f;
public float viewBiasMax = 10.0f;

1
com.unity.render-pipelines.high-definition/CHANGELOG.md


### Added
- Add option supportDitheringCrossFade on HDRP Asset to allow to remove shader variant during player build if needed
- Add contact shadows for punctual lights (in additional shadow settings), only one light is allowed to cast contact shadows at the same time and so at each frame a dominant light is choosed among all light with contact shadows enabled.
### Changed
- Re-enable shadow mask mode in debug view

1
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs


public readonly GUIContent shadowResolution = new GUIContent("Resolution", "Controls the rendered resolution of the shadow maps. A higher resolution will increase the fidelity of shadows at the cost of GPU performance and memory usage.");
public readonly GUIContent shadowFadeDistance = new GUIContent("Fade Distance", "The shadow will fade at distance ShadowFadeDistance before being culled to minimize popping.");
public readonly GUIContent shadowDimmer = new GUIContent("Dimmer", "Aim to be use with script, timeline or animation. It allows dimming one or multiple shadows. This can also be used as an optimization to fit in shadow budget manually and minimize popping.");
public readonly GUIContent contactShadows = new GUIContent("Enable Contact Shadows", "Enable support for contact shadows on this light. Better for lights with a lot of visible shadows.");
// Bias control
public readonly GUIContent viewBiasMin = new GUIContent("View Bias");

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs


public SerializedProperty dimmer;
public SerializedProperty fadeDistance;
public SerializedProperty resolution;
public SerializedProperty contactShadows;
// Bias control
public SerializedProperty viewBiasMin;

dimmer = o.Find(x => x.shadowDimmer),
fadeDistance = o.Find(x => x.shadowFadeDistance),
resolution = o.Find(x => x.shadowResolution),
contactShadows = o.Find(x => x.contactShadows),
viewBiasMin = o.Find(x => x.viewBiasMin),
viewBiasMax = o.Find(x => x.viewBiasMax),

EditorGUILayout.Space();
EditorGUILayout.LabelField("Additional Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_AdditionalShadowData.contactShadows, s_Styles.contactShadows);
if (settings.lightType.enumValueIndex != (int)LightType.Directional)
{

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs


newAsset.buildMaterialFlagsShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/LightLoop/materialflags.compute");
newAsset.deferredComputeShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/LightLoop/Deferred.compute");
newAsset.deferredDirectionalShadowComputeShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/DeferredDirectionalShadow.compute");
newAsset.screenSpaceShadowComputeShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/ScreenSpaceShadow.compute");
newAsset.volumeVoxelizationCS = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/Volumetrics/VolumeVoxelization.compute");
newAsset.volumetricLightingCS = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/Volumetrics/VolumetricLighting.compute");

4
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs


public Vector3 color;
public int shadowIndex; // -1 if unused
public int contactShadowIndex; // -1 if unused
public Vector3 forward;
public int cookieIndex; // -1 if unused

public Vector3 color;
public int shadowIndex; // -1 if unused
public int contactShadowIndex; // -1 if unused
public Vector3 forward;
public int cookieIndex; // -1 if unused

10
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl


int tileCookie;
float3 color;
int shadowIndex;
int contactShadowIndex;
float3 forward;
int cookieIndex;
float3 right;

float invSqrAttenuationRadius;
float3 color;
int shadowIndex;
int contactShadowIndex;
float3 forward;
int cookieIndex;
float3 right;

{
return value.shadowIndex;
}
int GetContactShadowIndex(DirectionalLightData value)
{
return value.contactShadowIndex;
}
float3 GetForward(DirectionalLightData value)
{
return value.forward;

int GetShadowIndex(LightData value)
{
return value.shadowIndex;
}
int GetContactShadowIndex(LightData value)
{
return value.contactShadowIndex;
}
float3 GetForward(LightData value)
{

14
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl


float3 positionWS = posInput.positionWS;
float shadow = 1.0;
float shadowMask = 1.0;
float4 shadowData = float4(1, 1, 1, 1);
color = lightData.color;
attenuation = 1.0; // Note: no volumetric attenuation along shadow rays for directional lights

#else
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, N, lightData.shadowIndex, L, posInput.positionSS);
#endif
float contactShadow = GetContactShadow(lightLoopContext, lightData.contactShadowIndex);
shadow = min(shadow, contactShadow);
#ifdef SHADOWS_SHADOWMASK

float3 N, float3 L, float3 lightToSample, float4 distances,
out float3 color, out float attenuation)
{
float3 positionWS = posInput.positionWS;
float shadow = 1.0;
float shadowMask = 1.0;
float3 positionWS = posInput.positionWS;
float shadow = 1.0;
float shadowMask = 1.0;
float contactShadow = 1.0;
color = lightData.color;
attenuation = SmoothPunctualLightAttenuation(distances, lightData.invSqrAttenuationRadius,

{
// TODO: make projector lights cast shadows.
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS, N, lightData.shadowIndex, L, distances.x, posInput.positionSS);
contactShadow = GetContactShadow(lightLoopContext, lightData.contactShadowIndex);
shadow = min(shadow, contactShadow);
#ifdef SHADOWS_SHADOWMASK
// Note: Legacy Unity have two shadow mask mode. ShadowMask (ShadowMask contain static objects shadow and ShadowMap contain only dynamic objects shadow, final result is the minimun of both value)
// and ShadowMask_Distance (ShadowMask contain static objects shadow and ShadowMap contain everything and is blend with ShadowMask based on distance (Global distance setup in QualitySettigns)).

134
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs


private ComputeShader buildDispatchIndirectShader { get { return m_Resources.buildDispatchIndirectShader; } }
private ComputeShader clearDispatchIndirectShader { get { return m_Resources.clearDispatchIndirectShader; } }
private ComputeShader deferredComputeShader { get { return m_Resources.deferredComputeShader; } }
private ComputeShader deferredDirectionalShadowComputeShader { get { return m_Resources.deferredDirectionalShadowComputeShader; } }
private ComputeShader screenSpaceShadowComputeShader { get { return m_Resources.screenSpaceShadowComputeShader; } }
static int s_GenAABBKernel;

static int s_deferredDirectionalShadowKernel;
static int s_deferredDirectionalShadow_Contact_Kernel;
static int s_deferredContactShadowKernel;
static ComputeBuffer s_LightVolumeDataBuffer = null;
static ComputeBuffer s_ConvexBoundsBuffer = null;

FrameSettings m_FrameSettings = null;
RenderPipelineResources m_Resources = null;
ContactShadows m_ContactShadows = null;
bool m_EnableContactShadow = false;
// Following is an array of material of size eight for all combination of keyword: OUTPUT_SPLIT_LIGHTING - LIGHTLOOP_TILE_PASS - SHADOWS_SHADOWMASK - USE_FPTL_LIGHTLIST/USE_CLUSTERED_LIGHTLIST - DEBUG_DISPLAY
Material[] m_deferredLightingMaterial;
Material m_DebugViewTilesMaterial;

Light m_CurrentSunLight;
int m_CurrentSunLightShadowIndex = -1;
// Used to get the current dominant casting shadow light on screen (the one which takes the biggest part of the screen)
int m_DominantLightIndex = -1;
float m_DominantLightValue;
// Store the dominant light to give to ScreenSpaceShadow.compute (null is the dominant light is directional)
LightData m_DominantLightData;
public Light GetCurrentSunLight() { return m_CurrentSunLight; }

s_shadeOpaqueDirectShadowMaskFptlKernel = deferredComputeShader.FindKernel("Deferred_Direct_ShadowMask_Fptl");
s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel = deferredComputeShader.FindKernel("Deferred_Direct_ShadowMask_Fptl_DebugDisplay");
s_deferredDirectionalShadowKernel = deferredDirectionalShadowComputeShader.FindKernel("DeferredDirectionalShadow");
s_deferredDirectionalShadow_Contact_Kernel = deferredDirectionalShadowComputeShader.FindKernel("DeferredDirectionalShadow_Contact");
s_deferredDirectionalShadowKernel = screenSpaceShadowComputeShader.FindKernel("DeferredDirectionalShadow");
s_deferredDirectionalShadow_Contact_Kernel = screenSpaceShadowComputeShader.FindKernel("DeferredDirectionalShadow_Contact");
s_deferredContactShadowKernel = screenSpaceShadowComputeShader.FindKernel("DeferredContactShadow");
for (int variant = 0; variant < LightDefinitions.s_NumFeatureVariants; variant++)
{

{
m_FrameSettings = frameSettings;
m_ContactShadows = VolumeManager.instance.stack.GetComponent<ContactShadows>();
m_EnableContactShadow = m_FrameSettings.enableContactShadows && m_ContactShadows.enable && m_ContactShadows.length > 0;
// Cluster
{
var clustPrepassSourceIdx = m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? ClusterPrepassSource.BigTile : ClusterPrepassSource.None;

return new Vector3(light.finalColor.r, light.finalColor.g, light.finalColor.b);
}
bool GetDominantLightWithShadows(AdditionalShadowData additionalShadowData, VisibleLight light, int lightIndex = -1)
{
// Ratio of the size of the light on screen and its intensity, gives a value used to compare light importance
float lightDominanceValue = light.screenRect.size.magnitude * light.light.intensity;
if (additionalShadowData == null || !additionalShadowData.contactShadows || light.light.shadows == LightShadows.None)
return false;
if (lightDominanceValue <= m_DominantLightValue || m_DominantLightValue == Single.PositiveInfinity)
return false;
if (light.lightType == LightType.Directional)
m_DominantLightValue = Single.PositiveInfinity;
else
{
m_DominantLightData = m_lightList.lights[lightIndex];
m_DominantLightIndex = lightIndex;
m_DominantLightValue = lightDominanceValue;
}
return true;
}
public bool GetDirectionalLightData(CommandBuffer cmd, ShadowSettings shadowSettings, GPULightType gpuLightType, VisibleLight light, HDAdditionalLightData additionalData, AdditionalShadowData additionalShadowData, int lightIndex)
{
var directionalLightData = new DirectionalLightData();

if (diffuseDimmer <= 0.0f && specularDimmer <= 0.0f)
return false;
// Light direction for directional is opposite to the forward direction
directionalLightData.forward = light.light.transform.forward;
// Rescale for cookies and windowing.

// Fallback to the first non shadow casting directional light.
m_CurrentSunLight = m_CurrentSunLight == null ? light.light : m_CurrentSunLight;
directionalLightData.contactShadowIndex = -1;
// The first shadow casting directional light with contact shadow enabled is always taken as dominant light
if (GetDominantLightWithShadows(additionalShadowData, light))
directionalLightData.contactShadowIndex = 0;
m_lightList.directionalLights.Add(directionalLightData);

lightData.shadowMaskSelector.x = -1.0f;
lightData.nonLightmappedOnly = 0;
}
lightData.contactShadowIndex = -1;
// Check if the current light is dominant and store it's index to change it's property later,
// as we can't know which one will be dominant before checking all the lights
GetDominantLightWithShadows(additionalshadowData, light, m_lightList.lights.Count -1);
return true;
}

// We need to properly reset this here otherwise if we go from 1 light to no visible light we would keep the old reference active.
m_CurrentSunLight = null;
m_CurrentSunLightShadowIndex = -1;
m_DominantLightIndex = -1;
m_DominantLightValue = 0;
var stereoEnabled = m_FrameSettings.enableStereo;

int lightCount = Math.Min(cullResults.visibleLights.Count, k_MaxLightsOnScreen);
var sortKeys = new uint[lightCount];
int sortCount = 0;
for (int lightIndex = 0, numLights = cullResults.visibleLights.Count; (lightIndex < numLights) && (sortCount < lightCount); ++lightIndex)
{
var light = cullResults.visibleLights[lightIndex];

}
}
//Activate contact shadows on dominant light
if (m_DominantLightIndex != -1)
{
m_DominantLightData = m_lightList.lights[m_DominantLightIndex];
m_DominantLightData.contactShadowIndex = 0;
m_lightList.lights[m_DominantLightIndex] = m_DominantLightData;
}
// Sanity check
Debug.Assert(m_lightList.directionalLights.Count == directionalLightcount);
Debug.Assert(m_lightList.lights.Count == areaLightCount + punctualLightcount);

public void RenderDeferredDirectionalShadow(HDCamera hdCamera, RTHandleSystem.RTHandle deferredShadowRT, RenderTargetIdentifier depthTexture, CommandBuffer cmd)
{
if (m_CurrentSunLight == null || m_CurrentSunLight.GetComponent<AdditionalShadowData>() == null || m_CurrentSunLightShadowIndex < 0)
bool sunLightShadow = m_CurrentSunLight != null && m_CurrentSunLight.GetComponent<AdditionalShadowData>() != null && m_CurrentSunLightShadowIndex >= 0;
// if there is no directional light shadows or no need to compute contact shadows, we just quit
if (!sunLightShadow && m_DominantLightIndex == -1)
cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, RuntimeUtilities.blackTexture);
cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, RuntimeUtilities.whiteTexture);
ContactShadows contactShadows = VolumeManager.instance.stack.GetComponent<ContactShadows>();
Vector4 lightDirection = Vector4.zero;
Vector4 lightPosition = Vector4.zero;
int kernel;
bool enableContactShadows = m_FrameSettings.enableContactShadows && contactShadows.enable && contactShadows.length > 0.0f;
int kernel;
if (enableContactShadows)
kernel = s_deferredDirectionalShadow_Contact_Kernel;
// Here we have three cases:
// - if there is a sun light casting shadow, we need to use comput directional light shadows
// and contact shadows of the dominant light (or the directional if contact shadows are enabled on it)
// - if there is no sun or it's not casting shadows, we don't need to compute it's costy directional
// shadows so we only compute contact shadows for the dominant light
// - if there is no contact shadows then we only compute the directional light shadows
if (m_EnableContactShadow)
{
if (sunLightShadow)
kernel = s_deferredDirectionalShadow_Contact_Kernel;
else
kernel = s_deferredContactShadowKernel;
}
// We use the .w component of the direction/position vectors to choose in the shader the
// light direction of the contact shadows (direction light direction or (pixel position - light position))
if (m_CurrentSunLight != null)
{
lightDirection = -m_CurrentSunLight.transform.forward;
lightDirection.w = 1;
}
if (m_DominantLightIndex != -1)
{
lightPosition = m_DominantLightData.positionWS;
lightPosition.w = 1;
lightDirection.w = 0;
}
m_ShadowMgr.BindResources(cmd, deferredDirectionalShadowComputeShader, kernel);
m_ShadowMgr.BindResources(cmd, screenSpaceShadowComputeShader, kernel);
if (enableContactShadows)
if (m_ContactShadows)
float contactShadowRange = Mathf.Clamp(contactShadows.fadeDistance, 0.0f, contactShadows.maxDistance);
float contactShadowFadeEnd = contactShadows.maxDistance;
float contactShadowRange = Mathf.Clamp(m_ContactShadows.fadeDistance, 0.0f, m_ContactShadows.maxDistance);
float contactShadowFadeEnd = m_ContactShadows.maxDistance;
Vector4 contactShadowParams = new Vector4(contactShadows.length, contactShadows.distanceScaleFactor, contactShadowFadeEnd, contactShadowOneOverFadeRange);
cmd.SetComputeVectorParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalContactShadowParams, contactShadowParams);
cmd.SetComputeIntParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalContactShadowSampleCount, contactShadows.sampleCount);
Vector4 contactShadowParams = new Vector4(m_ContactShadows.length, m_ContactShadows.distanceScaleFactor, contactShadowFadeEnd, contactShadowOneOverFadeRange);
cmd.SetComputeVectorParam(screenSpaceShadowComputeShader, HDShaderIDs._DirectionalContactShadowParams, contactShadowParams);
cmd.SetComputeIntParam(screenSpaceShadowComputeShader, HDShaderIDs._DirectionalContactShadowSampleCount, m_ContactShadows.sampleCount);
cmd.SetComputeIntParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalShadowIndex, m_CurrentSunLightShadowIndex);
cmd.SetComputeVectorParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalLightDirection, -m_CurrentSunLight.transform.forward);
cmd.SetComputeTextureParam(deferredDirectionalShadowComputeShader, kernel, HDShaderIDs._DeferredShadowTextureUAV, deferredShadowRT);
cmd.SetComputeTextureParam(deferredDirectionalShadowComputeShader, kernel, HDShaderIDs._CameraDepthTexture, depthTexture);
cmd.SetComputeIntParam(screenSpaceShadowComputeShader, HDShaderIDs._DirectionalShadowIndex, m_CurrentSunLightShadowIndex);
cmd.SetComputeVectorParam(screenSpaceShadowComputeShader, HDShaderIDs._DirectionalLightDirection, lightDirection);
cmd.SetComputeVectorParam(screenSpaceShadowComputeShader, HDShaderIDs._PunctualLightPosition, lightPosition);
cmd.SetComputeTextureParam(screenSpaceShadowComputeShader, kernel, HDShaderIDs._DeferredShadowTextureUAV, deferredShadowRT);
cmd.SetComputeTextureParam(screenSpaceShadowComputeShader, kernel, HDShaderIDs._CameraDepthTexture, depthTexture);
int deferredShadowTileSize = 16; // Must match DeferreDirectionalShadow.compute
int numTilesX = (hdCamera.actualWidth + (deferredShadowTileSize - 1)) / deferredShadowTileSize;

cmd.DispatchCompute(deferredDirectionalShadowComputeShader, kernel, numTilesX, numTilesY, 1);
cmd.DispatchCompute(screenSpaceShadowComputeShader, kernel, numTilesX, numTilesY, 1);
cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, deferredShadowRT);
}

3
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl


context.sampleReflection = 0;
context.shadowContext = InitShadowContext();
//We always fetch the screen space shadow texture, it is a 1x1 white texture if deferred directional shadow and/or contact shadow are disabled
context.shadowContext.contactShadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.positionSS).y;
// This struct is define in the material. the Lightloop must not access it
// PostEvaluateBSDF call at the end will convert Lighting to diffuse and specular lighting
AggregateLighting aggregateLighting;

10
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


return _EnvLightDatas[j];
}
float GetContactShadow(LightLoopContext lightLoopContact, int contactShadowIndex)
{
// Here we take the contact shadow value using the contactShadowIndex of the light
// If the contact shadows are diasbled, it's value is -1 so this function will only
// return 1
// On the other hand, if the feature is active it's value is 0 so we can return
// the value fetched at the begining of LightLoop()
return max(lightLoopContact.shadowContext.contactShadow, abs(contactShadowIndex));
}

55
com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute


// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel DeferredDirectionalShadow DEFERRED_DIRECTIONAL=DeferredDirectionalShadow
#pragma kernel DeferredDirectionalShadow_Contact DEFERRED_DIRECTIONAL=DeferredDirectionalShadow_Contact ENABLE_CONTACT_SHADOWS
#pragma kernel DeferredContactShadow
#ifdef SHADER_API_PSSL
# pragma argument( scheduler=minpressure ) // instruct the shader compiler to prefer minimizing vgpr usage

CBUFFER_START(DeferredShadowParameters)
uint _DirectionalShadowIndex;
float3 _LightDirection;
float4 _DirectionalLightDirection;
float4 _PunctualLightPosition;
float4 _ScreenSpaceShadowsParameters;
int _SampleCount;
CBUFFER_END

return occluded;
}
float ComputeContactShadow(PositionInputs posInput, float3 direction)
{
float contactShadow = 1.0;
if (_ContactShadowLength > 0.0f)
{
//Here LightDirection is not the light direction but the light position
float4 result = ScreenSpaceShadowRayCast(posInput.positionWS, direction, _ContactShadowLength * max(0.5, posInput.linearDepth * _ContactShadowDistanceScaleFactor));
contactShadow = 1.0 - result.x * saturate((_ContactShadowFadeEnd - posInput.linearDepth) * _ContactShadowFadeOneOverRange);
}
return contactShadow;
}
float contactShadow = 1.0;
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, pixelCoord.xy).x;

PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V, tileCoord);
//Direction got from either the directional light direction or the difference of punctual light position and the pixel position
float3 direction = normalize(_DirectionalLightDirection.xyz * _DirectionalLightDirection.w + (_PunctualLightPosition.xyz - posInput.positionWS) * _PunctualLightPosition.w);
NormalData normalData;
DecodeFromNormalBuffer(posInput.positionSS, normalData);

float shadow = GetDirectionalShadowAttenuation(shadowContext, posInput.positionWS, normalWS, _DirectionalShadowIndex, _LightDirection);
float shadow = GetDirectionalShadowAttenuation(shadowContext, posInput.positionWS, normalWS, _DirectionalShadowIndex, _DirectionalLightDirection.xyz);
float contactShadow = 1.0f;
if (_ContactShadowLength > 0.0f)
{
float4 result = ScreenSpaceShadowRayCast(posInput.positionWS, normalize(_LightDirection), _ContactShadowLength * max(0.5, posInput.linearDepth * _ContactShadowDistanceScaleFactor));
contactShadow = 1.0 - result.x * saturate((_ContactShadowFadeEnd - posInput.linearDepth) * _ContactShadowFadeOneOverRange);
shadow *= contactShadow;
}
contactShadow = ComputeContactShadow(posInput, direction);
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, 0.0, 0.0, 0.0);
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, contactShadow, 1.0, 1.0);
[numthreads(DEFERRED_SHADOW_TILE_SIZE, DEFERRED_SHADOW_TILE_SIZE, 1)]
void DeferredContactShadow(uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID)
{
uint2 pixelCoord = groupId * DEFERRED_SHADOW_TILE_SIZE + groupThreadId;
uint2 tileCoord = groupId;
float contactShadow = 1.0;
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, pixelCoord.xy).x;
if (depth == UNITY_RAW_FAR_CLIP_VALUE)
return;
PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V, tileCoord);
float3 direction = normalize(_PunctualLightPosition.xyz - posInput.positionWS);
contactShadow = ComputeContactShadow(posInput, direction);
_DeferredShadowTextureUAV[pixelCoord] = float4(1.0, contactShadow, 1.0, 1.0);
}

3
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _DirectionalShadowIndex = Shader.PropertyToID("_DirectionalShadowIndex");
public static readonly int _DirectionalContactShadowParams = Shader.PropertyToID("_ScreenSpaceShadowsParameters");
public static readonly int _DirectionalContactShadowSampleCount = Shader.PropertyToID("_SampleCount");
public static readonly int _DirectionalLightDirection = Shader.PropertyToID("_LightDirection");
public static readonly int _DirectionalLightDirection = Shader.PropertyToID("_DirectionalLightDirection");
public static readonly int _PunctualLightPosition = Shader.PropertyToID("_PunctualLightPosition");
public static readonly int _StencilMask = Shader.PropertyToID("_StencilMask");
public static readonly int _StencilRef = Shader.PropertyToID("_StencilRef");

2
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


type: 3}
deferredComputeShader: {fileID: 7200000, guid: 0b64f79746d2daf4198eaf6eab9af259,
type: 3}
deferredDirectionalShadowComputeShader: {fileID: 7200000, guid: fbde6fae193b2a94e9fd97c163c204f4,
screenSpaceShadowComputeShader: {fileID: 7200000, guid: 3e6900e06dc185a4380af4dacb4db0a4,
type: 3}
volumeVoxelizationCS: {fileID: 7200000, guid: c20b371db720da244b73830ec74a343a,
type: 3}

2
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public ComputeShader buildPerVoxelLightListShader; // clustered
public ComputeShader buildMaterialFlagsShader;
public ComputeShader deferredComputeShader;
public ComputeShader deferredDirectionalShadowComputeShader;
public ComputeShader screenSpaceShadowComputeShader;
public ComputeShader volumeVoxelizationCS;
public ComputeShader volumetricLightingCS;

8
com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute.meta


fileFormatVersion: 2
guid: 3e6900e06dc185a4380af4dacb4db0a4
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:

10
com.unity.render-pipelines.high-definition/HDRP/Lighting/DeferredDirectionalShadow.compute.meta


fileFormatVersion: 2
guid: fbde6fae193b2a94e9fd97c163c204f4
timeCreated: 1505129983
licenseType: Pro
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 8196
userData:
assetBundleName:
assetBundleVariant:

/com.unity.render-pipelines.high-definition/HDRP/Lighting/DeferredDirectionalShadow.compute → /com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute

正在加载...
取消
保存