Skip to content

Conversation

@devshgraphicsprogramming
Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming commented Nov 12, 2025

Description

Continues #863

Testing

TODO list:

Missing https://github.com/Devsh-Graphics-Programming/Nabla/blob/master/include/nbl/builtin/glsl/sampling/quantized_sequence.glsl

The #define should be template<uint16_t BytesLog2,int32_t Dim> QuantizedSequence in namespace nbl::sampling

You treat it as Dim of UNORM shoved in 0x1<<BytesLog2 data type thats either vector<uint16_t,N> or vector<uint32_t,N> depending on whats easier to decode, never uint64_t

there should be a vector<FloatingPointScalar,D> nbl::sampling::decode(const QuantizedSequence<N,D> val, QuantizedSequence<N,D> scramble)

Valid combos are BytesLog2 from 1 to 4 (not 0 because no uint8_t type) and Dim from 1 to 4

#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.

#863 (comment)

Needs to be a struct but also with an operator() (because value can only be an int)

Comment on lines +11 to +22
namespace nbl
{
namespace hlsl
{

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, also don't forget the sampling namespace

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

using scalar_type = T;
using vector2_type = vector<T, 2>;

static Linear<T> create(NBL_CONST_REF_ARG(vector2_type) linearCoeffs)
Copy link
Member Author

Choose a reason for hiding this comment

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

need to document that they're start and end importance values

Comment on lines +27 to +38
retval.linearCoeffs = linearCoeffs;
return retval;
}

scalar_type generate(scalar_type u)
{
const scalar_type rcpDiff = 1.0 / (linearCoeffs[0] - linearCoeffs[1]);
const vector2_type squaredCoeffs = linearCoeffs * linearCoeffs;
return nbl::hlsl::abs(rcpDiff) < numeric_limits<scalar_type>::max ? (linearCoeffs[0] - nbl::hlsl::sqrt(nbl::hlsl::mix(squaredCoeffs[0], squaredCoeffs[1], u))) * rcpDiff : u;
}

vector2_type linearCoeffs;
Copy link
Member Author

@devshgraphicsprogramming devshgraphicsprogramming Nov 12, 2025

Choose a reason for hiding this comment

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

your members should be what can be precomputed from generate without knowing u so:

  • rcpDiff
  • squaredCoeffs

and obviously keep linearCoeffs[0]

Actually you could precompute squaredCoeffs[1]-squaredCoeffs[0] to turn mix into u*diff+base

Comment on lines +34 to +46
vector3_type slerp_delta(NBL_CONST_REF_ARG(vector3_type) start, NBL_CONST_REF_ARG(vector3_type) preScaledWaypoint, scalar_type cosAngleFromStart)
{
vector3_type planeNormal = nbl::hlsl::cross(start,preScaledWaypoint);

cosAngleFromStart *= 0.5;
const scalar_type sinAngle = nbl::hlsl::sqrt(0.5 - cosAngleFromStart);
const scalar_type cosAngle = nbl::hlsl::sqrt(0.5 + cosAngleFromStart);

planeNormal *= sinAngle;
const vector3_type precompPart = nbl::hlsl::cross(planeNormal, start) * 2.0;

return precompPart * cosAngle + nbl::hlsl::cross(planeNormal, precompPart);
}
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 a quaternion struct with all this stuff

Comment on lines 5 to 7
#ifndef _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_INCLUDED_
#define _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_INCLUDED_

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 should obviously be spherical_triangle.hlsl

Comment on lines 49 to 63
vector3_type cos_sides,csc_sides;
if (pyramidAngles(cos_sides, csc_sides))
return 0.f;

// these variables might eventually get optimized out
cos_a = cos_sides[0];
cos_c = cos_sides[2];
csc_b = csc_sides[1];
csc_c = csc_sides[2];

// Both vertices and angles at the vertices are denoted by the same upper case letters A, B, and C. The angles A, B, C of the triangle are equal to the angles between the planes that intersect the surface of the sphere or, equivalently, the angles between the tangent vectors of the great circle arcs where they meet at the vertices. Angles are in radians. The angles of proper spherical triangles are (by convention) less than PI
cos_vertices = hlsl::clamp((cos_sides - cos_sides.yzx * cos_sides.zxy) * csc_sides.yzx * csc_sides.zxy, (vector3_type)(-1.f), (vector3_type)1.f); // using Spherical Law of Cosines (TODO: do we need to clamp anymore? since the pyramid angles method introduction?)
sin_vertices = hlsl::sqrt((vector3_type)1.f - cos_vertices * cos_vertices);

return math::getArccosSumofABC_minus_PI(cos_vertices[0], cos_vertices[1], cos_vertices[2], sin_vertices[0], sin_vertices[1], sin_vertices[2]);
Copy link
Member Author

Choose a reason for hiding this comment

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

see if you can do better with the sincos_accumulator

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.

4 participants