浏览代码

Change light smoothing factor in lightweight renderpipeline to match lightmapper

/main
egomeh 6 年前
当前提交
e91dfb63
共有 2 个文件被更改,包括 17 次插入4 次删除
  1. 13
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs
  2. 8
      com.unity.render-pipelines.lightweight/LWRP/ShaderLibrary/Lighting.hlsl

13
com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs


if (lightData.lightType != LightType.Directional)
{
// Light attenuation in lightweight matches the unity vanilla one.
// attenuation = 1.0 / 1.0 + distanceToLightSqr * quadraticAttenuation
// then a smooth factor is applied to linearly fade attenuation to light range
// the attenuation smooth factor starts having effect at 80% of light range
// attenuation = 1.0 / distanceToLightSqr
// We offer two different smoothing factors.
// The smoothing factors make sure that the light intensity is zero at the light range limit.
// The first smoothing factor is a linear fade starting at 80 % of the light range.
// The other smoothing factor matches the one used in the Unity lightmapper but is slower than the linear one.
// smoothFactor = (1.0 - saturate((distanceSqr * 1.0 / lightrangeSqr)^2))^2
lightAttenuation.x = oneOverFadeRangeSqr;
float oneOverLightRangeSqr = 1.0f / Mathf.Max(0.0001f, lightData.range * lightData.range);
lightAttenuation.x = SystemInfo.deviceType == DeviceType.Handheld ? oneOverFadeRangeSqr : oneOverLightRangeSqr;
lightAttenuation.y = lightRangeSqrOverFadeRangeSqr;
subtractiveMixedLighting = 1.0f;
}

8
com.unity.render-pipelines.lightweight/LWRP/ShaderLibrary/Lighting.hlsl


// for directional lights attenuation will be 1
half lightAtten = 1.0h / distanceSqr;
#if defined(SHADER_HINT_NICE_QUALITY)
// Use the smoothing factor also used in the Unity lightmapper.
half factor = distanceSqr * distanceAttenuation.x;
half smoothFactor = saturate(1.0h - factor * factor);
smoothFactor = smoothFactor * smoothFactor;
#else
// We need to smoothly fade attenuation to light range. We start fading linearly at 80% of light range
// Therefore:
// fadeDistance = (0.8 * 0.8 * lightRangeSq)

// distanceSqr * distanceAttenuation.y + distanceAttenuation.z
half smoothFactor = saturate(distanceSqr * distanceAttenuation.x + distanceAttenuation.y);
#endif
return lightAtten * smoothFactor;
}

正在加载...
取消
保存