-
Notifications
You must be signed in to change notification settings - Fork 65
bxdf fixes: non cook-torrance stuff #919
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4fd9d59
minor fixes to interaction, microfacet cache in common.hlsl
keptsecret 3c4a1d5
added delta distribution bxdfs
keptsecret 1eac170
added oren nayar bsdf
keptsecret be844a5
fixes to smooth dielectric bsdf
keptsecret 5f9f746
redone bxdf concepts
keptsecret 349d6b2
don't take sample u by reference
keptsecret 5b6bb6e
added a reflectTransmit to ray dir type
keptsecret 4f31580
fix thin dielectric scatter func
keptsecret e2357fc
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret 3d418bb
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret 34ae295
change microfacet bxdf concept
keptsecret 906d3ec
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret 1099d60
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret c194f4e
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret d80f5ca
minor oren nayar changes to store A2 and AB
keptsecret 5dd4956
Merge branch 'master' into bxdf_fixes_non_ct
keptsecret d4c61bd
minor fixes to concept, iso cachce
keptsecret 68c8123
removed create from lambertian, delta dis bc they do nothing
keptsecret a0dbcc2
added macro for bxdf type aliases
keptsecret b0c41f7
oren nayar create changes
keptsecret 7e086f4
fix more oren nayar bugs
keptsecret 6488ba4
fix delta distribution generate
keptsecret 75ef607
reverted __rec_pi_factored_out_wo_clamps removal in oren nayar
keptsecret 906d437
moved lambertian and oren nayar logic into a base class
keptsecret File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O. | ||
// This file is part of the "Nabla Engine". | ||
// For conditions of distribution and use, see copyright notice in nabla.h | ||
#ifndef _NBL_BUILTIN_HLSL_BXDF_BASE_LAMBERTIAN_INCLUDED_ | ||
#define _NBL_BUILTIN_HLSL_BXDF_BASE_LAMBERTIAN_INCLUDED_ | ||
|
||
#include "nbl/builtin/hlsl/bxdf/common.hlsl" | ||
#include "nbl/builtin/hlsl/bxdf/config.hlsl" | ||
#include "nbl/builtin/hlsl/sampling/cos_weighted_spheres.hlsl" | ||
|
||
namespace nbl | ||
{ | ||
namespace hlsl | ||
{ | ||
namespace bxdf | ||
{ | ||
namespace base | ||
{ | ||
|
||
template<class Config, bool IsBSDF NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>) | ||
struct SLambertianBase | ||
{ | ||
using this_t = SLambertianBase<Config, IsBSDF>; | ||
BXDF_CONFIG_TYPE_ALIASES(Config); | ||
|
||
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = conditional_value<IsBSDF, BxDFClampMode, BxDFClampMode::BCM_ABS, BxDFClampMode::BCM_MAX>::value; | ||
|
||
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction) | ||
{ | ||
return hlsl::promote<spectral_type>(_sample.getNdotL(_clamp) * numbers::inv_pi<scalar_type> * hlsl::mix(1.0, 0.5, IsBSDF)); | ||
} | ||
|
||
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u) | ||
{ | ||
// static_assert(!IsBSDF); | ||
ray_dir_info_type L; | ||
L.direction = sampling::ProjectedHemisphere<scalar_type>::generate(u); | ||
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace()); | ||
} | ||
|
||
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u) | ||
{ | ||
// static_assert(IsBSDF); | ||
ray_dir_info_type L; | ||
L.direction = sampling::ProjectedSphere<scalar_type>::generate(u); | ||
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace()); | ||
} | ||
|
||
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample) | ||
{ | ||
if (IsBSDF) | ||
return sampling::ProjectedSphere<scalar_type>::pdf(_sample.getNdotL(_clamp)); | ||
else | ||
return sampling::ProjectedHemisphere<scalar_type>::pdf(_sample.getNdotL(_clamp)); | ||
} | ||
|
||
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction) | ||
{ | ||
sampling::quotient_and_pdf<monochrome_type, scalar_type> qp; | ||
if (IsBSDF) | ||
qp = sampling::ProjectedSphere<scalar_type>::template quotient_and_pdf(_sample.getNdotL(_clamp)); | ||
else | ||
qp = sampling::ProjectedHemisphere<scalar_type>::template quotient_and_pdf(_sample.getNdotL(_clamp)); | ||
return quotient_pdf_type::create(qp.quotient[0], qp.pdf); | ||
} | ||
}; | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O. | ||
// This file is part of the "Nabla Engine". | ||
// For conditions of distribution and use, see copyright notice in nabla.h | ||
#ifndef _NBL_BUILTIN_HLSL_BXDF_BASE_OREN_NAYAR_INCLUDED_ | ||
#define _NBL_BUILTIN_HLSL_BXDF_BASE_OREN_NAYAR_INCLUDED_ | ||
|
||
#include "nbl/builtin/hlsl/bxdf/common.hlsl" | ||
#include "nbl/builtin/hlsl/bxdf/config.hlsl" | ||
#include "nbl/builtin/hlsl/sampling/cos_weighted_spheres.hlsl" | ||
|
||
namespace nbl | ||
{ | ||
namespace hlsl | ||
{ | ||
namespace bxdf | ||
{ | ||
namespace base | ||
{ | ||
|
||
template<class Config, bool IsBSDF NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>) | ||
struct SOrenNayarBase | ||
{ | ||
using this_t = SOrenNayarBase<Config, IsBSDF>; | ||
BXDF_CONFIG_TYPE_ALIASES(Config); | ||
|
||
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = conditional_value<IsBSDF, BxDFClampMode, BxDFClampMode::BCM_ABS, BxDFClampMode::BCM_MAX>::value; | ||
|
||
struct SCreationParams | ||
{ | ||
scalar_type A; | ||
}; | ||
using creation_type = SCreationParams; | ||
|
||
struct SQuery | ||
{ | ||
scalar_type getVdotL() NBL_CONST_MEMBER_FUNC { return VdotL; } | ||
scalar_type VdotL; | ||
}; | ||
|
||
static this_t create(NBL_CONST_REF_ARG(creation_type) params) | ||
{ | ||
this_t retval; | ||
retval.A2 = params.A * 0.5; | ||
retval.AB = vector2_type(1.0, 0.0) + vector2_type(-0.5, 0.45) * vector2_type(retval.A2, retval.A2) / vector2_type(retval.A2 + 0.33, retval.A2 + 0.09); | ||
return retval; | ||
} | ||
|
||
scalar_type __rec_pi_factored_out_wo_clamps(scalar_type VdotL, scalar_type clampedNdotL, scalar_type clampedNdotV) | ||
{ | ||
scalar_type C = 1.0 / max<scalar_type>(clampedNdotL, clampedNdotV); | ||
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - clampedNdotL * clampedNdotV, 0.0); | ||
return (AB.x + AB.y * cos_phi_sin_theta * C); | ||
} | ||
template<typename Query> | ||
spectral_type __eval(NBL_CONST_REF_ARG(Query) query, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction) | ||
{ | ||
scalar_type NdotL = _sample.getNdotL(_clamp); | ||
return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * hlsl::mix(1.0, 0.5, IsBSDF) * __rec_pi_factored_out_wo_clamps(query.getVdotL(), NdotL, interaction.getNdotV(_clamp))); | ||
} | ||
|
||
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction) | ||
{ | ||
SQuery query; | ||
query.VdotL = hlsl::dot(interaction.getV().getDirection(), _sample.getL().getDirection()); | ||
return __eval<SQuery>(query, _sample, interaction); | ||
} | ||
|
||
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u) | ||
{ | ||
// static_assert(!IsBSDF); | ||
ray_dir_info_type L; | ||
L.direction = sampling::ProjectedHemisphere<scalar_type>::generate(u); | ||
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace()); | ||
} | ||
|
||
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u) | ||
{ | ||
// static_assert(IsBSDF); | ||
ray_dir_info_type L; | ||
L.direction = sampling::ProjectedSphere<scalar_type>::generate(u); | ||
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace()); | ||
} | ||
Comment on lines
+68
to
+82
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. same comment as for the lambertian |
||
|
||
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample) | ||
{ | ||
if (IsBSDF) | ||
return sampling::ProjectedSphere<scalar_type>::pdf(_sample.getNdotL(_clamp)); | ||
else | ||
return sampling::ProjectedHemisphere<scalar_type>::pdf(_sample.getNdotL(_clamp)); | ||
} | ||
|
||
template<typename Query> | ||
quotient_pdf_type __quotient_and_pdf(NBL_CONST_REF_ARG(Query) query, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction) | ||
{ | ||
scalar_type _pdf = pdf(_sample); | ||
scalar_type q = __rec_pi_factored_out_wo_clamps(query.getVdotL(), _sample.getNdotL(_clamp), interaction.getNdotV(_clamp)); | ||
return quotient_pdf_type::create(q, _pdf); | ||
} | ||
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction) | ||
{ | ||
SQuery query; | ||
query.VdotL = hlsl::dot(interaction.getV().getDirection(), _sample.getL().getDirection()); | ||
return __quotient_and_pdf<SQuery>(query, _sample, interaction); | ||
} | ||
|
||
scalar_type A2; | ||
vector2_type AB; | ||
}; | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is flaky, template the
generate
on the vector type andREQUIRE
thatvector_type==conditional_t<IsBSDF,vector3_type,vector2_type)