Skip to content

Hlsl path tracer example #863

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

Open
wants to merge 158 commits into
base: hlsl_bxdfs
Choose a base branch
from

Conversation

devshgraphicsprogramming
Copy link
Member

Description

Testing

TODO list:

kevyuu and others added 30 commits January 21, 2025 14:24
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
Signed-off-by: kevyuu <kevin.kayu@gmail.com>
AnastaZIuk and others added 17 commits March 31, 2025 10:13
…er_attached

nbl::system::isDebuggerAttached
…r-steps_bugfix

added -fconstexpr-ops-limit for gcc
…fs_hlsl

Maths for HLSL BxDFs (template cmath, tgmath)
…nfo at build time (use gtml outputs); fix a few syntax errors
…build counter (the iteration thats currently being stored)

Next are callbacks upon DeferredOperation and CommandBuffer completion
… the buildAccelerationStructures command in the pool.

Now just time for callbacks.

@Crisspl I also added that feature you wanted `bool IGPUCommandBuffer::recordReferences(const std::span<const IReferenceCounted*> refs);`
Add absolutely awesome callback to `IQueue::SSubmitInfo`
…cking

TLAS tracking BLAS they use doing build
Comment on lines 123 to +125
bool partitionRandVariable(float leftProb, NBL_REF_ARG(float) xi, NBL_REF_ARG(float) rcpChoiceProb)
{
#ifdef __HLSL_VERSION
NBL_CONSTEXPR float NEXT_ULP_AFTER_UNITY = asfloat(0x3f800001u);
#else
NBL_CONSTEXPR float32_t NEXT_ULP_AFTER_UNITY = bit_cast<float32_t>(0x3f800001u);
#endif
const float32_t NEXT_ULP_AFTER_UNITY = bit_cast<float32_t>(0x3f800001u);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be templated on T instead of float and live in sampling.hlsl (named same as the folder and namespace), do as part of #811

P.S. for the constant you can use

const T NextULPAfterUnity = bit_cast<T>(++bit_cast<unsigned_int_of_size_t<sizeof(T)> >(T(1)));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you can put it in sampling/basic.hlsl

Comment on lines +1 to +68
// Copyright (C) 2018-2023 - 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_MATH_MORTON_INCLUDED_
#define _NBL_BUILTIN_HLSL_MATH_MORTON_INCLUDED_

#include "nbl/builtin/hlsl/cpp_compat.hlsl"

namespace nbl
{
namespace hlsl
{
namespace math
{

namespace impl
{

template<typename T, uint32_t bitDepth>
struct MortonComponent;

template<typename T>
struct MortonComponent<T, 8u>
{
static T decode2d(T x)
{
x &= 0x55555555u;
x = (x ^ (x >> 1u)) & 0x33333333u;
x = (x ^ (x >> 2u)) & 0x0f0f0f0fu;
x = (x ^ (x >> 4u)) & 0x00ff00ffu;
return x;
}
};

template<typename T>
struct MortonComponent<T, 32u>
{
static T decode2d(T x)
{
x &= 0x55555555u;
x = (x ^ (x >> 1u)) & 0x33333333u;
x = (x ^ (x >> 2u)) & 0x0f0f0f0fu;
x = (x ^ (x >> 4u)) & 0x00ff00ffu;
x = (x ^ (x >> 8u)) & 0x0000ffffu;
x = (x ^ (x >> 16u));
return x;
}
};

}

template<typename T, uint32_t bitDepth=sizeof(T)*8u>
struct Morton
{
using vector2_type = vector<T, 2>;
using component_type = impl::MortonComponent<T, bitDepth>;

static vector2_type decode2d(T x)
{
return vector2_type(component_type::decode2d(x), component_type::decode2d(x >> 1u));
}
};

}
}
}

#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file will die after #860 is merged

return retval;
}

vector2_type generate(NBL_REF_ARG(scalar_type) rcpPdf, NBL_CONST_REF_ARG(vector2_type) _u)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need some structs like

template<typename V, typename P=float>
struct ValueAndPdf;

template<typename T, typename P=float>
struct ValueAndRcpPdf;

in sampling/basic.hlsl

do as part of #811

P.S. can require that P is a ScalarFloat

Comment on lines +16 to +22
template<typename T>
vector<T,2> boxMullerTransform(vector<T,2> xi, T stddev)
{
T sinPhi, cosPhi;
math::sincos<T>(2.0 * numbers::pi<float> * xi.y - numbers::pi<float>, sinPhi, cosPhi);
return vector<T,2>(cosPhi, sinPhi) * nbl::hlsl::sqrt(-2.0 * nbl::hlsl::log(xi.x)) * stddev;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turn into struct with stddev as a member

return 4.0 * nbl::hlsl::mix(nbl::hlsl::mix(bilinearCoeffs[0], bilinearCoeffs[1], u.x), nbl::hlsl::mix(bilinearCoeffs[2], bilinearCoeffs[3], u.x), u.y) / (bilinearCoeffs[0] + bilinearCoeffs[1] + bilinearCoeffs[2] + bilinearCoeffs[3]);
}

vector4_type bilinearCoeffs;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document which index/component maps to which vertex of the unit square

@devshgraphicsprogramming
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants