Skip to content

Commit 258836a

Browse files
committed
latest example
2 parents 546ed90 + 2539522 commit 258836a

22 files changed

Lines changed: 1126 additions & 519 deletions

File tree

.github/workflows/build-nabla.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ jobs:
569569
$imageBadge | Set-Content -Path "$imagePath/image-badge.json" -Encoding utf8
570570
571571
- name: Deploy Badges
572-
uses: Devsh-Graphics-Programming/actions-gh-pages@v4.0.0-devsh.1
572+
uses: peaceiris/actions-gh-pages@v3
573573
with:
574574
github_token: ${{ secrets.GITHUB_TOKEN }}
575575
publish_branch: badges

3rdparty/boost/superproject

include/nbl/asset/ICPUScene.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class ICPUScene final : public IAsset, public IScene
276276
instances.emplace_back().instance = std::move(inst);
277277
}
278278
// TODO: adjust BLAS geometry flags according to materials set opaqueness and NO_DUPLICATE_ANY_HIT_INVOCATION_BIT
279-
SResult retval = {.instances=core::make_refctd_dynamic_array<decltype(SResult::instances)>(instanceCount),.allInstancesValid=allInstancesValid};
279+
SResult retval = {.instances=core::make_refctd_dynamic_array<decltype(SResult::instances)>(instances.size()),.allInstancesValid=allInstancesValid};
280280
std::move(instances.begin(),instances.end(),retval.instances->begin());
281281
return retval;
282282
}

include/nbl/asset/material_compiler3/CFrontendIR.h

Lines changed: 221 additions & 44 deletions
Large diffs are not rendered by default.

include/nbl/asset/utils/IShaderCompiler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "nbl/builtin/hlsl/enums.hlsl"
1818

19+
#include <functional>
20+
1921
namespace nbl::asset
2022
{
2123

@@ -136,6 +138,7 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
136138
E_SPIRV_VERSION targetSpirvVersion = E_SPIRV_VERSION::ESV_1_6;
137139
bool depfile = false;
138140
system::path depfilePath = {};
141+
std::function<void(std::string_view)> onPartialOutputOnFailure = {};
139142
};
140143

141144
// https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#debugging

include/nbl/builtin/hlsl/path_tracing/unidirectional.hlsl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct Unidirectional
5454
return hlsl::dot(spectralTypeToLumaCoeffs, col);
5555
}
5656

57-
bool closestHitProgram(uint16_t depth, uint32_t _sample, NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(closest_hit_type) intersectData)
57+
bool closestHitProgram(const bool lastBounce, uint16_t depth, uint32_t _sample, NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(closest_hit_type) intersectData)
5858
{
5959
anisotropic_interaction_type interaction = intersectData.getInteraction();
6060

@@ -76,7 +76,7 @@ struct Unidirectional
7676
ray.addPayloadContribution(emissive);
7777
}
7878

79-
if (!matLightID.canContinuePath())
79+
if (lastBounce || !matLightID.canContinuePath())
8080
return false;
8181

8282
bxdfnode_type bxdf = materialSystem.getBxDFNode(matID, interaction);
@@ -185,16 +185,17 @@ struct Unidirectional
185185
// bounces
186186
// note do 1-based indexing because we expect first dimension was consumed to generate the ray
187187
bool continuePath = true;
188+
bool notMissed = true;
188189
for (uint16_t d = 1; (d <= maxDepth) && continuePath; d++)
189190
{
190191
ray.setT(numeric_limits<scalar_type>::max);
191192
closest_hit_type intersection = intersector_type::traceClosestHit(scene, ray);
192193

193-
continuePath = intersection.foundHit();
194-
if (continuePath)
195-
continuePath = closestHitProgram(d, sampleIndex, ray, intersection);
194+
notMissed = intersection.foundHit();
195+
if (notMissed)
196+
continuePath = closestHitProgram(d==maxDepth, d, sampleIndex, ray, intersection);
196197
}
197-
if (!continuePath)
198+
if (!notMissed)
198199
missProgram(ray);
199200

200201
const uint32_t sampleCount = sampleIndex + 1;

include/nbl/builtin/hlsl/shapes/spherical_triangle.hlsl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ struct SphericalTriangle
4848
if (pyramidAngles())
4949
return 0.f;
5050

51-
// 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
51+
// 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,
52+
// 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
5253
cos_vertices = hlsl::clamp((cos_sides - cos_sides.yzx * cos_sides.zxy) * csc_sides.yzx * csc_sides.zxy, hlsl::promote<vector3_type>(-1.0), hlsl::promote<vector3_type>(1.0)); // using Spherical Law of Cosines (TODO: do we need to clamp anymore? since the pyramid angles method introduction?)
5354
sin_vertices = hlsl::sqrt(hlsl::promote<vector3_type>(1.0) - cos_vertices * cos_vertices);
5455

@@ -64,7 +65,7 @@ struct SphericalTriangle
6465
return solidAngle(dummy0,dummy1);
6566
}
6667

