@@ -113,6 +113,15 @@ vec3 EvalClearcoat(Material mat, vec3 V, vec3 N, vec3 L, vec3 H, inout float pdf
113
113
return vec3 (0.25 * mat.clearcoat * F * D * G);
114
114
}
115
115
116
+ void GetSpecColor(Material mat, float eta, inout vec3 specCol, inout vec3 sheenCol)
117
+ {
118
+ float lum = Luminance(mat.baseColor);
119
+ vec3 ctint = lum > 0.0 ? mat.baseColor / lum : vec3 (1 .0f);
120
+ float F0 = (1.0 - eta) / (1.0 + eta);
121
+ specCol = mix (F0 * F0 * mix (vec3 (1.0 ), ctint, mat.specularTint), mat.baseColor, mat.metallic);
122
+ sheenCol = mix (vec3 (1.0 ), ctint, mat.sheenTint);
123
+ }
124
+
116
125
void GetLobeProbabilities(Material mat, float eta, vec3 specCol, float approxFresnel, inout float diffuseWt, inout float specReflectWt, inout float specRefractWt, inout float clearcoatWt)
117
126
{
118
127
diffuseWt = Luminance(mat.baseColor) * (1.0 - mat.metallic) * (1.0 - mat.specTrans);
@@ -135,12 +144,9 @@ vec3 DisneySample(State state, vec3 V, vec3 N, inout vec3 L, inout float pdf)
135
144
float r1 = rand();
136
145
float r2 = rand();
137
146
138
- // Compute specular color
139
- float lum = Luminance(state.mat.baseColor);
140
- vec3 ctint = lum > 0.0 ? state.mat.baseColor / lum : vec3 (1 .0f);
141
- float F0 = state.eta < 1.0 ? (1.0 - state.mat.ior) / (1.0 + state.mat.ior) : (state.mat.ior - 1.0 ) / (state.mat.ior + 1.0 );
142
- vec3 specCol = mix (F0 * F0 * mix (vec3 (1.0 ), ctint, state.mat.specularTint), state.mat.baseColor, state.mat.metallic);
143
- vec3 csheen = mix (vec3 (1.0 ), ctint, state.mat.sheenTint);
147
+ // Specular and sheen color
148
+ vec3 specCol, sheenCol;
149
+ GetSpecColor(state.mat, state.eta, specCol, sheenCol);
144
150
145
151
// Lobe weights
146
152
float diffuseWt, specReflectWt, specRefractWt, clearcoatWt;
@@ -165,7 +171,7 @@ vec3 DisneySample(State state, vec3 V, vec3 N, inout vec3 L, inout float pdf)
165
171
166
172
vec3 H = normalize (L + V);
167
173
168
- f = EvalDiffuse(state.mat, csheen , V, N, L, H, pdf);
174
+ f = EvalDiffuse(state.mat, sheenCol , V, N, L, H, pdf);
169
175
pdf *= diffuseWt;
170
176
}
171
177
else if (r1 < cdf[1 ]) // Specular Reflection Lobe
@@ -174,7 +180,7 @@ vec3 DisneySample(State state, vec3 V, vec3 N, inout vec3 L, inout float pdf)
174
180
vec3 H = SampleGTR2(state.mat.roughness, r1, r2);
175
181
H = T * H.x + B * H.y + N * H.z;
176
182
177
- if (dot (V, H) <= 0.0 )
183
+ if (dot (V, H) < 0.0 )
178
184
H = - H;
179
185
180
186
L = normalize (reflect (- V, H));
@@ -188,7 +194,7 @@ vec3 DisneySample(State state, vec3 V, vec3 N, inout vec3 L, inout float pdf)
188
194
vec3 H = SampleGTR2(state.mat.roughness, r1, r2);
189
195
H = T * H.x + B * H.y + N * H.z;
190
196
191
- if (dot (V, H) <= 0.0 )
197
+ if (dot (V, H) < 0.0 )
192
198
H = - H;
193
199
194
200
L = normalize (refract (- V, H, state.eta));
@@ -202,7 +208,7 @@ vec3 DisneySample(State state, vec3 V, vec3 N, inout vec3 L, inout float pdf)
202
208
vec3 H = SampleGTR1(state.mat.clearcoatRoughness, r1, r2);
203
209
H = T * H.x + B * H.y + N * H.z;
204
210
205
- if (dot (V, H) <= 0.0 )
211
+ if (dot (V, H) < 0.0 )
206
212
H = - H;
207
213
208
214
L = normalize (reflect (- V, H));
@@ -231,12 +237,9 @@ vec3 DisneyEval(State state, vec3 V, vec3 N, vec3 L, inout float bsdfPdf)
231
237
if (dot (V, H) < 0.0 )
232
238
H = - H;
233
239
234
- // Compute specular color
235
- float lum = Luminance(state.mat.baseColor);
236
- vec3 ctint = lum > 0.0 ? state.mat.baseColor / lum : vec3 (1 .0f);
237
- float F0 = state.eta < 1.0 ? (1.0 - state.mat.ior) / (1.0 + state.mat.ior) : (state.mat.ior - 1.0 ) / (state.mat.ior + 1.0 );
238
- vec3 specCol = mix (F0 * F0 * mix (vec3 (1.0 ), ctint, state.mat.specularTint), state.mat.baseColor, state.mat.metallic);
239
- vec3 csheen = mix (vec3 (1.0 ), ctint, state.mat.sheenTint);
240
+ // Specular and sheen color
241
+ vec3 specCol, sheenCol;
242
+ GetSpecColor(state.mat, state.eta, specCol, sheenCol);
240
243
241
244
// Lobe weights
242
245
float diffuseWt, specReflectWt, specRefractWt, clearcoatWt;
@@ -248,7 +251,7 @@ vec3 DisneyEval(State state, vec3 V, vec3 N, vec3 L, inout float bsdfPdf)
248
251
// Diffuse
249
252
if (diffuseWt > 0.0 && NDotL > 0.0 )
250
253
{
251
- f += EvalDiffuse(state.mat, csheen , V, N, L, H, pdf);
254
+ f += EvalDiffuse(state.mat, sheenCol , V, N, L, H, pdf);
252
255
bsdfPdf += pdf * diffuseWt;
253
256
}
254
257
0 commit comments