浏览代码

Removed useless kernel

/main
Antoine Lelievre 6 年前
当前提交
a69f06e6
共有 5 个文件被更改,包括 44 次插入52 次删除
  1. 51
      com.unity.render-pipelines.high-definition/HDRP/Lighting/DeferredDirectionalShadow.compute
  2. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  3. 36
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  4. 3
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl
  5. 4
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl

51
com.unity.render-pipelines.high-definition/HDRP/Lighting/DeferredDirectionalShadow.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

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

float shadow = GetDirectionalShadowAttenuation(shadowContext, posInput.positionWS, normalWS, _DirectionalShadowIndex, _LightDirection);
#ifdef ENABLE_CONTACT_SHADOWS
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);
shadow *= contactShadow;
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, 0.0, 0.0, 0.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 depth = LOAD_TEXTURE2D(_CameraDepthTexture, pixelCoord.xy).x;
PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V, tileCoord);
float contactShadow = 1.0f;
float shadow = 1;
if (_ContactShadowLength > 0.0f)
{
//Here LightDirection is not the light direction but the light position
float4 result = ScreenSpaceShadowRayCast(posInput.positionWS, normalize(_LightDirection - posInput.positionWS), _ContactShadowLength * max(0.5, posInput.linearDepth * _ContactShadowDistanceScaleFactor));
contactShadow = 1.0 - result.x * saturate((_ContactShadowFadeEnd - posInput.linearDepth) * _ContactShadowFadeOneOverRange);
shadow *= contactShadow;
}
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, _LightDirection);
}
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, contactShadow, 0.0, 0.0);
}

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


{
// TODO: make projector lights cast shadows.
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS, N, lightData.shadowIndex, L, distances.x, posInput.positionSS);
contactShadow = GetSContactShadow(lightLoopContext, lightData.contactShadowIndex);
contactShadow = GetContactShadow(lightLoopContext, lightData.contactShadowIndex);
shadow = min(shadow, contactShadow);
#ifdef SHADOWS_SHADOWMASK

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


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;

int m_CurrentSunLightShadowIndex = -1;
LightData m_DominantLightData;
int m_DominantLightIndex = -1;
bool m_CurrentSunLightContactShadow = false;
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++)
{

int lightIndex, ref Vector3 lightDimensions)
{
var lightData = new LightData();
ContactShadows contactShadows = VolumeManager.instance.stack.GetComponent<ContactShadows>();
bool enableContactShadows = m_FrameSettings.enableContactShadows && contactShadows.enable && contactShadows.length > 0.0f;
lightData.contactShadowIndex = -1;
lightData.contactShadowIndex = enableContactShadows ? 1 : -1;
lightData.positionWS = light.light.transform.position;
// Setting 0 for invSqrAttenuationRadius mean we have no range attenuation, but still have inverse square attenuation.

m_CurrentSunLight = null;
m_CurrentSunLightShadowIndex = -1;
m_DominantLightIndex = -1;
m_CurrentSunLightContactShadow = false;
var stereoEnabled = m_FrameSettings.enableStereo;

m_lightList.directionalLights[last] = lightData;
}
if (additionalShadowData.contactShadows)
if (additionalShadowData != null && additionalShadowData.contactShadows)
{
m_CurrentSunLightContactShadow = true;
}
}
continue;
}

lightData.positionWS -= camPosWS;
m_lightList.lights[last] = lightData;
}
if (additionalShadowData != null && additionalShadowData.contactShadows && lightDimensions.magnitude > biggestLight)
{
m_DominantLightData = m_lightList.lights[m_lightList.lights.Count - 1];

{
ContactShadows contactShadows = VolumeManager.instance.stack.GetComponent<ContactShadows>();
bool enableContactShadows = m_FrameSettings.enableContactShadows && contactShadows.enable && contactShadows.length > 0.0f;
Vector3 lightDirection;
Vector4 lightDirection;
if (enableContactShadows)
{
if (m_DominantLightIndex != -1)
kernel = s_deferredContactShadowkernel;
else
kernel = s_deferredDirectionalShadow_Contact_Kernel;
}
if (enableContactShadows && (m_DominantLightIndex != -1 || m_CurrentSunLightContactShadow))
kernel = s_deferredDirectionalShadow_Contact_Kernel;
if (m_CurrentSunLight != null)
if (m_DominantLightIndex == -1 && m_CurrentSunLight != null)
{
lightDirection.w = 0;
}
{
lightDirection.w = 1;
}
m_ShadowMgr.BindResources(cmd, deferredDirectionalShadowComputeShader, kernel);

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


context.sampleReflection = 0;
context.shadowContext = InitShadowContext();
context.shadowContext.contactShadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.positionSS).x;
context.shadowContext.contactShadow = 1;
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

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


return _EnvLightDatas[j];
}
float GetSContactShadow(LightLoopContext lightLoopContact, int contactShadowIndex)
float GetContactShadow(LightLoopContext lightLoopContact, int contactShadowIndex)
return 1;//max(lightLoopContact.shadowContext.contactShadow, abs(contactShadowIndex));
return max(lightLoopContact.shadowContext.contactShadow, abs(contactShadowIndex));
}
正在加载...
取消
保存