-
Notifications
You must be signed in to change notification settings - Fork 67
Iridescent fresnel, bxdfs #918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
4b3224a
9c71906
0f51306
f205d4e
f6daa6f
09402ea
a77c337
aa0f6e8
d2cb193
33fc955
0f6c7a2
d8b6773
65239d9
9a8b77e
702ec8d
76ad0ed
53c930f
23de8ed
ff9e03f
18b3922
a5d8f5c
f3dd05c
68d3614
aebfecf
b53fa1b
946b050
1a2f561
4b8a06b
5782a49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,11 +188,14 @@ NBL_CONCEPT_END( | |
| ((NBL_CONCEPT_REQ_TYPE)(T::ray_dir_info_type)) | ||
| ((NBL_CONCEPT_REQ_TYPE)(T::scalar_type)) | ||
| ((NBL_CONCEPT_REQ_TYPE)(T::vector3_type)) | ||
| ((NBL_CONCEPT_REQ_TYPE)(T::spectral_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getV()), ::nbl::hlsl::is_same_v, typename T::ray_dir_info_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getN()), ::nbl::hlsl::is_same_v, typename T::vector3_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getNdotV(clampMode)), ::nbl::hlsl::is_same_v, typename T::scalar_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getNdotV2()), ::nbl::hlsl::is_same_v, typename T::scalar_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getPathOrigin()), ::nbl::hlsl::is_same_v, PathOrigin)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getLuminosityContributionHint()), ::nbl::hlsl::is_same_v, typename T::spectral_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getPrefixThroughputWeights()), ::nbl::hlsl::is_same_v, typename T::spectral_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(normV,normN)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(ray_dir_info::Basic, typename T::ray_dir_info_type)) | ||
| ); | ||
|
|
@@ -202,21 +205,25 @@ NBL_CONCEPT_END( | |
| #undef iso | ||
| #include <nbl/builtin/hlsl/concepts/__end.hlsl> | ||
|
|
||
| template<class RayDirInfo NBL_PRIMARY_REQUIRES(ray_dir_info::Basic<RayDirInfo>) | ||
| template<class RayDirInfo, class Spectrum NBL_PRIMARY_REQUIRES(ray_dir_info::Basic<RayDirInfo> && concepts::FloatingPointLikeVectorial<Spectrum>) | ||
| struct SIsotropic | ||
| { | ||
| using this_t = SIsotropic<RayDirInfo, Spectrum>; | ||
| using ray_dir_info_type = RayDirInfo; | ||
| using scalar_type = typename RayDirInfo::scalar_type; | ||
| using vector3_type = typename RayDirInfo::vector3_type; | ||
| using spectral_type = vector3_type; | ||
|
|
||
| // WARNING: Changed since GLSL, now arguments need to be normalized! | ||
| static SIsotropic<RayDirInfo> create(NBL_CONST_REF_ARG(RayDirInfo) normalizedV, const vector3_type normalizedN) | ||
| static this_t create(NBL_CONST_REF_ARG(RayDirInfo) normalizedV, const vector3_type normalizedN) | ||
| { | ||
| SIsotropic<RayDirInfo> retval; | ||
| this_t retval; | ||
| retval.V = normalizedV; | ||
| retval.N = normalizedN; | ||
| retval.NdotV = nbl::hlsl::dot<vector3_type>(retval.N, retval.V.getDirection()); | ||
| retval.NdotV2 = retval.NdotV * retval.NdotV; | ||
| retval.luminosityContributionHint = hlsl::promote<spectral_type>(1.0); | ||
| retval.throughputWeights = hlsl::promote<spectral_type>(1.0); | ||
|
|
||
| return retval; | ||
| } | ||
|
|
@@ -230,11 +237,20 @@ struct SIsotropic | |
| scalar_type getNdotV2() NBL_CONST_MEMBER_FUNC { return NdotV2; } | ||
|
|
||
| PathOrigin getPathOrigin() NBL_CONST_MEMBER_FUNC { return PathOrigin::PO_SENSOR; } | ||
| spectral_type getLuminosityContributionHint() NBL_CONST_MEMBER_FUNC { return luminosityContributionHint; } | ||
| spectral_type getPrefixThroughputWeights() NBL_CONST_MEMBER_FUNC | ||
| { | ||
| spectral_type prefixThroughputWeights = luminosityContributionHint * throughputWeights; | ||
| return prefixThroughputWeights / math::lpNorm<spectral_type,1>(prefixThroughputWeights); | ||
| } | ||
|
|
||
| RayDirInfo V; | ||
| vector3_type N; | ||
| scalar_type NdotV; | ||
| scalar_type NdotV2; | ||
|
|
||
| spectral_type luminosityContributionHint; | ||
| spectral_type throughputWeights; // product of all quotients so far | ||
|
||
| }; | ||
|
|
||
| #define NBL_CONCEPT_NAME Anisotropic | ||
|
|
@@ -278,6 +294,7 @@ struct SAnisotropic | |
| using scalar_type = typename ray_dir_info_type::scalar_type; | ||
| using vector3_type = typename ray_dir_info_type::vector3_type; | ||
| using matrix3x3_type = matrix<scalar_type, 3, 3>; | ||
| using spectral_type = typename isotropic_interaction_type::spectral_type; | ||
|
|
||
| // WARNING: Changed since GLSL, now arguments need to be normalized! | ||
| static this_t create( | ||
|
|
@@ -319,6 +336,8 @@ struct SAnisotropic | |
| scalar_type getNdotV(BxDFClampMode _clamp = BxDFClampMode::BCM_NONE) NBL_CONST_MEMBER_FUNC { return isotropic.getNdotV(_clamp); } | ||
| scalar_type getNdotV2() NBL_CONST_MEMBER_FUNC { return isotropic.getNdotV2(); } | ||
| PathOrigin getPathOrigin() NBL_CONST_MEMBER_FUNC { return isotropic.getPathOrigin(); } | ||
| spectral_type getLuminosityContributionHint() NBL_CONST_MEMBER_FUNC { return isotropic.getLuminosityContributionHint(); } | ||
| spectral_type getPrefixThroughputWeights() NBL_CONST_MEMBER_FUNC { return isotropic.getPrefixThroughputWeights(); } | ||
|
|
||
| vector3_type getT() NBL_CONST_MEMBER_FUNC { return T; } | ||
| vector3_type getB() NBL_CONST_MEMBER_FUNC { return B; } | ||
|
|
@@ -345,7 +364,7 @@ struct SAnisotropic | |
| #define NBL_CONCEPT_TPLT_PRM_KINDS (typename) | ||
| #define NBL_CONCEPT_TPLT_PRM_NAMES (T) | ||
| #define NBL_CONCEPT_PARAM_0 (_sample, T) | ||
| #define NBL_CONCEPT_PARAM_1 (inter, surface_interactions::SIsotropic<typename T::ray_dir_info_type>) | ||
| #define NBL_CONCEPT_PARAM_1 (inter, surface_interactions::SIsotropic<typename T::ray_dir_info_type, typename T::vector3_type>) | ||
| #define NBL_CONCEPT_PARAM_2 (rdirinfo, typename T::ray_dir_info_type) | ||
| #define NBL_CONCEPT_PARAM_3 (pV, typename T::vector3_type) | ||
| #define NBL_CONCEPT_PARAM_4 (frame, typename T::matrix3x3_type) | ||
|
|
@@ -376,7 +395,7 @@ NBL_CONCEPT_END( | |
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(rdirinfo,pV)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(rdirinfo,pV,pV,pV)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(rdirinfo,pV,pV,pNdotL)), ::nbl::hlsl::is_same_v, T)) | ||
| // ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SIsotropic<typename T::ray_dir_info_type> >(pV,inter)), ::nbl::hlsl::is_same_v, T)) // NOTE: temporarily commented out due to dxc bug https://github.com/microsoft/DirectXShaderCompiler/issues/7154 | ||
| // ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SIsotropic<typename T::ray_dir_info_type, typename T::vector3_type> >(pV,inter)), ::nbl::hlsl::is_same_v, T)) // NOTE: temporarily commented out due to dxc bug https://github.com/microsoft/DirectXShaderCompiler/issues/7154 | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getTangentSpaceL()), ::nbl::hlsl::is_same_v, typename T::vector3_type)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createInvalid()), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(ray_dir_info::Basic, typename T::ray_dir_info_type)) | ||
|
|
@@ -525,7 +544,7 @@ NBL_CONCEPT_END( | |
| #define NBL_CONCEPT_TPLT_PRM_KINDS (typename) | ||
| #define NBL_CONCEPT_TPLT_PRM_NAMES (T) | ||
| #define NBL_CONCEPT_PARAM_0 (cache, T) | ||
| #define NBL_CONCEPT_PARAM_1 (iso, surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type> >) | ||
| #define NBL_CONCEPT_PARAM_1 (iso, surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type >) | ||
| #define NBL_CONCEPT_PARAM_2 (pNdotV, typename T::scalar_type) | ||
| #define NBL_CONCEPT_PARAM_3 (_sample, SLightSample<ray_dir_info::SBasic<typename T::scalar_type> >) | ||
| #define NBL_CONCEPT_PARAM_4 (V, typename T::vector3_type) | ||
|
|
@@ -540,9 +559,9 @@ NBL_CONCEPT_BEGIN(6) | |
| NBL_CONCEPT_END( | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(pNdotV,pNdotV,pNdotV,pNdotV)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(pNdotV,pNdotV,pNdotV)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template createForReflection<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type> >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(iso,_sample)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template createForReflection<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(iso,_sample)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(V,V,V,eta,V)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type> >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(iso,_sample,eta,V)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(iso,_sample,eta,V)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(ReadableIsotropicMicrofacetCache, T)) | ||
| ); | ||
| #undef eta | ||
|
|
@@ -698,7 +717,7 @@ struct SIsotropicMicrofacetCache | |
| #define NBL_CONCEPT_TPLT_PRM_KINDS (typename) | ||
| #define NBL_CONCEPT_TPLT_PRM_NAMES (T) | ||
| #define NBL_CONCEPT_PARAM_0 (cache, T) | ||
| #define NBL_CONCEPT_PARAM_1 (aniso, surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type> > >) | ||
| #define NBL_CONCEPT_PARAM_1 (aniso, surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type > >) | ||
| #define NBL_CONCEPT_PARAM_2 (pNdotL, typename T::scalar_type) | ||
| #define NBL_CONCEPT_PARAM_3 (_sample, SLightSample<ray_dir_info::SBasic<typename T::scalar_type> >) | ||
| #define NBL_CONCEPT_PARAM_4 (V, typename T::vector3_type) | ||
|
|
@@ -724,9 +743,9 @@ NBL_CONCEPT_END( | |
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(V,V)), ::nbl::hlsl::is_same_v, T)) | ||
| // ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(V,V,b0,rcp_eta)), ::nbl::hlsl::is_same_v, T)) // TODO: refuses to compile when arg4 is rcp_eta for some reason, eta is fine | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(V,V,pNdotL)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template createForReflection<surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type> > >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(aniso,_sample)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template createForReflection<surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type > >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(aniso,_sample)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(V,V,V,V,V,eta,V)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type> > >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(aniso,_sample,eta)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type > >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(aniso,_sample,eta)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createPartial(pNdotL,pNdotL,pNdotL,b0,rcp_eta)), ::nbl::hlsl::is_same_v, T)) | ||
| ((NBL_CONCEPT_REQ_EXPR)(cache.fillTangents(V,V,V))) | ||
| ((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(CreatableIsotropicMicrofacetCache, typename T::isocache_type)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,11 +107,12 @@ struct BeckmannCommon<T,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar< | |
| isInfinity = true; | ||
| return bit_cast<scalar_type>(numeric_limits<scalar_type>::infinity); | ||
| } | ||
| isInfinity = false; | ||
| scalar_type NdotH2 = cache.getNdotH2(); | ||
| scalar_type nom = exp2<scalar_type>((NdotH2 - scalar_type(1.0)) / (log<scalar_type>(2.0) * a2 * NdotH2)); | ||
| scalar_type denom = a2 * NdotH2 * NdotH2; | ||
| return numbers::inv_pi<scalar_type> * nom / denom; | ||
| scalar_type ndf = numbers::inv_pi<scalar_type> * nom / denom; | ||
| isInfinity = hlsl::isinf(ndf); | ||
| return ndf; | ||
| } | ||
|
|
||
| scalar_type C2(scalar_type NdotX2) | ||
|
|
@@ -141,7 +142,9 @@ struct BeckmannCommon<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T | |
| scalar_type NdotH2 = cache.getNdotH2(); | ||
| scalar_type nom = exp<scalar_type>(-(cache.getTdotH2() / ax2 + cache.getBdotH2() / ay2) / NdotH2); | ||
| scalar_type denom = a2 * NdotH2 * NdotH2; | ||
| return numbers::inv_pi<scalar_type> * nom / denom; | ||
| scalar_type ndf = numbers::inv_pi<scalar_type> * nom / denom; | ||
| isInfinity = hlsl::isinf(ndf); | ||
| return ndf; | ||
| } | ||
|
|
||
| scalar_type C2(scalar_type TdotX2, scalar_type BdotX2, scalar_type NdotX2) | ||
|
|
@@ -277,12 +280,7 @@ struct Beckmann | |
| quant_query_type quant_query; // only has members for refraction | ||
| NBL_IF_CONSTEXPR(SupportsTransmission) | ||
| { | ||
| quant_query.VdotHLdotH = cache.getVdotHLdotH(); | ||
| const scalar_type VdotH = cache.getVdotH(); | ||
| const scalar_type VdotH_etaLdotH = hlsl::mix(VdotH + orientedEta * cache.getLdotH(), | ||
| VdotH / orientedEta + cache.getLdotH(), | ||
| interaction.getPathOrigin() == PathOrigin::PO_SENSOR); | ||
| quant_query.neg_rcp2_refractionDenom = scalar_type(-1.0) / (VdotH_etaLdotH * VdotH_etaLdotH); | ||
| quant_query = quant_query_type::template create<Interaction, MicrofacetCache>(interaction, cache, orientedEta); | ||
| } | ||
| return quant_query; | ||
| } | ||
|
|
@@ -337,8 +335,13 @@ struct Beckmann | |
| quant_type DG1(NBL_CONST_REF_ARG(dg1_query_type) query, NBL_CONST_REF_ARG(quant_query_type) quant_query, NBL_CONST_REF_ARG(LS) _sample, NBL_CONST_REF_ARG(Interaction) interaction, NBL_REF_ARG(bool) isInfinity) | ||
| { | ||
| scalar_type D = query.getNdf(); | ||
| scalar_type dg1 = query.getNdf() / (scalar_type(1.0) + query.getLambdaV()); | ||
| isInfinity = D == bit_cast<scalar_type>(numeric_limits<scalar_type>::infinity); | ||
| isInfinity = hlsl::isinf(D); | ||
| if (isInfinity) | ||
| { | ||
| quant_type dmq; | ||
| return dmq; | ||
|
Comment on lines
+341
to
+342
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're returning an uninitialized variable, the values will be bogus
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it enough that we check infinity bool and not use the return value? Or just for safety |
||
| } | ||
| scalar_type dg1 = D / (scalar_type(1.0) + query.getLambdaV()); | ||
| return createDualMeasureQuantity<T, reflect_refract, quant_query_type>(dg1, interaction.getNdotV(BxDFClampMode::BCM_ABS), _sample.getNdotL(BxDFClampMode::BCM_ABS), quant_query); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd only have
getLuminosityContributionHint