-
Notifications
You must be signed in to change notification settings - Fork 67
Hlsl path tracer example #947
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?
Conversation
…l_path_tracer_example
| #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); |
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.
Needs to be a struct but also with an operator() (because value can only be an int)
| 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; | ||
| } |
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.
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; |
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.
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) |
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.
need to document that they're start and end importance values
| 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; |
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.
your members should be what can be precomputed from generate without knowing u so:
rcpDiffsquaredCoeffs
and obviously keep linearCoeffs[0]
Actually you could precompute squaredCoeffs[1]-squaredCoeffs[0] to turn mix into u*diff+base
| 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); | ||
| } |
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 quaternion struct with all this stuff
| #ifndef _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_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.
file should obviously be spherical_triangle.hlsl
| 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]); |
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.
see if you can do better with the sincos_accumulator
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
#defineshould betemplate<uint16_t BytesLog2,int32_t Dim> QuantizedSequencein namespacenbl::samplingYou treat it as Dim of
UNORMshoved in0x1<<BytesLog2data type thats eithervector<uint16_t,N>orvector<uint32_t,N>depending on whats easier to decode, neveruint64_tthere should be a
vector<FloatingPointScalar,D> nbl::sampling::decode(const QuantizedSequence<N,D> val, QuantizedSequence<N,D> scramble)Valid combos are
BytesLog2from 1 to 4 (not 0 because no uint8_t type) and Dim from 1 to 4