67-
scalar_type projectedSolidAngle(const vector3_type receiverNormal, NBL_REF_ARG(vector3_type) cos_sides, NBL_REF_ARG(vector3_type) csc_sides, NBL_REF_ARG(vector3_type) cos_vertices)
68+
scalar_type projectedSolidAngle(const vector3_type receiverNormal, NBL_REF_ARG(vector3_type) cos_vertices)
6869
{
6970
if (pyramidAngles())
7071
return 0.f;
@@ -75,10 +76,22 @@ struct SphericalTriangle
7576
awayFromEdgePlane[0] = hlsl::cross(vertices[1], vertices[2]) * csc_sides[0];
7677
awayFromEdgePlane[1] = hlsl::cross(vertices[2], vertices[0]) * csc_sides[1];
7778
awayFromEdgePlane[2] = hlsl::cross(vertices[0], vertices[1]) * csc_sides[2];
79+
// The ABS makes it so that the computation is correct for an `abs(cos(theta))` factor which is the projected solid angle used for a BSDF
80+
// Proof: Kelvin-Stokes theorem, if you split the set into two along the horizon with constant CCW winding, the `cross` along the shared edge goes in different directions and cancels out,
81+
// while `acos` of the clipped great arcs corresponding to polygon edges add up to the original sides again
7882
const vector3_type externalProducts = hlsl::abs(hlsl::mul(/* transposed already */awayFromEdgePlane, receiverNormal));
7983

84+
// Far TODO: `cross(A,B)*acos(dot(A,B))/sin(1-dot^2)` can be done with `cross*acos_csc_approx(dot(A,B))`
85+
// We could skip the `csc_sides` factor, and computing `pyramidAngles` and replace them with this approximation weighting before the dot product with the receiver notmal
86+
// The curve fit "revealed in a dream" to me is `exp2(F(log2(x+1)))` where `F(u)` is a polynomial, so far I've calculated `F = (1-u)0.635+(1-u^2)0.0118` which gives <5% error until 165 degrees
87+
// I have a feeling that a polynomial of ((Au+B)u+C)u+D could be sufficient if it has following properties:
88+
// `F(0) = 0` and
89+
// `F(u) <= log2(\frac{\cos^{-1}\left(2^{x}-1\right)}{\sqrt{1-\left(2^{x}-1\right)^{2}}})` because you want to consistently under-estimate the Projected Solid Angle to avoid creating energy
90+
// See https://www.desmos.com/calculator/sdptomhbju
91+
// Furthermore we could clip the polynomial calc to `Cu+D or `(Bu+C)u+D` for small arguments
8092
const vector3_type pyramidAngles = hlsl::acos<vector3_type>(cos_sides);
81-
return hlsl::dot(pyramidAngles, externalProducts) / (2.f * numbers::pi<scalar_type>);
93+
// So that riangle covering almost whole hemisphere sums to PI
94+
return hlsl::dot(pyramidAngles, externalProducts) * scalar_type(0.5);
8295
}
8396

8497
vector3_type vertices[3];

include/nbl/ext/MitsubaLoader/SContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct SContext final
8787
#endif
8888
core::smart_refctd_ptr<frontend_ir_t> frontIR;
8989
// common frontend nodes
90+
frontend_ir_t::typed_pointer_type<const frontend_ir_t::CSpectralVariable> unityFactor;
9091
frontend_ir_t::typed_pointer_type<const frontend_ir_t::IExprNode> errorBRDF;
9192
frontend_ir_t::typed_pointer_type<const frontend_ir_t::CLayer> errorMaterial, unsupportedPhong, unsupportedWard;
9293
frontend_ir_t::typed_pointer_type<const frontend_ir_t::CDeltaTransmission> deltaTransmission;
@@ -95,6 +96,7 @@ struct SContext final
9596
{
9697
Albedo,
9798
Opacity,
99+
Weight,
98100
MitsubaExtraFactor,
99101
Count
100102
};

src/nbl/asset/interchange/CImageLoaderJPG.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ bool CImageLoaderJPG::isALoadableFileFormat(system::IFile* _file, const system::
157157
if (!_file)
158158
return false;
159159

160-
uint32_t header = 0;
160+
uint16_t soiMarker = 0;
161161
system::IFile::success_t success;
162-
_file->read(success, &header, 6, sizeof(uint32_t));
163-
return success && ((header&0x00FFD8FFu)==0x00FFD8FFu || header == 0x4a464946 || header == 0x4649464a || header == 0x66697845u || header == 0x70747468u); // maybe 0x4a464946 can go
162+
_file->read(success, &soiMarker, 0, sizeof(uint16_t));
163+
constexpr auto JPEG_VALID_SOI_MARKER = 0xD8FF;
164+
return success && (soiMarker == JPEG_VALID_SOI_MARKER);
164165
#endif
165166
}
166167

0 commit comments

Comments
 (0)