@@ -95,8 +95,11 @@ with the surface normal `w`.
9595function D (trd:: TrowbridgeReitzDistribution , w:: Vec3f ):: Float32
9696 tan_θ² = tan_θ (w)^ 2
9797 isinf (tan_θ²) && return 0f0
98-
99- cos_θ⁴ = cos_θ (w)^ 4
98+
99+ # Calculate cos_θ⁴ without using ^4
100+ cos_θ² = cos_θ (w) * cos_θ (w)
101+ cos_θ⁴ = cos_θ² * cos_θ²
102+
100103 e = (cos_ϕ (w)^ 2 / (trd. α_x^ 2 ) + sin_ϕ (w)^ 2 / (trd. α_y^ 2 )) * tan_θ²
101104 1f0 / (π * trd. α_x * trd. α_y * cos_θ⁴ * (1f0 + e)^ 2 )
102105end
@@ -210,7 +213,7 @@ function distribution_microfacet_reflection(m::UberBxDF{S}, wo::Vec3f, wi::Vec3f
210213 wh = wi + wo
211214 # Degenerate cases for microfacet reflection.
212215
213- (cosθi ≈ 0 || cosθo ≈ 0 ) && return S (0f0 )
216+ (cosθi ≈ 0f0 || cosθo ≈ 0f0 ) && return S (0f0 )
214217 wh ≈ Vec3f (0 ) && return S (0f0 )
215218 wh = normalize (wh)
216219 f = m. fresnel (wi ⋅ face_forward (wh, Vec3f (0 , 0 , 1 )))
@@ -222,12 +225,12 @@ end
222225 m:: UberBxDF{S} , wo:: Vec3f , u:: Point2f ,
223226 ):: Tuple{Vec3f,Float32,RGBSpectrum,UInt8} where {S<: Spectrum }
224227
225- wo[3 ] ≈ 0 && return Vec3f (0.0f0 ), 0.0f0 , S (0.0f0 ), UInt8 (0 )
228+ wo[3 ] ≈ 0f0 && return Vec3f (0.0f0 ), 0.0f0 , S (0.0f0 ), UInt8 (0 )
226229
227230 # Sample microfacet orientation `wh` and reflected direction `wi`.
228231
229232 wh = sample_wh (m. distribution, wo, u)
230- (wo ⋅ wh) < 0 && return Vec3f (0.0f0 ), 0.0f0 , S (0.0f0 ), UInt8 (0 )
233+ (wo ⋅ wh) < 0f0 && return Vec3f (0.0f0 ), 0.0f0 , S (0.0f0 ), UInt8 (0 )
231234
232235 wi = reflect (wo, wh)
233236 ! same_hemisphere (wo, wi) && return Vec3f (0.0f0 ), 0.0f0 , S (0.0f0 ), UInt8 (0 )
@@ -252,7 +255,7 @@ function distribution_microfacet_transmission(m::UberBxDF{S}, wo::Vec3f, wi::Vec
252255 same_hemisphere (wo, wi) && return S (0f0 )
253256
254257 cosθo, cosθi = cos_θ (wo), cos_θ (wi)
255- (cosθo ≈ 0 || cosθi ≈ 0 ) && return S (0f0 )
258+ (cosθo ≈ 0f0 || cosθi ≈ 0f0 ) && return S (0f0 )
256259 # Compute `wh` from `wo` & `wi` for microfacet transmission.
257260 η = cos_θ (wo) > 0f0 ? (m. η_b / m. η_a) : (m. η_a / m. η_b)
258261 wh = normalize ((wo + wi * η))
275278
276279@inline function sample_microfacet_transmission (m:: UberBxDF{S} , wo:: Vec3f , u:: Point2f ) where {S<: Spectrum }
277280
278- wo[3 ] ≈ 0 && return Vec3f (0f0 ), 0f0 , S (0f0 ), UInt8 (0 )
281+ wo[3 ] ≈ 0f0 && return Vec3f (0f0 ), 0f0 , S (0f0 ), UInt8 (0 )
279282 wh = sample_wh (m. distribution, wo, u)
280283 (wo ⋅ wh) < 0 && return Vec3f (0f0 ), 0f0 , S (0f0 ), UInt8 (0 )
281284
0 commit comments