-
Notifications
You must be signed in to change notification settings - Fork 15
Hlsl path tracer #224
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?
Hlsl path tracer #224
Conversation
| #ifndef _NBL_HLSL_PATHTRACER_RWMC_GLOBAL_SETTINGS_COMMON_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACER_RWMC_GLOBAL_SETTINGS_COMMON_INCLUDED_ | ||
| #include "nbl/builtin/hlsl/cpp_compat.hlsl" | ||
|
|
||
| NBL_CONSTEXPR uint32_t CascadeCount = 6u; | ||
|
|
||
| #endif |
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.
kinda silly having one header just for this
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.
kick it into the main common file
| Shape<scalar_type, PST_SPHERE> light_spheres[1]; | ||
| Shape<scalar_type, PST_TRIANGLE> light_triangles[1]; | ||
| Shape<scalar_type, PST_RECTANGLE> light_rectangles[1]; |
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.
you shouldn't need unused members if you have getters
| if (ImGui::IsKeyPressed(ImGuiKey_S) && params.allowedOp & ImGuizmo::OPERATION::SCALE) // for triangle/rectangle | ||
| mCurrentGizmoOperation = ImGuizmo::SCALE_X | ImGuizmo::SCALE_Y; | ||
|
|
||
| #if 0 |
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.
whats this if 0 about?
| #ifndef __HLSL_VERSION | ||
| #include "matrix4SIMD.h" | ||
| #endif |
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.
remove the include, not needed
| struct RenderRWMCPushConstants | ||
| { | ||
| RenderPushConstants renderPushConstants; | ||
| nbl::hlsl::rwmc::SplattingParameters splattingParameters; |
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.
the splatting params shoul have never been compressed in Nabla, they should have been compressed here, and a getter/setter method here too
| #ifdef PERSISTENT_WORKGROUPS | ||
| #include "nbl/builtin/hlsl/math/morton.hlsl" | ||
| #endif |
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.
no needed
|
|
||
| float32_t3 color = resolve(accessor, int16_t2(coords.x, coords.y)); | ||
|
|
||
| //float32_t3 color = rwmc::reweight<rwmc::ResolveAccessorAdaptor<float> >(pc.resolveParameters, cascade, coords); |
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.
remove commented code
| #ifndef _NBL_HLSL_PATHTRACER_RESOLVE_COMMON_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACER_RESOLVE_COMMON_INCLUDED_ |
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.
wrong header guard, this is userspace code
|
|
||
| struct ResolvePushConstants | ||
| { | ||
| uint32_t sampleCount; |
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.
unused variable
| RenderRWMCPushConstants rwmcPushConstants; | ||
| RenderPushConstants pc; | ||
| ResolvePushConstants resolvePushConstants; |
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.
don't you rebuild them every frame from imgui stuff + camera etc?
Maybe lets not store them around as global state and have them transient
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTGLSLPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTGLSLPersistentWGPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPersistentWGPipelines; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPipelinesRWMC; | ||
| std::array<smart_refctd_ptr<IGPUComputePipeline>, E_LIGHT_GEOMETRY::ELG_COUNT> m_PTHLSLPersistentWGPipelinesRWMC; |
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.
you can delete GLSL code now
| void updatePathtracerPushConstants() | ||
| { | ||
| // disregard surface/swapchain transformation for now | ||
| const auto viewProjectionMatrix = m_camera.getConcatenatedMatrix(); | ||
| // TODO: rewrite the `Camera` class so it uses hlsl::float32_t4x4 instead of core::matrix4SIMD | ||
| core::matrix4SIMD invMVP; | ||
| viewProjectionMatrix.getInverseTransform(invMVP); | ||
| if (useRWMC) | ||
| { | ||
| memcpy(&rwmcPushConstants.renderPushConstants.invMVP, invMVP.pointer(), sizeof(rwmcPushConstants.renderPushConstants.invMVP)); | ||
| rwmcPushConstants.renderPushConstants.generalPurposeLightMatrix = hlsl::float32_t3x4(transpose(m_lightModelMatrix)); | ||
| rwmcPushConstants.renderPushConstants.depth = depth; | ||
| rwmcPushConstants.renderPushConstants.sampleCount = resolvePushConstants.sampleCount = spp; | ||
| rwmcPushConstants.renderPushConstants.pSampleSequence = m_sequenceBuffer->getDeviceAddress(); | ||
| //rwmcPushConstants.splattingParameters.log2Start = std::log2(rwmcStart); | ||
| //rwmcPushConstants.splattingParameters.log2Base = std::log2(rwmcBase); | ||
| float32_t2 packLogs = float32_t2(std::log2(rwmcStart), std::log2(rwmcBase)); | ||
| rwmcPushConstants.splattingParameters.packedLog2 = hlsl::packHalf2x16(packLogs); | ||
| } | ||
| else | ||
| { | ||
| memcpy(&pc.invMVP, invMVP.pointer(), sizeof(pc.invMVP)); | ||
| pc.generalPurposeLightMatrix = hlsl::float32_t3x4(transpose(m_lightModelMatrix)); | ||
| pc.sampleCount = spp; | ||
| pc.depth = depth; | ||
| pc.pSampleSequence = m_sequenceBuffer->getDeviceAddress(); | ||
| } | ||
| } |
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.
you can move into a lambda somwhere in workLoopBody
| float rwmcMinReliableLuma; | ||
| float rwmcKappa; | ||
| float rwmcStart; | ||
| float rwmcBase; |
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.
gather them up, make nicer create methods for splatting and resolve params
see #218 (comment)
| const float32_t2 unpacked = hlsl::unpackHalf2x16(pc.packedSplattingParams); | ||
| rwmc::SplattingParameters splattingParameters = rwmc::SplattingParameters::create(unpacked[0], unpacked[1]); | ||
| accumulator_type accumulator = accumulator_type::create(splattingParameters); |
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.
add a get and set method to RenderRWMCPushConstants
| float32_t3 color = resolve(accessor, int16_t2(coords.x, coords.y)); | ||
|
|
||
| //float32_t3 color = rwmc::reweight<rwmc::ResolveAccessorAdaptor<float> >(pc.resolveParameters, cascade, coords); | ||
| //float32_t3 color = rwmc::reweight<ResolveAccessorAdaptor<float> >(pc.resolveParameters, cascade, coords); |
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.
whats this commented out code, if not used then remove it
| float32_t2 packParams = float32_t2(rwmcBase, rwmcStart); | ||
| rwmcPushConstants.packedSplattingParams = hlsl::packHalf2x16(packParams); |
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.
we need a setter method for the packed params
| #ifndef _NBL_HLSL_PATHTRACING_INCLUDED_ | ||
| #define _NBL_HLSL_PATHTRACING_INCLUDED_ | ||
|
|
||
| #include <nbl/builtin/hlsl/colorspace/EOTF.hlsl> | ||
| #include <nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl> | ||
| #include <nbl/builtin/hlsl/math/functions.hlsl> | ||
| #include <nbl/builtin/hlsl/sampling/basic.hlsl> | ||
| #include <nbl/builtin/hlsl/bxdf/bxdf_traits.hlsl> | ||
| #include <nbl/builtin/hlsl/sampling/quantized_sequence.hlsl> | ||
| #include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl> | ||
| #include "concepts.hlsl" | ||
|
|
||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| namespace path_tracing | ||
| { | ||
|
|
||
| template<class RandGen, class RayGen, class Intersector, class MaterialSystem, /* class PathGuider, */ class NextEventEstimator, class Accumulator, class Scene | ||
| NBL_PRIMARY_REQUIRES(concepts::RandGenerator<RandGen> && concepts::RayGenerator<RayGen> && | ||
| concepts::Intersector<Intersector> && concepts::MaterialSystem<MaterialSystem> && | ||
| concepts::NextEventEstimator<NextEventEstimator> && concepts::Accumulator<Accumulator> && | ||
| concepts::Scene<Scene>) | ||
| struct Unidirectional | ||
| { | ||
| using this_t = Unidirectional<RandGen, RayGen, Intersector, MaterialSystem, NextEventEstimator, Accumulator, Scene>; |
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.
all this needs to go to Nabla repo
| template<typename RNG> | ||
| struct Uniform1D | ||
| { | ||
| using rng_type = RNG; | ||
| using return_type = uint32_t; | ||
|
|
||
| static Uniform1D<RNG> construct(uint32_t2 seed) | ||
| { | ||
| Uniform1D<RNG> retval; | ||
| retval.rng = rng_type::construct(seed); | ||
| return retval; | ||
| } | ||
|
|
||
| return_type operator()() | ||
| { | ||
| return rng(); | ||
| } | ||
|
|
||
| rng_type rng; | ||
| }; | ||
|
|
||
| template<typename RNG> | ||
| struct Uniform3D | ||
| { | ||
| using rng_type = RNG; | ||
| using return_type = uint32_t3; | ||
|
|
||
| static Uniform3D<RNG> construct(uint32_t2 seed) | ||
| { | ||
| Uniform3D<RNG> retval; | ||
| retval.rng = rng_type::construct(seed); | ||
| return retval; | ||
| } | ||
|
|
||
| return_type operator()() | ||
| { | ||
| return return_type(rng(), rng(), rng()); | ||
| } | ||
|
|
||
| rng_type rng; | ||
| }; |
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.
these need also static return_type __call(NBL_REF_ARG(rng_type) rng)
AND to be in Nabla repo
| static this_t create(NBL_CONST_REF_ARG(vector2_type) pixOffsetParam, NBL_CONST_REF_ARG(vector3_type) camPos, NBL_CONST_REF_ARG(vector4_type) NDC, NBL_CONST_REF_ARG(matrix4x4_type) invMVP) | ||
| { | ||
| this_t retval; | ||
| retval.pixOffsetParam = pixOffsetParam; | ||
| retval.camPos = camPos; | ||
| retval.NDC = NDC; | ||
| retval.invMVP = invMVP; | ||
| return retval; | ||
| } |
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.
again, lets not make useless psedo-constructors
| // #if POLYGON_METHOD==2 | ||
| // ray._immutable.normalAtOrigin = vec3(0.0,0.0,0.0); | ||
| // ray._immutable.wasBSDFAtOrigin = false; | ||
| // #endif | ||
|
|
||
| ray.payload.accumulation = (vector3_type)0.0; | ||
| ray.payload.otherTechniqueHeuristic = 0.0; // needed for direct eye-light paths | ||
| ray.payload.throughput = (vector3_type)1.0; | ||
| // #ifdef KILL_DIFFUSE_SPECULAR_PATHS | ||
| // ray._payload.hasDiffuse = false; | ||
| // #endif |
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.
payload shouldn't be initialized by raygen, just the direction
| // apply stochastic reconstruction filter | ||
| const float gaussianFilterCutoff = 2.5; | ||
| const float truncation = nbl::hlsl::exp(-0.5 * gaussianFilterCutoff * gaussianFilterCutoff); | ||
| vector2_type remappedRand = randVec.xy; | ||
| remappedRand.x *= 1.0 - truncation; | ||
| remappedRand.x += truncation; | ||
| nbl::hlsl::sampling::BoxMullerTransform<scalar_type> boxMuller; | ||
| boxMuller.stddev = 1.5; | ||
| tmp.xy += pixOffsetParam * boxMuller(remappedRand); |
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.
wrap this up in another struct, this is a Stochastic Reconstruction Filter of which one can have Tent, Box, etc. this one is Gaussian
| #ifndef _NBL_HLSL_EXT_RAYGEN_INCLUDED_ | ||
| #define _NBL_HLSL_EXT_RAYGEN_INCLUDED_ | ||
|
|
||
| #include <nbl/builtin/hlsl/sampling/box_muller_transform.hlsl> | ||
|
|
||
| #include "common.hlsl" | ||
|
|
||
| namespace RayGen | ||
| { | ||
|
|
||
| template<class Ray> | ||
| struct Basic | ||
| { | ||
| using this_t = Basic<Ray>; | ||
| using ray_type = Ray; | ||
| using scalar_type = typename Ray::scalar_type; | ||
| using vector3_type = typename Ray::vector3_type; | ||
|
|
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 looks useful put it in the path_tracing namespace and builtin directory as DefaultRayGen or BasicRayGen
@keptsecret after you merge
masteragain, you'll probably have the UI mess up and show changed from the merge commit, so close and reopen againTODO