Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
9be65a0
changed quaternion struct name, brought in quaternion stuff from prze…
keptsecret Dec 1, 2025
3e03467
_static_create quaternion to matrix, create quaternion from axis-angle
keptsecret Dec 2, 2025
34d1385
added more quaternion funcs: transformVec, inverse, normalize + stati…
keptsecret Dec 2, 2025
61540d6
Modified `LoadableImage` and `ResolveAccessorBase` concepts
Przemog1 Dec 11, 2025
6953879
Small RWMC fixes
Przemog1 Dec 22, 2025
3d0c454
changes to linear, bilinear, box muller for pdf and backward pdf
keptsecret Jan 20, 2026
bea01f9
get polarized fresnel values by component
keptsecret Jan 20, 2026
5a36766
precompute some phase shift constants
keptsecret Jan 21, 2026
d079f5b
removed morton struct superseded by new one
keptsecret Jan 21, 2026
3f8fd48
changes to solid angle method name, simplified a lot of code in spher…
keptsecret Jan 21, 2026
c06f199
simplify call to iridescent helper through base struct
keptsecret Jan 21, 2026
407d0fd
removed redundant/unused variables from spherical triangle sample
keptsecret Jan 22, 2026
795b9fa
spherical rectangle stores origin, extent, basis and takes observer i…
keptsecret Jan 22, 2026
f9b949e
added compressed spherical rectangle, comments for info of implementa…
keptsecret Jan 22, 2026
140c5c6
removed unused code
keptsecret Jan 22, 2026
2ce08d9
path tracer (unidirectional) and concepts moved from example
keptsecret Jan 23, 2026
1a7b185
use correct quantized sequence decode
keptsecret Jan 23, 2026
3350351
moved raygen out as basic ray gen with gaussian filter
keptsecret Jan 23, 2026
29910cf
merge master, fix conflicts
keptsecret Feb 2, 2026
a4a5a12
merge master, fix conflicts
keptsecret Feb 6, 2026
ea38df1
Merge branch 'master' into path_tracer_leftover_cleanup
keptsecret Feb 12, 2026
c630f62
Merge branch 'master' into path_tracer_leftover_cleanup
devshgraphicsprogramming Feb 12, 2026
5ed90fa
moved nan check from ndotl to ldoth
keptsecret Feb 13, 2026
b8f0c9f
minor fixes because this is ref in hlsl and pointer in c++
keptsecret Feb 13, 2026
78dcf93
revert linear back to old version because rcpDiff can be negative
keptsecret Feb 13, 2026
cf936ed
fix conditionalAbsOrMax for vectors
keptsecret Feb 13, 2026
5e52a6f
refactor changes to various sampling functions so it runs
keptsecret Feb 13, 2026
86e3146
some fixes to pt concept type names
keptsecret Feb 13, 2026
addde12
RWMC fixes
Przemog1 Feb 16, 2026
94a5bfb
type alias for id of material and light, also reduced arguments to ma…
keptsecret Feb 16, 2026
1227991
change nee to return a struct because of multiple return values
keptsecret Feb 16, 2026
676831e
scene does the mapping from object id to light/mat id
keptsecret Feb 16, 2026
3a90b0c
Finalize RWMC review fixes
AnastaZIuk Feb 16, 2026
187ced6
Restrict Resolver template parameters to review scope
AnastaZIuk Feb 16, 2026
a604064
renamed constants in camelcase
keptsecret Feb 17, 2026
87c7fb1
intersector returns a struct with intersection point, interaction, hi…
keptsecret Feb 17, 2026
9d98071
randGen should return a unorm float, everything that rand3d() does wi…
keptsecret Feb 17, 2026
acd91aa
refactor ray struct to be polymorphic on polygon method, new methods
keptsecret Feb 17, 2026
70b90d6
Finalize RWMC review fixes
AnastaZIuk Feb 17, 2026
ea2e525
Fix accessor concepts for out-param get
AnastaZIuk Feb 17, 2026
9399ad3
Address latest RWMC accessor and splatting review comments
AnastaZIuk Feb 17, 2026
1125f48
Improve packed splatting parameter naming
AnastaZIuk Feb 17, 2026
6897443
Merge branch 'master' into path_tracer_leftover_cleanup
keptsecret Feb 18, 2026
31011e8
fix depth increment, nee should return env radiance
keptsecret Feb 18, 2026
0ee6534
minor bug fix to depth, throughputCIE
keptsecret Feb 18, 2026
b7ec514
material system handles emissive material of lights, nee does only de…
keptsecret Feb 18, 2026
f71610b
Created concepts for samplers, added quotient_and_pdf variants to sat…
karimsayedre Feb 18, 2026
e20adf0
Merge branch 'master' into path_tracer_leftover_cleanup
keptsecret Feb 19, 2026
e02ae41
made some vars members to assign, gaussian takes vec2
keptsecret Feb 19, 2026
b27ec2d
nee chooses the light so takes material system with emissive instead
keptsecret Feb 19, 2026
e648649
merge rwmc_fix2, fix conflicts
keptsecret Feb 19, 2026
233f9b8
fixes to mis usage, moved albedo into material
keptsecret Feb 19, 2026
2e19c85
nee shouldn't copy scene again
keptsecret Feb 19, 2026
f9cd190
intersector does traceShadowRay as well
keptsecret Feb 19, 2026
2b52594
merge master, fix conflicts
keptsecret Feb 20, 2026
740ff00
use ray methods instead of calling members
keptsecret Feb 20, 2026
d96e337
minor fixes to check ldoth only when transmit
keptsecret Feb 20, 2026
8a614c3
more getters and setters for ray, result structs
keptsecret Feb 20, 2026
76ed253
made tolerance method a type alias in nee with new static method
keptsecret Feb 20, 2026
f165d87
merge master, fix conflicts
keptsecret Feb 23, 2026
da544f8
add more concepts for additional structs in pt
keptsecret Feb 23, 2026
15003cb
added concept for ray type
keptsecret Feb 23, 2026
0a85285
added a create param struct for resolve params
keptsecret Feb 23, 2026
60728b7
renamed intersector traceRay to traceClosestHit
keptsecret Feb 23, 2026
8a29fa2
concept for material light id
keptsecret Feb 24, 2026
9a227eb
removed redundant param for randgen operator
keptsecret Feb 24, 2026
a506180
added a create method to pack all the required splatting params
keptsecret Feb 24, 2026
4ceb3f2
scene returns an interaction, instead of just normal
keptsecret Feb 25, 2026
917acc5
minor fixes to spherical rectangle stuff
keptsecret Feb 25, 2026
0e0b0ad
revert bad formatting for hlsl sampling headers
karimsayedre Feb 25, 2026
3574d83
Separate warp sample types from quotient_and_pdf, add sample density …
karimsayedre Feb 25, 2026
4ea58c8
remove unused variable in packed splatting params
keptsecret Feb 25, 2026
885e58f
minor changes to concept for intersector, nee; document concept symbols
keptsecret Feb 25, 2026
9aeb80c
changes to ray methods to separate interaction from init, nee takes a…
keptsecret Feb 25, 2026
575f15b
fix normalize throughputCIE, minor changes to method names
keptsecret Feb 25, 2026
b5a4feb
use nbl this macro for fresnel iridescent that uses this
keptsecret Feb 26, 2026
120e179
added some asserts, material system should take aniso types and decid…
keptsecret Feb 26, 2026
5e243d9
correct pdf method for mat system, added shouldDoMIS for ray payload
keptsecret Feb 26, 2026
40d585c
added some comments regarding future use of MIS, scene takes and inte…
keptsecret Feb 26, 2026
8d8b4af
minor name changes of methods
keptsecret Feb 27, 2026
82ee23c
offset ray origin by geometric normal, not ray dir
keptsecret Feb 27, 2026
f6987fb
path tracer doesn't store a ray gen, instead takes a generated ray fo…
keptsecret Feb 27, 2026
5922b38
env light id always 0, handle miss program like sampling env light
keptsecret Feb 27, 2026
4319536
Merge branch 'master' into path_tracer_leftover_cleanup
keptsecret Mar 2, 2026
168ca4d
merge master, fix conflicts
keptsecret Mar 2, 2026
f1493ed
changes to linear, bilinear, box muller for pdf and backward pdf
keptsecret Jan 20, 2026
5933fe0
changes to solid angle method name, simplified a lot of code in spher…
keptsecret Jan 21, 2026
3ac7b83
removed redundant/unused variables from spherical triangle sample
keptsecret Jan 22, 2026
4ed1cbc
spherical rectangle stores origin, extent, basis and takes observer i…
keptsecret Jan 22, 2026
65ef4b3
added compressed spherical rectangle, comments for info of implementa…
keptsecret Jan 22, 2026
7fc8281
minor fixes to spherical rectangle stuff
keptsecret Feb 25, 2026
855dac4
spherical rectangle constructor for same rectangle and observer
keptsecret Mar 2, 2026
468031f
spherical rectangle create only from compressed, minor fix for spheri…
keptsecret Mar 2, 2026
0f143a0
reduced duplicate methods to only ones matching (close to) concept in…
keptsecret Mar 2, 2026
fb0e8a5
spherical rect generate don't divide by extents, let user do that
keptsecret Mar 2, 2026
ab5ee78
store only needed members from tri
keptsecret Mar 3, 2026
17c85ba
forward/backward pdfs for spherical triangle/rectangle, projected sph…
keptsecret Mar 3, 2026
d95cfa7
copied over fixed linear sampling because merge fucked up, added forw…
keptsecret Mar 3, 2026
0bb7b39
add forward pdf, generate inverse to bilinear
keptsecret Mar 4, 2026
89f6d5f
uniform hemi/sphere samplign make static methods private, added metho…
keptsecret Mar 4, 2026
e07ebc1
cosine hemi/sphere sampling make static methods private, added method…
keptsecret Mar 4, 2026
c4e63b3
box muller transform add forward pdf, generate wasn't merged from pt …
keptsecret Mar 4, 2026
9c18828
don't handle microfacet cache in path tracer, let mat sys do it; also…
keptsecret Mar 5, 2026
960704d
luminosity coeff should be spectral_type
keptsecret Mar 5, 2026
c064b29
`approx_compare` uses abs then relative comparison, better sampler co…
karimsayedre Mar 5, 2026
d254d7a
Merge branch 'master' into sampler-concepts
karimsayedre Mar 5, 2026
4d186db
nee method to get env light id, added minor checks for pdf=0 and stuff
keptsecret Mar 6, 2026
ad5b706
latest example
keptsecret Mar 6, 2026
c65bb4c
separate payload throughput from emissive MIS, fix inf check
keptsecret Mar 6, 2026
8a9070e
minor change to ray concept, fix include in splatting params file
keptsecret Mar 6, 2026
90dfc4e
Merge pull request #991 from Devsh-Graphics-Programming/path_tracer_l…
devshgraphicsprogramming Mar 6, 2026
5bc073f
Merge branch 'master' into sampler-concepts
karimsayedre Mar 6, 2026
d2114f8
fixes after merge
karimsayedre Mar 7, 2026
4f390b4
Merge remote-tracking branch 'origin/sampling_refactor_for_pt' into s…
karimsayedre Mar 7, 2026
743575f
update `examples_tests`
karimsayedre Mar 7, 2026
4d266ec
All samplers now conform to concepts
karimsayedre Mar 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples_tests
Submodule examples_tests updated 68 files
+40 −0 31_HLSLPathTracer/CMakeLists.txt
+837 −0 31_HLSLPathTracer/app_resources/glsl/common.glsl
+182 −0 31_HLSLPathTracer/app_resources/glsl/litByRectangle.comp
+60 −0 31_HLSLPathTracer/app_resources/glsl/litBySphere.comp
+105 −0 31_HLSLPathTracer/app_resources/glsl/litByTriangle.comp
+742 −0 31_HLSLPathTracer/app_resources/hlsl/example_common.hlsl
+131 −0 31_HLSLPathTracer/app_resources/hlsl/intersector.hlsl
+286 −0 31_HLSLPathTracer/app_resources/hlsl/material_system.hlsl
+438 −0 31_HLSLPathTracer/app_resources/hlsl/next_event_estimator.hlsl
+19 −0 31_HLSLPathTracer/app_resources/hlsl/present.frag.hlsl
+40 −0 31_HLSLPathTracer/app_resources/hlsl/rand_gen.hlsl
+222 −0 31_HLSLPathTracer/app_resources/hlsl/render.comp.hlsl
+27 −0 31_HLSLPathTracer/app_resources/hlsl/render_common.hlsl
+13 −0 31_HLSLPathTracer/app_resources/hlsl/render_rwmc_common.hlsl
+65 −0 31_HLSLPathTracer/app_resources/hlsl/resolve.comp.hlsl
+15 −0 31_HLSLPathTracer/app_resources/hlsl/resolve_common.hlsl
+76 −0 31_HLSLPathTracer/app_resources/hlsl/scene_base.hlsl
+97 −0 31_HLSLPathTracer/app_resources/hlsl/scene_rectangle_light.hlsl
+100 −0 31_HLSLPathTracer/app_resources/hlsl/scene_sphere_light.hlsl
+97 −0 31_HLSLPathTracer/app_resources/hlsl/scene_triangle_light.hlsl
+28 −0 31_HLSLPathTracer/config.json.template
+17 −0 31_HLSLPathTracer/include/nbl/this_example/common.hpp
+167 −0 31_HLSLPathTracer/include/nbl/this_example/transform.hpp
+1,580 −0 31_HLSLPathTracer/main.cpp
+50 −0 31_HLSLPathTracer/pipeline.groovy
+64 −0 37_HLSLSamplingTests/CBilinearTester.h
+67 −0 37_HLSLSamplingTests/CBoxMullerTransformTester.h
+61 −0 37_HLSLSamplingTests/CConcentricMappingTester.h
+62 −0 37_HLSLSamplingTests/CLinearTester.h
+201 −0 37_HLSLSamplingTests/CMakeLists.txt
+61 −0 37_HLSLSamplingTests/CProjectedHemisphereTester.h
+63 −0 37_HLSLSamplingTests/CProjectedSphereTester.h
+102 −0 37_HLSLSamplingTests/CProjectedSphericalTriangleTester.h
+251 −0 37_HLSLSamplingTests/CSamplerBenchmark.h
+67 −0 37_HLSLSamplingTests/CSphericalRectangleTester.h
+124 −0 37_HLSLSamplingTests/CSphericalTriangleTester.h
+62 −0 37_HLSLSamplingTests/CUniformHemisphereTester.h
+62 −0 37_HLSLSamplingTests/CUniformSphereTester.h
+36 −0 37_HLSLSamplingTests/app_resources/bilinear_test.comp.hlsl
+38 −0 37_HLSLSamplingTests/app_resources/box_muller_transform_test.comp.hlsl
+50 −0 37_HLSLSamplingTests/app_resources/common/bilinear.hlsl
+43 −0 37_HLSLSamplingTests/app_resources/common/box_muller_transform.hlsl
+46 −0 37_HLSLSamplingTests/app_resources/common/concentric_mapping.hlsl
+48 −0 37_HLSLSamplingTests/app_resources/common/linear.hlsl
+47 −0 37_HLSLSamplingTests/app_resources/common/projected_hemisphere.hlsl
+52 −0 37_HLSLSamplingTests/app_resources/common/projected_sphere.hlsl
+68 −0 37_HLSLSamplingTests/app_resources/common/projected_spherical_triangle.hlsl
+49 −0 37_HLSLSamplingTests/app_resources/common/spherical_rectangle.hlsl
+97 −0 37_HLSLSamplingTests/app_resources/common/spherical_triangle.hlsl
+48 −0 37_HLSLSamplingTests/app_resources/common/uniform_hemisphere.hlsl
+49 −0 37_HLSLSamplingTests/app_resources/common/uniform_sphere.hlsl
+31 −0 37_HLSLSamplingTests/app_resources/concentric_mapping_test.comp.hlsl
+36 −0 37_HLSLSamplingTests/app_resources/linear_test.comp.hlsl
+34 −0 37_HLSLSamplingTests/app_resources/projected_hemisphere_test.comp.hlsl
+34 −0 37_HLSLSamplingTests/app_resources/projected_sphere_test.comp.hlsl
+47 −0 37_HLSLSamplingTests/app_resources/projected_spherical_triangle_test.comp.hlsl
+42 −0 37_HLSLSamplingTests/app_resources/spherical_rectangle_test.comp.hlsl
+46 −0 37_HLSLSamplingTests/app_resources/spherical_triangle.comp.hlsl
+159 −0 37_HLSLSamplingTests/app_resources/test_compile.comp.hlsl
+34 −0 37_HLSLSamplingTests/app_resources/uniform_hemisphere_test.comp.hlsl
+34 −0 37_HLSLSamplingTests/app_resources/uniform_sphere_test.comp.hlsl
+385 −0 37_HLSLSamplingTests/main.cpp
+1 −1 40_PathTracer/include/renderer/shaders/session.hlsl
+17 −1 40_PathTracer/src/renderer/CRenderer.cpp
+3 −3 59_QuaternionTests/CQuaternionTester.h
+44 −9 62_CAD/main.cpp
+2 −0 CMakeLists.txt
+383 −384 common/include/nbl/examples/Tester/ITester.h
14 changes: 12 additions & 2 deletions include/nbl/builtin/hlsl/bxdf/base/cook_torrance_base.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ struct SCookTorrance
// fail if samples have invalid paths
const scalar_type NdotL = hlsl::mix(scalar_type(2.0) * VdotH * localH.z - NdotV,
localH.z * (VdotH * rcpEta.value[0] + LdotH) - NdotV * rcpEta.value[0], transmitted);
assert(!hlsl::isnan(NdotL));
// VNDF sampling guarantees that `VdotH` has same sign as `NdotV`
// and `transmitted` controls the sign of `LdotH` relative to `VdotH` by construction (reflect -> same sign, or refract -> opposite sign)
if (hlsl::isnan(NdotL) || ComputeMicrofacetNormal<scalar_type>::isTransmissionPath(NdotV, NdotL) != transmitted)
if (ComputeMicrofacetNormal<scalar_type>::isTransmissionPath(NdotV, NdotL) != transmitted)
{
valid = false;
return sample_type::createInvalid(); // should check if sample direction is invalid
Expand Down Expand Up @@ -307,7 +308,16 @@ struct SCookTorrance
partitionRandVariable.leftProb = reflectance;
bool transmitted = partitionRandVariable(z, rcpChoiceProb);

const scalar_type LdotH = hlsl::mix(VdotH, ieee754::copySign(hlsl::sqrt(rcpEta.value2[0]*VdotH*VdotH + scalar_type(1.0) - rcpEta.value2[0]), -VdotH), transmitted);
scalar_type LdotH;
if (transmitted)
{
scalar_type det = rcpEta.value2[0]*VdotH*VdotH + scalar_type(1.0) - rcpEta.value2[0];
if (det < scalar_type(0.0))
return sample_type::createInvalid();
LdotH = ieee754::copySign(hlsl::sqrt(det), -VdotH);
}
else
LdotH = VdotH;
bool valid;
sample_type s = __generate_common(interaction, localH, NdotV, VdotH, LdotH, transmitted, rcpEta, valid);
if (valid)
Expand Down
12 changes: 7 additions & 5 deletions include/nbl/builtin/hlsl/bxdf/base/lambertian.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ struct SLambertianBase
template<typename C=bool_constant<!IsBSDF> >
enable_if_t<C::value && !IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u) NBL_CONST_MEMBER_FUNC
{
typename sampling::ProjectedHemisphere<scalar_type>::cache_type cache;
ray_dir_info_type L;
L.setDirection(sampling::ProjectedHemisphere<scalar_type>::generate(u));
L.setDirection(sampling::ProjectedHemisphere<scalar_type>::generate(u, cache));
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}
template<typename C=bool_constant<IsBSDF> >
enable_if_t<C::value && IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u) NBL_CONST_MEMBER_FUNC
{
typename sampling::ProjectedSphere<scalar_type>::cache_type cache;
vector3_type _u = u;
ray_dir_info_type L;
L.setDirection(sampling::ProjectedSphere<scalar_type>::generate(_u));
L.setDirection(sampling::ProjectedSphere<scalar_type>::generate(_u, cache));
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}
template<typename C=bool_constant<!IsBSDF> >
Expand Down Expand Up @@ -76,10 +78,10 @@ struct SLambertianBase
{
sampling::quotient_and_pdf<monochrome_type, scalar_type> qp;
NBL_IF_CONSTEXPR (IsBSDF)
qp = sampling::ProjectedSphere<scalar_type>::template quotient_and_pdf(_sample.getNdotL(_clamp));
qp = sampling::ProjectedSphere<scalar_type>::template quotientAndPdf(_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);
qp = sampling::ProjectedHemisphere<scalar_type>::template quotientAndPdf(_sample.getNdotL(_clamp));
return quotient_pdf_type::create(qp.quotient()[0], qp.pdf());
}
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction) NBL_CONST_MEMBER_FUNC
{
Expand Down
6 changes: 4 additions & 2 deletions include/nbl/builtin/hlsl/bxdf/base/oren_nayar.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,18 @@ struct SOrenNayarBase
template<typename C=bool_constant<!IsBSDF> >
enable_if_t<C::value && !IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u) NBL_CONST_MEMBER_FUNC
{
typename sampling::ProjectedHemisphere<scalar_type>::cache_type cache;
ray_dir_info_type L;
L.setDirection(sampling::ProjectedHemisphere<scalar_type>::generate(u));
L.setDirection(sampling::ProjectedHemisphere<scalar_type>::generate(u, cache));
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}
template<typename C=bool_constant<IsBSDF> >
enable_if_t<C::value && IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u) NBL_CONST_MEMBER_FUNC
{
typename sampling::ProjectedSphere<scalar_type>::cache_type cache;
vector3_type _u = u;
ray_dir_info_type L;
L.setDirection(sampling::ProjectedSphere<scalar_type>::generate(_u));
L.setDirection(sampling::ProjectedSphere<scalar_type>::generate(_u, cache));
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
}
template<typename C=bool_constant<!IsBSDF> >
Expand Down
92 changes: 64 additions & 28 deletions include/nbl/builtin/hlsl/bxdf/fresnel.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,8 @@ struct iridescent_helper
using vector_type = T;

