mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
Cleanup: simplify computation in Cycles area light sampling
`diff` in numerator and denominator cancels out, except for the signs, which we know beforehand since `x1 > x0`, `y1 > y0` Pull Request: https://projects.blender.org/blender/blender/pulls/122740
This commit is contained in:
parent
c1a9ccdf0b
commit
2ddc936cbb
2 changed files with 7 additions and 3 deletions
|
|
@ -39,9 +39,8 @@ ccl_device_inline float area_light_rect_sample(float3 P,
|
|||
float x0 = xc - 0.5f * len_u, x1 = xc + 0.5f * len_u;
|
||||
float y0 = yc - 0.5f * len_v, y1 = yc + 0.5f * len_v;
|
||||
/* Compute predefined constants. */
|
||||
float4 diff = make_float4(x0, y1, x1, y0) - make_float4(x1, y0, x0, y1);
|
||||
float4 nz = make_float4(y0, x1, y1, x0) * diff;
|
||||
nz = nz / sqrt(z0 * z0 * diff * diff + nz * nz);
|
||||
float4 nz = make_float4(-y0, x1, y1, -x0);
|
||||
nz /= sqrt(nz * nz + z0 * z0);
|
||||
/* The original paper uses `acos()` to compute the internal angles here, and then computes the
|
||||
* solid angle as their sum minus 2*pi. However, for very small rectangles, this results in
|
||||
* excessive cancellation error since the sum will be almost 2*pi as well.
|
||||
|
|
|
|||
|
|
@ -132,6 +132,11 @@ ccl_device_inline float4 operator*=(float4 &a, float f)
|
|||
return a = a * f;
|
||||
}
|
||||
|
||||
ccl_device_inline float4 operator/=(float4 &a, const float4 b)
|
||||
{
|
||||
return a = a / b;
|
||||
}
|
||||
|
||||
ccl_device_inline float4 operator/=(float4 &a, float f)
|
||||
{
|
||||
return a = a / f;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue