浏览代码

Added a light attenuation falloff in the shader to prevent the hardcutoff at the light range. Better is to use a light texture falloff but as off now _LightTexture0 is not passed in SRP. We can create one later.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
7ea80c7b
共有 1 个文件被更改,包括 11 次插入3 次删除
  1. 14
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc

14
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc


posToLight -= posWorld * lightInput.pos.w;
float distanceSqr = max(dot(posToLight, posToLight), 0.001);
float dist = sqrt(distanceSqr);
// TODO: compute light attenuation from texture to save ALU. Builtin _LightTexture0 not set from SRP but we can create one.
// light attenuation with falloff.
// lightInput.atten.z = kQuadFallOff = (25.0) / (lightRange * lightRange)
// lightInput.atten.w = lightRange * lightRange
// TODO: we can precompute 1.0 / (lightInput.atten.w * 0.64 - lightInput.atten.w)
// falloff is computed from 80% light range squared
float falloff = saturate((distanceSqr - lightInput.atten.w) / (lightInput.atten.w * 0.64 - lightInput.atten.w));
lightAtten *= falloff;
half cutoff = step(distanceSqr, lightInput.atten.w);
lightAtten *= cutoff;
half NdotL = saturate(dot(normal, lightDir));

正在加载...
取消
保存