// returns phi, the phase shift for each plane of polarization (p,s)
static void phase_shift(const vector_type ior1, const vector_type ior2, const vector_type iork2, const vector_type cosTheta, NBL_REF_ARG(vector_type) phiS, NBL_REF_ARG(vector_type) phiP)
static void phase_shift(const vector_type ior1, const vector_type ior2, const vector_type iork2, const vector_type cosTheta, const vector_type cosTheta2, const vector_type sinTheta2, NBL_REF_ARG(vector_type) phiS, NBL_REF_ARG(vector_type) phiP)
{
const vector_type cosTheta2 = cosTheta * cosTheta;
const vector_type sinTheta2 = hlsl::promote<vector_type>(1.0) - cosTheta2;
const vector_type ior1_2 = ior1*ior1;
const vector_type ior2_2 = ior2*ior2;
const vector_type iork2_2 = iork2*iork2;
Expand All @@ -523,6 +521,7 @@ struct iridescent_helper
const vector_type a = hlsl::sqrt(a2);
const vector_type b = hlsl::sqrt(b2);

// TODO: very optimizable, especially atan2 usage
phiS = hlsl::atan2(scalar_type(2.0) * ior1 * b * cosTheta, a2 + b2 - ior1_2*cosTheta2);
const vector_type k2_plus_one = hlsl::promote<vector_type>(1.0) + iork2_2;
phiP = hlsl::atan2(scalar_type(2.0) * ior1 * ior2_2 * cosTheta * (scalar_type(2.0) * iork2 * a - (hlsl::promote<vector_type>(1.0) - iork2_2) * b),
Expand All @@ -549,37 +548,50 @@ struct iridescent_helper
{
const scalar_type cosTheta_1 = clampedCosTheta;
vector_type R12p, R23p, R12s, R23s;
vector_type cosTheta_2;
vector_type cosTheta_2, cosTheta2_2;
vector<bool,vector_traits<vector_type>::Dimension> notTIR;
{
const vector_type scale = scalar_type(1.0)/eta12;
const vector_type cosTheta2_2 = hlsl::promote<vector_type>(1.0) - hlsl::promote<vector_type>(scalar_type(1.0)-cosTheta_1*cosTheta_1) * scale * scale;
cosTheta2_2 = hlsl::promote<vector_type>(1.0) - hlsl::promote<vector_type>(scalar_type(1.0)-cosTheta_1*cosTheta_1) * scale * scale;
notTIR = cosTheta2_2 > hlsl::promote<vector_type>(0.0);
cosTheta_2 = hlsl::sqrt(hlsl::max(cosTheta2_2, hlsl::promote<vector_type>(0.0)));
cosTheta_2 = hlsl::mix(hlsl::promote<vector_type>(0.0), hlsl::sqrt(cosTheta2_2), notTIR);
}

if (hlsl::any(notTIR))
NBL_UNROLL for (uint32_t i = 0; i < vector_traits<vector_type>::Dimension; i++)
{
Dielectric<vector_type>::__polarized(eta12 * eta12, hlsl::promote<vector_type>(cosTheta_1), R12p, R12s);

// Reflected part by the base
// if kappa==0, base material is dielectric
NBL_IF_CONSTEXPR(SupportsTransmission)
Dielectric<vector_type>::__polarized(eta23 * eta23, cosTheta_2, R23p, R23s);
// Check for total internal reflection
if (notTIR[i])
{
using monochrome_type = vector<scalar_type, 1>;
monochrome_type p12, s12, p23, s23;
Dielectric<monochrome_type>::__polarized(hlsl::promote<monochrome_type>(eta12[i] * eta12[i]), hlsl::promote<monochrome_type>(cosTheta_1), p12, s12);

const monochrome_type eta23_2 = hlsl::promote<monochrome_type>(eta23[i] * eta23[i]);

// Reflected part by the base
// if kappa==0, base material is dielectric
NBL_IF_CONSTEXPR(SupportsTransmission)
Dielectric<monochrome_type>::__polarized(eta23_2, hlsl::promote<monochrome_type>(cosTheta_2[i]), p23, s23);
else
{
const monochrome_type etaLen2 = eta23_2 + hlsl::promote<monochrome_type>(etak23[i] * etak23[i]);
Conductor<monochrome_type>::__polarized(hlsl::promote<monochrome_type>(eta23[i]), etaLen2, hlsl::promote<monochrome_type>(cosTheta_2[i]), p23, s23);
}

R12p[i] = p12[0];
R12s[i] = s12[0];
R23p[i] = p23[0];
R23s[i] = s23[0];
}
else
{
vector_type etaLen2 = eta23 * eta23 + etak23 * etak23;
Conductor<vector_type>::__polarized(eta23, etaLen2, cosTheta_2, R23p, R23s);
R12s[i] = scalar_type(0.0);
R12p[i] = scalar_type(0.0);
R23s[i] = scalar_type(0.0);
R23p[i] = scalar_type(0.0);
}
}

// Check for total internal reflection
const vector_type notTIRFactor = vector_type(notTIR); // 0 when TIR, 1 otherwise
R12s = R12s * notTIRFactor;
R12p = R12p * notTIRFactor;
R23s = R23s * notTIRFactor;
R23p = R23p * notTIRFactor;

// Compute the transmission coefficients
vector_type T121p = hlsl::promote<vector_type>(1.0) - R12p;
vector_type T121s = hlsl::promote<vector_type>(1.0) - R12s;
Expand All @@ -591,8 +603,18 @@ struct iridescent_helper
vector_type I = hlsl::promote<vector_type>(0.0);

// Evaluate the phase shift
phase_shift(ior1, ior2, hlsl::promote<vector_type>(0.0), hlsl::promote<vector_type>(cosTheta_1), phi21s, phi21p);
phase_shift(ior2, ior3, iork3, cosTheta_2, phi23s, phi23p);
{
const vector_type ct = hlsl::promote<vector_type>(cosTheta_1);
const vector_type ct2 = ct * ct;
const vector_type st2 = hlsl::promote<vector_type>(1.0) - ct2;
phase_shift(ior1, ior2, hlsl::promote<vector_type>(0.0), ct, ct2, st2, phi21s, phi21p);
}
{
const vector_type ct = hlsl::promote<vector_type>(cosTheta_2);
const vector_type ct2 = cosTheta2_2;
const vector_type st2 = hlsl::promote<vector_type>(1.0) - ct2;
phase_shift(ior2, ior3, iork3, ct, ct2, st2, phi23s, phi23p);
}
phi21p = hlsl::promote<vector_type>(numbers::pi<scalar_type>) - phi21p;
phi21s = hlsl::promote<vector_type>(numbers::pi<scalar_type>) - phi21s;

Expand All @@ -613,6 +635,7 @@ struct iridescent_helper
NBL_UNROLL for (int m=1; m<=2; ++m)
{
Cm *= r123p;
// TODO: common subexpression, maybe we can hoist it out somehow?
Sm = hlsl::promote<vector_type>(2.0) * evalSensitivity(hlsl::promote<vector_type>(scalar_type(m))*D, hlsl::promote<vector_type>(scalar_type(m))*(phi23p+phi21p));
I += Cm*Sm;
}
Expand Down Expand Up @@ -641,6 +664,13 @@ struct iridescent_base
using scalar_type = typename vector_traits<T>::scalar_type;
using vector_type = T;

template<bool SupportsTransmission, typename Colorspace>
T __call(const vector_type iork3, const vector_type etak23, const scalar_type clampedCosTheta) NBL_CONST_MEMBER_FUNC
{
return impl::iridescent_helper<T,false>::template __call<Colorspace>(D, ior1, ior2, ior3, iork3,
eta12, eta23, etak23, clampedCosTheta);
}

vector_type D;
vector_type ior1;
vector_type ior2;
Expand All @@ -650,6 +680,14 @@ struct iridescent_base
vector_type eta23; // thin-film -> base material IOR
vector_type eta13;
};


// workaround due to DXC bug: github.com/microsoft/DirectXShaderCompiler/issues/5966
template<typename T, bool SupportsTransmission, typename Colorspace>
T __iridescent_base__call_const(NBL_CONST_REF_ARG(iridescent_base<T>) _this, const T iork3, const T etak23, const typename vector_traits<T>::scalar_type clampedCosTheta)
{
return _this.template __call<SupportsTransmission, Colorspace>(iork3, etak23, clampedCosTheta);
}
}

template<typename T, typename Colorspace>
Expand Down Expand Up @@ -691,8 +729,7 @@ struct Iridescent<T, false, Colorspace NBL_PARTIAL_REQ_BOT(concepts::FloatingPoi

T operator()(const scalar_type clampedCosTheta) NBL_CONST_MEMBER_FUNC
{
return impl::iridescent_helper<T,false>::template __call<Colorspace>(base_type::D, base_type::ior1, base_type::ior2, base_type::ior3, base_type::iork3,
base_type::eta12, base_type::eta23, getEtak23(), clampedCosTheta);
return impl::__iridescent_base__call_const<T, false, Colorspace>(NBL_DEREF_THIS, base_type::iork3, getEtak23(), clampedCosTheta);
}

vector_type getEtak23() NBL_CONST_MEMBER_FUNC
Expand Down Expand Up @@ -739,8 +776,7 @@ struct Iridescent<T, true, Colorspace NBL_PARTIAL_REQ_BOT(concepts::FloatingPoin

T operator()(const scalar_type clampedCosTheta) NBL_CONST_MEMBER_FUNC
{
return impl::iridescent_helper<T,true>::template __call<Colorspace>(base_type::D, base_type::ior1, base_type::ior2, base_type::ior3, getEtak23(),
base_type::eta12, base_type::eta23, getEtak23(), clampedCosTheta);
return impl::__iridescent_base__call_const<T, true, Colorspace>(NBL_DEREF_THIS, getEtak23(), getEtak23(), clampedCosTheta);
}

scalar_type getRefractionOrientedEta() NBL_CONST_MEMBER_FUNC { return base_type::eta13[0]; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@ namespace accessors
{
// declare concept
#define NBL_CONCEPT_NAME AnisotropicallySampled
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(Dims)
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(int32_t)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(Dims)(Components)
// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (a,U)
#define NBL_CONCEPT_PARAM_1 (uv,vector<float32_t,Dims>)
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
#define NBL_CONCEPT_PARAM_3 (dU,vector<float32_t,Dims>)
#define NBL_CONCEPT_PARAM_4 (dV,vector<float32_t,Dims>)
#define NBL_CONCEPT_PARAM_5 (outVal,vector<float32_t,Components>)
// start concept
NBL_CONCEPT_BEGIN(5)
NBL_CONCEPT_BEGIN(6)
// need to be defined AFTER the cocnept begins
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define dU NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
#define dV NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
#define outVal NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_5
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<Dims>(uv,layer,dU,dV)) , ::nbl::hlsl::is_same_v, float32_t4>))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<Dims>(outVal,uv,layer,dU,dV)) , ::nbl::hlsl::is_same_v, void))
);
#undef outVal
#undef dV
#undef dU
#undef layer
Expand All @@ -47,4 +50,4 @@ NBL_CONCEPT_END(
}
}
}
#endif
#endif
30 changes: 18 additions & 12 deletions include/nbl/builtin/hlsl/concepts/accessors/loadable_image.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,58 @@ namespace accessors
{

// concept `LoadableImage` translates to smth like this:
//template<typename U, typename T, int32_t Dims>
//concept LoadableImage = requires(U a, vector<uint16_t, Dims> uv, uint16_t layer) {
// ::nbl::hlsl::is_same_v<decltype(declval<U>().template get<T,Dims>(uv,layer)), vector<T,4>>;
//template<typename U, typename T, int32_t Dims, int32_t Components>
//concept LoadableImage = requires(U a, vector<uint16_t, Dims> uv, uint16_t layer, vector<T, Components> outVal) {
// ::nbl::hlsl::is_same_v<decltype(declval<U>().template get<T,Dims>(outVal,uv,layer)), void>;
//};

// declare concept
#define NBL_CONCEPT_NAME LoadableImage
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)(Components)
// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (a,U)
#define NBL_CONCEPT_PARAM_1 (uv,vector<uint16_t,Dims>)
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
#define NBL_CONCEPT_PARAM_3 (outVal,vector<T,Components>)
// start concept
NBL_CONCEPT_BEGIN(3)
NBL_CONCEPT_BEGIN(4)
// need to be defined AFTER the concept begins
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define outVal NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(uv,layer)), ::nbl::hlsl::is_same_v, vector<T,4>))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(outVal,uv,layer)), ::nbl::hlsl::is_same_v, void))
);
#undef outVal
#undef layer
#undef uv
#undef a
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

// declare concept
#define NBL_CONCEPT_NAME MipmappedLoadableImage
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)(typename)(int32_t)(int32_t)
#define NBL_CONCEPT_TPLT_PRM_NAMES (U)(T)(Dims)(Components)
// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (a,U)
#define NBL_CONCEPT_PARAM_1 (uv,vector<uint16_t,Dims>)
#define NBL_CONCEPT_PARAM_2 (layer,uint16_t)
#define NBL_CONCEPT_PARAM_3 (level,uint16_t)
#define NBL_CONCEPT_PARAM_4 (outVal,vector<T,Components>)
// start concept
NBL_CONCEPT_BEGIN(4)
NBL_CONCEPT_BEGIN(5)
// need to be defined AFTER the cocnept begins
#define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define uv NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define layer NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define level NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
#define outVal NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(uv,layer,level)) , ::nbl::hlsl::is_same_v, vector<T,4>))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((a.template get<T,Dims>(outVal,uv,layer,level)) , ::nbl::hlsl::is_same_v, void))
);
#undef outVal
#undef level
#undef layer
#undef uv
Expand All @@ -73,4 +79,4 @@ NBL_CONCEPT_END(
}
}
}
#endif
#endif
Loading
Loading