@@ -165,13 +165,24 @@ struct SCookTorrance
165
165
template<typename C=bool_constant<!IsBSDF> >
166
166
enable_if_t<C::value && !IsBSDF, sample_type> generate (NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction, const vector2_type u, NBL_REF_ARG (anisocache_type) cache)
167
167
{
168
+ ray_dir_info_type localV_raydir = interaction.getV ().transform (interaction.getToTangentSpace ());
168
169
const vector3_type localV = interaction.getTangentSpaceV ();
169
170
const vector3_type localH = ndf.generateH (localV, u);
170
171
171
172
cache = anisocache_type::createForReflection (localV, localH);
172
- ray_dir_info_type localL;
173
+ // struct reflect_wrapper
174
+ // {
175
+ // vector3_type operator()()
176
+ // {
177
+ // return r(VdotH);
178
+ // }
179
+ // bxdf::Reflect<scalar_type> r;
180
+ // scalar_type VdotH;
181
+ // };
182
+ // reflect_wrapper r;
173
183
bxdf::Reflect<scalar_type> r = bxdf::Reflect<scalar_type>::create (localV, localH);
174
- localL = localL.reflect (r);
184
+ // r.VdotH = cache.getVdotH();
185
+ ray_dir_info_type localL = localV_raydir.reflect (r);
175
186
176
187
return sample_type::createFromTangentSpace (localL, interaction.getFromTangentSpace ());
177
188
}
@@ -180,33 +191,31 @@ struct SCookTorrance
180
191
{
181
192
fresnel::OrientedEtaRcps<monochrome_type> rcpEta = fresnel.getOrientedEtaRcps ();
182
193
194
+ ray_dir_info_type V = interaction.getV ();
183
195
const vector3_type localV = interaction.getTangentSpaceV ();
184
- const vector3_type upperHemisphereV = ieee754::flipSignIfRHSNegative<vector3_type>(localV, hlsl::promote<vector3_type>(interaction.getNdotV ())); //hlsl::mix(localV, -localV, interaction.getNdotV() < scalar_type(0.0));
196
+ const vector3_type upperHemisphereV = ieee754::flipSignIfRHSNegative<vector3_type>(localV, hlsl::promote<vector3_type>(interaction.getNdotV ()));
185
197
const vector3_type localH = ndf.generateH (upperHemisphereV, u.xy);
198
+ const vector3_type H = hlsl::mul (interaction.getFromTangentSpace (), localH);
186
199
187
- const scalar_type VdotH = hlsl::dot (localV, localH );
200
+ const scalar_type VdotH = hlsl::dot (V. getDirection (), H );
188
201
const scalar_type reflectance = fresnel (hlsl::abs (VdotH))[0 ];
189
202
190
203
scalar_type rcpChoiceProb;
191
204
scalar_type z = u.z;
192
205
bool transmitted = math::partitionRandVariable (reflectance, z, rcpChoiceProb);
193
206
194
- Refract<scalar_type> r = Refract<scalar_type>::create (localV, localH);
195
- ray_dir_info_type localL;
207
+ Refract<scalar_type> r = Refract<scalar_type>::create (V.getDirection (), H);
196
208
bxdf::ReflectRefract<scalar_type> rr;
197
209
rr.refract = r;
198
- localL = localL .reflectRefract (rr, transmitted, rcpEta.value[0 ]);
210
+ ray_dir_info_type L = V .reflectRefract (rr, transmitted, rcpEta.value[0 ]);
199
211
200
212
// fail if samples have invalid paths
201
- // TODO fix this: if (ComputeMicrofacetNormal<scalar_type>::isTransmissionPath(VdotH, hlsl::dot(localL.getDirection(), localH)) != transmitted)
202
- if ((!transmitted && hlsl::sign (localL.getDirection ().z) != hlsl::sign (localV.z)) || (transmitted && hlsl::sign (localL.getDirection ().z) == hlsl::sign (localV.z)))
203
- {
204
- localL.direction = vector3_type (0 ,0 ,0 ); // should check if sample direction is invalid
205
- }
213
+ if (ComputeMicrofacetNormal<scalar_type>::isTransmissionPath (VdotH, hlsl::dot (L.getDirection (), H)) != transmitted)
214
+ L.direction = vector3_type (0 ,0 ,0 ); // should check if sample direction is invalid
206
215
else
207
- cache = anisocache_type::create (localV, localH, transmitted, rcpEta );
216
+ cache = anisocache_type::create (VdotH, L. getDirection (), H, interaction. getT (), interaction. getB (), interaction. getN (), transmitted );
208
217
209
- return sample_type::createFromTangentSpace (localL , interaction.getFromTangentSpace ());
218
+ return sample_type::create (L , interaction.getT (), interaction. getB (), interaction. getN ());
210
219
}
211
220
template<typename C=bool_constant<!IsAnisotropic>, typename D=bool_constant<!IsBSDF> >
212
221
enable_if_t<C::value && !IsAnisotropic && D::value && !IsBSDF, sample_type> generate (NBL_CONST_REF_ARG (isotropic_interaction_type) interaction, const vector2_type u, NBL_REF_ARG (isocache_type) cache)
0 commit comments