@@ -22,6 +22,23 @@ namespace bxdf
22
22
namespace fresnel
23
23
{
24
24
25
+ // derived from the Earl Hammon GDC talk but improved for all IOR not just 1.333 with actual numerical integration and curve fitting
26
+ template<typename T NBL_PRIMARY_REQUIRES (concepts::FloatingPointLikeVectorial<T>)
27
+ struct DiffuseCorrectionFactor
28
+ {
29
+ T operator ()()
30
+ {
31
+ vector <bool ,vector_traits<T>::Dimension> TIR = orientedEta < hlsl::promote<T>(1.0 );
32
+ T invdenum = nbl::hlsl::mix<T>(hlsl::promote<T>(1.0 ), hlsl::promote<T>(1.0 ) / (orientedEta2 * orientedEta2 * (hlsl::promote<T>(554.33 ) - hlsl::promote<T>(380.7 ) * orientedEta)), TIR);
33
+ T num = orientedEta * nbl::hlsl::mix<T>(hlsl::promote<T>(0.1921156102251088 ), orientedEta * hlsl::promote<T>(298.25 ) - hlsl::promote<T>(261.38 ) * orientedEta2 + hlsl::promote<T>(138.43 ), TIR);
34
+ num = num + nbl::hlsl::mix<T>(hlsl::promote<T>(0.8078843897748912 ), hlsl::promote<T>(-1.67 ), TIR);
35
+ return num * invdenum;
36
+ }
37
+
38
+ T orientedEta;
39
+ T orientedEta2;
40
+ };
41
+
25
42
template<typename T NBL_PRIMARY_REQUIRES (concepts::FloatingPointLikeVectorial<T>)
26
43
struct OrientedEtaRcps
27
44
{
@@ -37,17 +54,12 @@ struct OrientedEtaRcps
37
54
return retval;
38
55
}
39
56
40
- T diffuseFresnelCorrectionFactor ()
57
+ DiffuseCorrectionFactor<T> createDiffuseCorrectionFactor () NBL_CONST_MEMBER_FUNC
41
58
{
42
- // assert(n*n==n2);
43
- const T n = hlsl::promote<T>(1.0 ) / value;
44
- const T n2 = hlsl::promote<T>(1.0 ) / value2;
45
-
46
- vector <bool ,vector_traits<T>::Dimension> TIR = n < hlsl::promote<T>(1.0 );
47
- T invdenum = nbl::hlsl::mix<T>(hlsl::promote<T>(1.0 ), hlsl::promote<T>(1.0 ) / (n2 * n2 * (hlsl::promote<T>(554.33 ) - hlsl::promote<T>(380.7 ) * n)), TIR);
48
- T num = n * nbl::hlsl::mix<T>(hlsl::promote<T>(0.1921156102251088 ), n * hlsl::promote<T>(298.25 ) - hlsl::promote<T>(261.38 ) * n2 + hlsl::promote<T>(138.43 ), TIR);
49
- num += nbl::hlsl::mix<T>(hlsl::promote<T>(0.8078843897748912 ), hlsl::promote<T>(-1.67 ), TIR);
50
- return num * invdenum;
59
+ DiffuseCorrectionFactor<T> diffuseCorrectionFactor;
60
+ diffuseCorrectionFactor.orientedEta = hlsl::promote<T>(1.0 ) / value;
61
+ diffuseCorrectionFactor.orientedEta2 = hlsl::promote<T>(1.0 ) / value2;
62
+ return diffuseCorrectionFactor;
51
63
}
52
64
53
65
T value;
0 commit comments