Skip to content

Commit fa41e99

Browse files
committed
Add neighbour selection heuristic controls
1 parent 0f558c8 commit fa41e99

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,5 @@
8888
"bitset": "cpp",
8989
"regex": "cpp",
9090
"typeindex": "cpp"
91-
},
92-
"cmake.buildEnvironment": {
93-
"embree_DIR": "C:/embree-4.3.1.x64.windows/lib/cmake/embree-4.3.1/",
94-
"TBB_DIR": "C:/Program Files (x86)/Intel/oneAPI/tbb/2021.12/lib/cmake/tbb/"
9591
}
9692
}

src/ray_tracing/embree_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ bool EmbreeInterface::closestHit(Ray& ray, HitInfo& hitInfo) const {
8080
rtcInterpolate0(rtcGetGeometry(m_scene, rayhit.hit.geomID), rayhit.hit.primID, rayhit.hit.u, rayhit.hit.v,
8181
RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE, 1, glm::value_ptr(hitInfo.texCoord), 2);
8282
hitInfo.material = m_meshToMaterial.at(rayhit.hit.geomID);
83+
hitInfo.geometryId = rayhit.hit.geomID;
8384
ray.t = rayhit.ray.tfar;
8485

8586
// Debug draw ray and normal, then return true

src/rendering/neighbour_selection.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
#include <algorithm>
44
#include <random>
55

6+
67
bool areSimilar(const RayHit& lhs, const RayHit& rhs, const Features& features) {
7-
// TODO: Expand to user-adjustable values (and maybe additional properties)
8-
float depthFracDiff = std::abs(1.0f - (lhs.ray.t / rhs.ray.t)); // Depth difference (greater than 10% leads to rejection)
9-
float normalsDotProd = glm::dot(lhs.hit.normal, rhs.hit.normal); // Normal difference (greater than 25 degrees leads to rejection)
10-
if (depthFracDiff > 0.1f || normalsDotProd < 0.90630778703f) { return false; } // TODO: Apply R&L instead of this lemming bullshit
8+
// Same geometries
9+
if (features.neighbourSameGeometry && lhs.hit.geometryId != rhs.hit.geometryId) { return false; }
10+
11+
// Depth difference
12+
float depthFracDiff = std::abs(1.0f - (lhs.ray.t / rhs.ray.t));
13+
if (depthFracDiff > features.neighbourMaxDepthDifferenceFraction) { return false; }
14+
15+
// Normal angle difference
16+
float maxDiffCos = std::cos(features.neighbourMaxNormalAngleDifferenceRadians);
17+
float normalsDotProd = glm::dot(lhs.hit.normal, rhs.hit.normal);
18+
if (normalsDotProd < features.neighbourMaxNormalAngleDifferenceRadians) { return false; }
19+
20+
// We passed the similarity test!
1121
return true;
1222
}
1323

src/ui/ui.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ void UiManager::drawProjectTab() {
7272
}
7373

7474
void UiManager::drawRayTracingTab() {
75+
drawRayTracingNeighbourSelectionParams();
76+
ImGui::Spacing();
77+
ImGui::Separator();
7578
drawRayTracingFeaturesToggles();
7679
ImGui::Spacing();
7780
ImGui::Separator();
@@ -257,6 +260,14 @@ void UiManager::drawLightControls() {
257260
}
258261
}
259262

263+
void UiManager::drawRayTracingNeighbourSelectionParams() {
264+
if (ImGui::CollapsingHeader("Neighbour Selection Heuristics", ImGuiTreeNodeFlags_DefaultOpen)) {
265+
ImGui::Checkbox("Same geometry", &config.features.neighbourSameGeometry);
266+
ImGui::SliderFloat("Max depth difference fraction", &config.features.neighbourMaxDepthDifferenceFraction, 0.01f, 1.0f);
267+
ImGui::SliderAngle("Max normal angle difference", &config.features.neighbourMaxNormalAngleDifferenceRadians, 0.0f, 90.0f);
268+
}
269+
}
270+
260271
void UiManager::drawRayTracingFeaturesToggles() {
261272
if (ImGui::CollapsingHeader("Features", ImGuiTreeNodeFlags_DefaultOpen)) {
262273
ImGui::Text("Common");

src/ui/ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class UiManager {
4848

4949
// Ray-tracing UI bits
5050
void drawRayTracingTab();
51+
void drawRayTracingNeighbourSelectionParams();
5152
void drawRayTracingFeaturesToggles();
5253
void drawRayTracingParams();
5354

src/utils/common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct HitInfo {
4545
glm::vec3 barycentricCoord;
4646
glm::vec2 texCoord;
4747
Material material;
48+
uint32_t geometryId;
4849
};
4950

5051
struct RayHit {
@@ -106,6 +107,11 @@ struct Features {
106107
uint32_t numNeighboursToSample = 5U;
107108
uint32_t spatialResampleRadius = 10U;
108109

110+
// Neighbour selection heuristics controls
111+
bool neighbourSameGeometry = false;
112+
float neighbourMaxDepthDifferenceFraction = 0.10f;
113+
float neighbourMaxNormalAngleDifferenceRadians = 0.436332f;
114+
109115
// R-MIS/R-OMIS parameter(s)
110116
uint32_t maxIterationsMIS = 5U;
111117
NeighbourSelectionStrategy neighbourSelectionStrategy = NeighbourSelectionStrategy::Random;

0 commit comments

Comments
 (0)