浏览代码

Take into account feedback

/main
sebastienlagarde 7 年前
当前提交
86dfa8ec
共有 3 个文件被更改,包括 51 次插入26 次删除
  1. 26
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  2. 26
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl
  3. 25
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl

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


// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
void EvaluateLight_Directional(LightLoopContext lightLoopContext, PositionInputs posInput,
DirectionalLightData lightData, BakeLightingData bakeLightingData,
float3 N, float3 L, bool isThinModeTransmission,
float3 N, float3 L,
out float3 color, out float attenuation)
{
float3 positionWS = posInput.positionWS;

shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
#endif
float NdotL = dot(N, L);
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (isThinModeTransmission || NdotL >= 0.0))
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (dot(N, L) >= 0.0))
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, NdotL > 0.0 ? N : -N, lightData.shadowIndex, L, posInput.positionSS);
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, N, lightData.shadowIndex, L, posInput.positionSS);
#endif
#ifdef SHADOWS_SHADOWMASK

// Volumetric don't use screenspace shadow. Transparent neither (as we don't have the depth information)
#if (SHADERPASS != SHADERPASS_VOLUMETRIC_LIGHTING && !defined(_SURFACE_TYPE_TRANSPARENT))
// Don't apply shadow contact on transmismission
shadow = isThinModeTransmission ? shadow : min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
shadow = min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
#endif
}

// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
void EvaluateLight_Punctual(LightLoopContext lightLoopContext, PositionInputs posInput,
LightData lightData, BakeLightingData bakeLightingData,
float3 N, float3 L, float3 lightToSample, float4 distances, bool isThinModeTransmission,
float3 N, float3 L, float3 lightToSample, float4 distances,
out float3 color, out float attenuation)
{
float3 positionWS = posInput.positionWS;

shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
#endif
float NdotL = dot(N, L);
// We test NdotL > 0.0 to not sample the shadow map if it is not required.
// In case of thin mode we always need to perform the fetch as we reuse it for back and front lighting
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (isThinModeTransmission || NdotL >= 0.0))
// We test NdotL >= 0.0 to not sample the shadow map if it is not required.
// Note that volumetric use N of 0 so it still work
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (dot(N, L) >= 0.0))
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS, NdotL > 0.0 ? N : -N, lightData.shadowIndex, L, distances.x, posInput.positionSS);
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS, N, lightData.shadowIndex, L, distances.x, posInput.positionSS);
#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)

// Volumetric don't use screenspace shadow. Transparent neither (as we don't have the depth information)
#if (SHADERPASS != SHADERPASS_VOLUMETRIC_LIGHTING && !defined(_SURFACE_TYPE_TRANSPARENT))
// Don't apply shadow contact on transmismission
shadow = isThinModeTransmission ? shadow : min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
shadow = min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
#endif
}

26
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl


float3 color;
float attenuation;
float attenuationNoContactShadows;
EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, N, L, HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS), color, attenuation);
// When using thin transmission mode we don't fetch shadow map for back face, we reuse front face shadow
// However we flip the normal for the bias (and the NdotL test) and disable contact shadow
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS) && NdotL < 0)
{
// Disable shadow contact in case of transmission and backface shadow
N = -N;
lightData.contactShadowIndex = -1; // This is only modify for the scope of this function
}
EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, N, L, color, attenuation);
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light)

float3 color;
float attenuation;
float attenuationNoContactShadows;
// When using thin transmission mode we don't fetch shadow map for back face, we reuse front face shadow
// However we flip the normal for the bias (and the NdotL test) and disable contact shadow
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS) && NdotL < 0)
{
// Disable shadow contact in case of transmission and backface shadow
N = -N;
lightData.contactShadowIndex = -1; // This is only modify for the scope of this function
}
lightToSample, distances, HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS),
color, attenuation);
lightToSample, distances, color, attenuation);
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light)

25
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl


// color and attenuation are outputted by EvaluateLight:
float3 color;
float attenuation;
float attenuationNoContactShadows;
// When using thin transmission mode we don't fetch shadow map for back face, we reuse front face shadow
// However we flip the normal for the bias (and the NdotL test) and disable contact shadow
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS) && NdotL < 0)
{
// Disable shadow contact in case of transmission and backface shadow
N = -N;
lightData.contactShadowIndex = -1; // This is only modify for the scope of this function
}
// For shadow attenuation (ie receiver bias), always use the geometric normal:
EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, bsdfData.geomNormalWS, L, HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS), color, attenuation);

float3 color;
float attenuation;
float attenuationNoContactShadows;
// When using thin transmission mode we don't fetch shadow map for back face, we reuse front face shadow
// However we flip the normal for the bias (and the NdotL test) and disable contact shadow
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS) && NdotL < 0)
{
// Disable shadow contact in case of transmission and backface shadow
N = -N;
lightData.contactShadowIndex = -1; // This is only modify for the scope of this function
}
lightToSample, distances, HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS),
color, attenuation);
lightToSample, distances, color, attenuation);
float intensity = max(0, attenuation); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light)

// Note: we do not modify the distance to the light, or the light angle for the back face.
// This is a performance-saving optimization which makes sense as long as the thickness is small.
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
lighting.diffuse += EvaluateTransmission(bsdfData, transmittance, NdotL, NdotV, LdotV, attenuationNoContactShadows * lightData.diffuseScale);
lighting.diffuse += EvaluateTransmission(bsdfData, transmittance, NdotL, NdotV, LdotV, attenuation * lightData.diffuseScale);
}
// Save ALU by applying light and cookie colors only once.

正在加载...
取消
保存