浏览代码

Optimize and clean up LineIrradiance()

/main
Evgenii Golubev 8 年前
当前提交
22326553
共有 1 个文件被更改,包括 13 次插入11 次删除
  1. 24
      Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl

24
Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl


return PolygonRadiance(L, twoSided);
}
float LineFpo(float l, float rcpD, float rcpDL)
float LineFpo(float tLDDL, float lrcpD, float rcpD)
// Compute: l / d / (d * d + l * l) + 1.0 / (d * d) * atan(l / d).
return l * rcpDL + sq(rcpD) * atan(l * rcpD);
// Compute: ((l / d) / (d * d + l * l)) + (1.0 / (d * d)) * atan(l / d).
return tLDDL + sq(rcpD) * atan(lrcpD);
float LineFwt(float sqL, float rcpDL)
float LineFwt(float tLDDL, float l)
// Compute: l * l / d / (d * d + l * l).
return sqL * rcpDL;
// Compute: l * ((l / d) / (d * d + l * l)).
return l * tLDDL;
}
// Computes the integral of the clamped cosine over the line segment.

// the shaded point and the line, pointing away from the shaded point.
float LineIrradiance(float l1, float l2, float3 normal, float3 tangent)
{
float dist = length(normal);
float rcpDL1 = rcp(dist) * rcp(sq(dist) + sq(l1));
float rcpDL2 = rcp(dist) * rcp(sq(dist) + sq(l2));
float intP0 = LineFpo(l2, rcp(dist), rcpDL2) - LineFpo(l1, rcp(dist), rcpDL1);
float intWt = LineFwt(sq(l2), rcpDL2) - LineFwt(sq(l1), rcpDL1);
float d = length(normal);
float l1rcpD = l1 * rcp(d);
float l2rcpD = l2 * rcp(d);
float tLDDL1 = l1rcpD * rcp(sq(d) + sq(l1));
float tLDDL2 = l2rcpD * rcp(sq(d) + sq(l2));
float intWt = LineFwt(tLDDL2, l2) - LineFwt(tLDDL1, l1);
float intP0 = LineFpo(tLDDL2, l2rcpD, rcp(d)) - LineFpo(tLDDL1, l1rcpD, rcp(d));
return intP0 * normal.z + intWt * tangent.z;
}
正在加载...
取消
保存