浏览代码

Merge pull request #1348 from Unity-Technologies/Fix-shadow-mask

Fix directional light and shadow mask transition
/main
GitHub 6 年前
当前提交
5e1bd3c5
共有 5 个文件被更改,包括 19 次插入23 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md
  2. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs
  3. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl
  4. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightEvaluation.hlsl
  5. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs

1
ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md


- Fix unnecessary division by PI for baked area lights.
- Fix line lights sent to the lightmappers. The backends don't support this light type.
- Fix issue with shadow mask framesettings not correctly taken into account when shadow mask is enabled for lighting.
- Fix directional light and shadow mask transition, they are now matching making smooth transition
## [2018.1.0f2]

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs


public Vector3 up; // Rescaled by (2 / shapeHeight)
public float diffuseScale;
public Vector2 fadeDistanceScaleAndBias; // Use with ShadowMask feature
public float unused0;
public float volumetricDimmer;
public float volumetricDimmer; // TODO: improve the cache locality
};
[GenerateHLSL]

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl


float specularScale;
float3 up;
float diffuseScale;
float2 fadeDistanceScaleAndBias;
float unused0;
float volumetricDimmer;
float volumetricDimmer;
};
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.LightData

{
return value.diffuseScale;
}
float2 GetFadeDistanceScaleAndBias(DirectionalLightData value)
{
return value.fadeDistanceScaleAndBias;
}
float GetUnused0(DirectionalLightData value)
float GetVolumetricDimmer(DirectionalLightData value)
return value.unused0;
return value.volumetricDimmer;
}
int GetDynamicShadowCasterOnly(DirectionalLightData value)
{

{
return value.shadowMaskSelector;
}
float GetVolumetricDimmer(DirectionalLightData value)
{
return value.volumetricDimmer;
}
//

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightEvaluation.hlsl


#endif
#ifdef SHADOWS_SHADOWMASK
float fade = saturate(posInput.linearDepth * lightData.fadeDistanceScaleAndBias.x + lightData.fadeDistanceScaleAndBias.y);
// TODO: Optimize this code! Currently it is a bit like brute force to get the last transistion and fade to shadow mask, but there is
// certainly more efficient to do
// We reuse the transition from the cascade system to fade between shadow mask at max distance
uint payloadOffset;
real fade;
int cascadeCount;
int shadowSplitIndex = EvalShadow_GetSplitIndex(lightLoopContext.shadowContext, lightData.shadowIndex, positionWS, payloadOffset, fade, cascadeCount);
// we have a fade caclulation for each cascade but we must lerp with shadow mask only for the last one
fade = ((shadowSplitIndex + 1) == cascadeCount || shadowSplitIndex == -1.0) ? fade : 0.0;
shadow = lerp(shadow, shadowMask, fade); // Caution to lerp parameter: fade is the reverse of shadowDimmer
// In the transition code (both dithering and blend) we use shadow = lerp( shadow, 1.0, fade ) for last transition
// mean if we expend the code we have (shadow * (1 - fade) + fade). Here to make transition with shadow mask
// we will remove fade and add fade * shadowMask which mean we do a lerp with shadow mask
shadow = shadow - fade + fade * shadowMask;
// Note: There is no shadowDimmer when there is no shadow mask
#endif

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


m_CurrentSunLightShadowIndex = shadowIdx;
}
float scale;
float bias;
GetScaleAndBiasForLinearDistanceFade(m_maxShadowDistance, out scale, out bias);
directionalLightData.fadeDistanceScaleAndBias = new Vector2(scale, bias);
directionalLightData.shadowMaskSelector = Vector4.zero;
if (IsBakedShadowMaskLight(light.light))

正在加载...
取消
保存