Skip to content

Commit 568c35e

Browse files
committed
Improve diffuseIrradiance()
1 parent 2a1f14e commit 568c35e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

include/math/brdf.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,19 @@ static f32x4 importanceSamplingNdfDggx(float2 u, float a) noexcept
136136
*/
137137
static f32x4 diffuseIrradiance(float3 normal, const f32x4* shBuffer) noexcept
138138
{
139-
f32x4 irradiance = shBuffer[0] +
140-
shBuffer[1] * (normal.y) + shBuffer[2] * (normal.z) + shBuffer[3] * (normal.x) +
141-
shBuffer[4] * (normal.y * normal.x) +
142-
shBuffer[5] * (normal.y * normal.z) +
143-
shBuffer[6] * (3.0f * normal.z * normal.z - 1.0f) +
144-
shBuffer[7] * (normal.z * normal.x) +
145-
shBuffer[8] * (normal.x * normal.x - normal.y * normal.y);
139+
auto qb = float4(normal.y * normal.x, normal.y * normal.z,
140+
std::fma(normal.z * normal.z, 3.0f, -1.0f), normal.z * normal.x);
141+
auto ft = normal.x * normal.x - normal.y * normal.y;
142+
143+
auto irradiance = shBuffer[0];
144+
irradiance += shBuffer[1] * normal.y;
145+
irradiance += shBuffer[2] * normal.z;
146+
irradiance += shBuffer[3] * normal.x;
147+
irradiance += shBuffer[4] * qb.x;
148+
irradiance += shBuffer[5] * qb.y;
149+
irradiance += shBuffer[6] * qb.z;
150+
irradiance += shBuffer[7] * qb.w;
151+
irradiance += shBuffer[8] * ft;
146152
return max(irradiance, f32x4::zero);
147153
}
148154

0 commit comments

Comments
 (0)