@@ -29,24 +29,23 @@ NBL_PARTIAL_REQ_TOP(concepts::FloatingPointScalar<T>)
29
29
struct Beckmann<T,false NBL_PARTIAL_REQ_BOT (concepts::FloatingPointScalar<T>) >
30
30
{
31
31
using scalar_type = T;
32
- // using this_t = Beckmann<T,false>;
33
32
34
- scalar_type D (scalar_type a2, scalar_type NdotH2)
33
+ scalar_type D (scalar_type NdotH2)
35
34
{
36
- scalar_type nom = exp <scalar_type>( (NdotH2 - scalar_type (1.0 )) / (a2 * NdotH2) ); // exp(x) == exp2(x/log(2)) ?
35
+ scalar_type nom = exp2 <scalar_type>((NdotH2 - scalar_type (1.0 )) / (log<scalar_type>( 2.0 ) * a2 * NdotH2));
37
36
scalar_type denom = a2 * NdotH2 * NdotH2;
38
37
return numbers::inv_pi<scalar_type> * nom / denom;
39
38
}
40
39
41
40
// brdf
42
- scalar_type DG1 (scalar_type ndf, scalar_type maxNdotV, scalar_type lambda_V)
41
+ scalar_type DG1 (scalar_type ndf, scalar_type maxNdotV, scalar_type lambda_V, NBL_REF_ARG (scalar_type) onePlusLambda_V )
43
42
{
44
43
onePlusLambda_V = scalar_type (1.0 ) + lambda_V;
45
44
return ndf::microfacet_to_light_measure_transform<scalar_type,false ,ndf::MTT_REFLECT>::__call (ndf / onePlusLambda_V, maxNdotV);
46
45
}
47
46
48
47
// bsdf
49
- scalar_type DG1 (scalar_type ndf, scalar_type absNdotV, scalar_type lambda_V, bool transmitted, scalar_type VdotH, scalar_type LdotH, scalar_type VdotHLdotH, scalar_type orientedEta, scalar_type reflectance)
48
+ scalar_type DG1 (scalar_type ndf, scalar_type absNdotV, scalar_type lambda_V, bool transmitted, scalar_type VdotH, scalar_type LdotH, scalar_type VdotHLdotH, scalar_type orientedEta, scalar_type reflectance, NBL_REF_ARG (scalar_type) onePlusLambda_V )
50
49
{
51
50
onePlusLambda_V = scalar_type (1.0 ) + lambda_V;
52
51
return ndf::microfacet_to_light_measure_transform<scalar_type,false ,ndf::MTT_REFLECT_REFRACT>::__call (hlsl::mix (reflectance, scalar_type (1.0 ) - reflectance, transmitted) * ndf / onePlusLambda_V, absNdotV, transmitted, VdotH, LdotH, VdotHLdotH, orientedEta);
@@ -57,7 +56,7 @@ struct Beckmann<T,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
57
56
return scalar_type (1.0 ) / (scalar_type (1.0 ) + lambda);
58
57
}
59
58
60
- scalar_type C2 (scalar_type NdotX2, scalar_type a2 )
59
+ scalar_type C2 (scalar_type NdotX2)
61
60
{
62
61
return NdotX2 / (a2 * (scalar_type (1.0 ) - NdotX2));
63
62
}
@@ -70,31 +69,25 @@ struct Beckmann<T,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
70
69
return hlsl::mix<scalar_type>(scalar_type (0.0 ), nom / denom, c < scalar_type (1.6 ));
71
70
}
72
71
73
- scalar_type Lambda (scalar_type NdotX2, scalar_type a2 )
72
+ scalar_type LambdaC2 (scalar_type NdotX2)
74
73
{
75
- return Lambda (C2 (NdotX2, a2 ));
74
+ return Lambda (C2 (NdotX2));
76
75
}
77
76
78
- scalar_type correlated (scalar_type a2, scalar_type NdotV2, scalar_type NdotL2)
77
+ scalar_type correlated (scalar_type NdotV2, scalar_type NdotL2)
79
78
{
80
- scalar_type c2 = C2 (NdotV2, a2);
81
- scalar_type L_v = Lambda (c2);
82
- c2 = C2 (NdotL2, a2);
83
- scalar_type L_l = Lambda (c2);
79
+ scalar_type L_v = LambdaC2 (NdotV2);
80
+ scalar_type L_l = LambdaC2 (NdotL2);
84
81
return scalar_type (1.0 ) / (scalar_type (1.0 ) + L_v + L_l);
85
82
}
86
83
87
- scalar_type G2_over_G1 (scalar_type a2, bool transmitted, scalar_type NdotL2, scalar_type lambdaV_plus_one)
84
+ scalar_type G2_over_G1 (bool transmitted, scalar_type NdotL2, scalar_type lambdaV_plus_one)
88
85
{
89
- scalar_type lambdaL = Lambda (NdotL2, a2);
90
- return hlsl::mix (
91
- lambdaV_plus_one / (lambdaV_plus_one + lambdaL),
92
- lambdaV_plus_one * hlsl::beta<scalar_type>(lambdaV_plus_one, scalar_type (1.0 ) + lambdaL),
93
- transmitted
94
- );
86
+ scalar_type lambdaL = LambdaC2 (NdotL2);
87
+ return lambdaV_plus_one * hlsl::mix (scalar_type (1.0 )/(lambdaV_plus_one + lambdaL), hlsl::beta<scalar_type>(lambdaV_plus_one, scalar_type (1.0 ) + lambdaL), transmitted);
95
88
}
96
89
97
- scalar_type onePlusLambda_V ;
90
+ scalar_type a2 ;
98
91
};
99
92
100
93
@@ -104,26 +97,26 @@ struct Beckmann<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
104
97
{
105
98
using scalar_type = T;
106
99
107
- scalar_type D (scalar_type ax, scalar_type ay, scalar_type ax2, scalar_type ay2, scalar_type TdotH2, scalar_type BdotH2, scalar_type NdotH2)
100
+ scalar_type D (scalar_type TdotH2, scalar_type BdotH2, scalar_type NdotH2)
108
101
{
102
+ const scalar_type ax2 = ax*ax;
103
+ const scalar_type ay2 = ay*ay;
109
104
scalar_type nom = exp<scalar_type>(-(TdotH2 / ax2 + BdotH2 / ay2) / NdotH2);
110
105
scalar_type denom = ax * ay * NdotH2 * NdotH2;
111
106
return numbers::inv_pi<scalar_type> * nom / denom;
112
107
}
113
108
114
- scalar_type DG1 (scalar_type ndf, scalar_type maxNdotV, scalar_type lambda_V)
109
+ scalar_type DG1 (scalar_type ndf, scalar_type maxNdotV, scalar_type lambda_V, NBL_REF_ARG (scalar_type) onePlusLambda_V )
115
110
{
116
111
Beckmann<T,false > beckmann;
117
- scalar_type dg = beckmann.DG1 (ndf, maxNdotV, lambda_V);
118
- onePlusLambda_V = beckmann.onePlusLambda_V;
112
+ scalar_type dg = beckmann.DG1 (ndf, maxNdotV, lambda_V, onePlusLambda_V);
119
113
return dg;
120
114
}
121
115
122
- scalar_type DG1 (scalar_type ndf, scalar_type absNdotV, scalar_type lambda_V, bool transmitted, scalar_type VdotH, scalar_type LdotH, scalar_type VdotHLdotH, scalar_type orientedEta, scalar_type reflectance)
116
+ scalar_type DG1 (scalar_type ndf, scalar_type absNdotV, scalar_type lambda_V, bool transmitted, scalar_type VdotH, scalar_type LdotH, scalar_type VdotHLdotH, scalar_type orientedEta, scalar_type reflectance, NBL_REF_ARG (scalar_type) onePlusLambda_V )
123
117
{
124
118
Beckmann<T,false > beckmann;
125
- scalar_type dg = beckmann.DG1 (ndf, absNdotV, lambda_V, transmitted, VdotH, LdotH, VdotHLdotH, orientedEta, reflectance);
126
- onePlusLambda_V = beckmann.onePlusLambda_V;
119
+ scalar_type dg = beckmann.DG1 (ndf, absNdotV, lambda_V, transmitted, VdotH, LdotH, VdotHLdotH, orientedEta, reflectance, onePlusLambda_V);
127
120
return dg;
128
121
}
129
122
@@ -132,8 +125,10 @@ struct Beckmann<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
132
125
return scalar_type (1.0 ) / (scalar_type (1.0 ) + lambda);
133
126
}
134
127
135
- scalar_type C2 (scalar_type TdotX2, scalar_type BdotX2, scalar_type NdotX2, scalar_type ax2, scalar_type ay2 )
128
+ scalar_type C2 (scalar_type TdotX2, scalar_type BdotX2, scalar_type NdotX2)
136
129
{
130
+ const scalar_type ax2 = ax*ax;
131
+ const scalar_type ay2 = ay*ay;
137
132
return NdotX2 / (TdotX2 * ax2 + BdotX2 * ay2);
138
133
}
139
134
@@ -145,32 +140,26 @@ struct Beckmann<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
145
140
return hlsl::mix<scalar_type>(scalar_type (0.0 ), nom / denom, c < scalar_type (1.6 ));
146
141
}
147
142
148
- scalar_type Lambda (scalar_type TdotX2, scalar_type BdotX2, scalar_type NdotX2, scalar_type ax2, scalar_type ay2 )
143
+ scalar_type LambdaC2 (scalar_type TdotX2, scalar_type BdotX2, scalar_type NdotX2)
149
144
{
150
- return Lambda (C2 (TdotX2, BdotX2, NdotX2, ax2, ay2 ));
145
+ return Lambda (C2 (TdotX2, BdotX2, NdotX2));
151
146
}
152
147
153
- scalar_type correlated (scalar_type ax2, scalar_type ay2, scalar_type TdotV2, scalar_type BdotV2, scalar_type NdotV2, scalar_type TdotL2, scalar_type BdotL2, scalar_type NdotL2)
148
+ scalar_type correlated (scalar_type TdotV2, scalar_type BdotV2, scalar_type NdotV2, scalar_type TdotL2, scalar_type BdotL2, scalar_type NdotL2)
154
149
{
155
- scalar_type c2 = C2 (TdotV2, BdotV2, NdotV2, ax2, ay2);
156
- scalar_type L_v = Lambda (c2);
157
- c2 = C2 (TdotL2, BdotL2, NdotL2, ax2, ay2);
158
- scalar_type L_l = Lambda (c2);
159
- return G1 (L_v + L_l);
150
+ scalar_type L_v = LambdaC2 (TdotV2, BdotV2, NdotV2);
151
+ scalar_type L_l = LambdaC2 (TdotL2, BdotL2, NdotL2);
152
+ return scalar_type (1.0 ) / (scalar_type (1.0 ) + L_v + L_l);
160
153
}
161
154
162
- scalar_type G2_over_G1 (scalar_type ax2, scalar_type ay2, bool transmitted, scalar_type TdotL2, scalar_type BdotL2, scalar_type NdotL2, scalar_type lambdaV_plus_one)
155
+ scalar_type G2_over_G1 (bool transmitted, scalar_type TdotL2, scalar_type BdotL2, scalar_type NdotL2, scalar_type lambdaV_plus_one)
163
156
{
164
- scalar_type c2 = C2 (TdotL2, BdotL2, NdotL2, ax2, ay2);
165
- scalar_type lambdaL = Lambda (c2);
166
- return hlsl::mix (
167
- lambdaV_plus_one / (lambdaV_plus_one + lambdaL),
168
- lambdaV_plus_one * hlsl::beta<scalar_type>(lambdaV_plus_one, scalar_type (1.0 ) + lambdaL),
169
- transmitted
170
- );
157
+ scalar_type lambdaL = LambdaC2 (TdotL2, BdotL2, NdotL2);
158
+ return lambdaV_plus_one * hlsl::mix (scalar_type (1.0 )/(lambdaV_plus_one + lambdaL), hlsl::beta<scalar_type>(lambdaV_plus_one, scalar_type (1.0 ) + lambdaL), transmitted);
171
159
}
172
160
173
- scalar_type onePlusLambda_V;
161
+ scalar_type ax;
162
+ scalar_type ay;
174
163
};
175
164
176
165
}
0 commit comments