|
|
|
|
|
|
static int[] s_shadeOpaqueIndirectShadowMaskFptlKernels = new int[LightDefinitions.s_NumFeatureVariants]; |
|
|
|
|
|
|
|
static int s_deferredDirectionalShadowKernel; |
|
|
|
static int s_deferredContactShadowkernel; |
|
|
|
static int s_deferredDirectionalShadow_Contact_Kernel; |
|
|
|
|
|
|
|
static ComputeBuffer s_LightVolumeDataBuffer = null; |
|
|
|
|
|
|
|
|
|
|
Light m_CurrentSunLight; |
|
|
|
int m_CurrentSunLightShadowIndex = -1; |
|
|
|
int m_DominantLightIndex = -1; |
|
|
|
|
|
|
|
public Light GetCurrentSunLight() { return m_CurrentSunLight; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s_deferredDirectionalShadowKernel = deferredDirectionalShadowComputeShader.FindKernel("DeferredDirectionalShadow"); |
|
|
|
s_deferredDirectionalShadow_Contact_Kernel = deferredDirectionalShadowComputeShader.FindKernel("DeferredDirectionalShadow_Contact"); |
|
|
|
s_deferredContactShadowkernel = deferredDirectionalShadowComputeShader.FindKernel("DeferredContactShadow"); |
|
|
|
|
|
|
|
for (int variant = 0; variant < LightDefinitions.s_NumFeatureVariants; variant++) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
//TODO: move this upwards
|
|
|
|
float biggestLight = 0; |
|
|
|
int dominantLightIndex = -1; |
|
|
|
|
|
|
|
for (int sortIndex = 0; sortIndex < sortCount; ++sortIndex) |
|
|
|
{ |
|
|
|
|
|
|
if (GetDirectionalLightData(cmd, shadowSettings, gpuLightType, light, additionalLightData, additionalShadowData, lightIndex)) |
|
|
|
{ |
|
|
|
directionalLightcount++; |
|
|
|
|
|
|
|
if (additionalShadowData != null && additionalShadowData.contactShadows) |
|
|
|
{ |
|
|
|
dominantLightIndex = lightIndex; |
|
|
|
biggestLight = Single.PositiveInfinity; |
|
|
|
} |
|
|
|
|
|
|
|
// We make the light position camera-relative as late as possible in order
|
|
|
|
// to allow the preceding code to work with the absolute world space coordinates.
|
|
|
|
|
|
|
|
|
|
|
if (additionalShadowData != null && additionalShadowData.contactShadows && lightDimensions.magnitude > biggestLight) |
|
|
|
{ |
|
|
|
dominantLightIndex = lightIndex; |
|
|
|
m_DominantLightIndex = lightIndex; |
|
|
|
biggestLight = lightDimensions.magnitude; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void RenderDeferredDirectionalShadow(HDCamera hdCamera, RTHandleSystem.RTHandle deferredShadowRT, RenderTargetIdentifier depthTexture, CommandBuffer cmd) |
|
|
|
{ |
|
|
|
if (m_CurrentSunLight == null || m_CurrentSunLight.GetComponent<AdditionalShadowData>() == null || m_CurrentSunLightShadowIndex < 0) |
|
|
|
if ((m_CurrentSunLight == null || m_CurrentSunLight.GetComponent<AdditionalShadowData>() == null || m_CurrentSunLightShadowIndex < 0) && m_DominantLightIndex == -1) |
|
|
|
{ |
|
|
|
cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, RuntimeUtilities.blackTexture); |
|
|
|
return; |
|
|
|
|
|
|
{ |
|
|
|
ContactShadows contactShadows = VolumeManager.instance.stack.GetComponent<ContactShadows>(); |
|
|
|
ContactShadows contactShadows = VolumeManager.instance.stack.GetComponent<ContactShadows>(); |
|
|
|
bool enableContactShadows = m_FrameSettings.enableContactShadows && contactShadows.enable && contactShadows.length > 0.0f; |
|
|
|
Vector3 lightDirection; |
|
|
|
int kernel; |
|
|
|
bool enableContactShadows = m_FrameSettings.enableContactShadows && contactShadows.enable && contactShadows.length > 0.0f; |
|
|
|
int kernel; |
|
|
|
// Debug.Log("contactShadowsSettings: " + contactShadows.enable);
|
|
|
|
kernel = s_deferredDirectionalShadow_Contact_Kernel; |
|
|
|
{ |
|
|
|
Debug.Log("Contact shadows enabled !"); |
|
|
|
if (m_DominantLightIndex != -1) |
|
|
|
{ |
|
|
|
kernel = s_deferredContactShadowkernel; |
|
|
|
} |
|
|
|
else |
|
|
|
kernel = s_deferredDirectionalShadow_Contact_Kernel; |
|
|
|
} |
|
|
|
|
|
|
|
if (m_CurrentSunLight != null) |
|
|
|
lightDirection = -m_CurrentSunLight.transform.forward; |
|
|
|
else |
|
|
|
lightDirection = Vector3.one; //TODO: put dominant light direction here
|
|
|
|
|
|
|
|
m_ShadowMgr.BindResources(cmd, deferredDirectionalShadowComputeShader, kernel); |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cmd.SetComputeIntParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalShadowIndex, m_CurrentSunLightShadowIndex); |
|
|
|
cmd.SetComputeVectorParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalLightDirection, -m_CurrentSunLight.transform.forward); |
|
|
|
cmd.SetComputeVectorParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalLightDirection, lightDirection); |
|
|
|
cmd.SetComputeTextureParam(deferredDirectionalShadowComputeShader, kernel, HDShaderIDs._DeferredShadowTextureUAV, deferredShadowRT); |
|
|
|
cmd.SetComputeTextureParam(deferredDirectionalShadowComputeShader, kernel, HDShaderIDs._CameraDepthTexture, depthTexture); |
|
|
|
|
|
|
|