浏览代码

Added somne descriptive comments

/main
Antoine Lelievre 6 年前
当前提交
78777de4
共有 5 个文件被更改,包括 34 次插入4 次删除
  1. 20
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  2. 1
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl
  3. 5
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  4. 4
      com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute
  5. 8
      com.unity.render-pipelines.high-definition/HDRP/Lighting/ScreenSpaceShadow.compute.meta

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


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)
// 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; }

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)

// Fallback to the first non shadow casting directional light.
m_CurrentSunLight = m_CurrentSunLight == null ? light.light : m_CurrentSunLight;
directionalLightData.contactShadowIndex = m_EnableContactShadow ? 1 : -1;
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;

lightData.nonLightmappedOnly = 0;
}
lightData.contactShadowIndex = m_EnableContactShadow ? 1 : -1;
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;

{
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.whiteTexture);

Vector4 lightPosition = Vector4.zero;
int 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)

else
kernel = s_deferredDirectionalShadowKernel;
// 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;

1
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

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


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));
}

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


contactShadow = ComputeContactShadow(posInput, direction);
#endif
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, contactShadow, 0.0, 0.0);
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, contactShadow, 1.0, 1.0);
}
[numthreads(DEFERRED_SHADOW_TILE_SIZE, DEFERRED_SHADOW_TILE_SIZE, 1)]

contactShadow = ComputeContactShadow(posInput, direction);
_DeferredShadowTextureUAV[pixelCoord] = float4(0.0, contactShadow, 0.0, 0.0);
_DeferredShadowTextureUAV[pixelCoord] = float4(1.0, contactShadow, 1.0, 1.0);
}

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


fileFormatVersion: 2
guid: 3e6900e06dc185a4380af4dacb4db0a4
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存