From d5df4ea188261abe8770acf4e8dec4681ee28b71 Mon Sep 17 00:00:00 2001 From: Martin Opat Date: Wed, 15 Jan 2025 20:31:40 +0100 Subject: [PATCH] Added silhoutte gui control --- src/consts.cu | 2 ++ src/consts.h | 3 +++ src/gui/input/Widget.cpp | 7 +++++++ src/gui/input/Widget.h | 2 ++ src/illumination/transferFunction.cu | 2 +- 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/consts.cu b/src/consts.cu index 63f6242..30afa91 100644 --- a/src/consts.cu +++ b/src/consts.cu @@ -55,6 +55,8 @@ __device__ float d_alphaAcumLimit; __device__ int d_tfComboSelected; __device__ int d_tfComboSelectedColor; __device__ float d_opacityConst; +__device__ bool d_showSilhouettes; +__device__ float d_silhouettesThreshold; // ----------------------- Raycasting ----------------------- __device__ int d_samplesPerPixel; diff --git a/src/consts.h b/src/consts.h index b43dcd0..ca71393 100644 --- a/src/consts.h +++ b/src/consts.h @@ -73,6 +73,9 @@ extern __device__ int d_tfComboSelectedColor; extern __device__ float d_opacityConst; // samples per pixel extern __device__ int d_samplesPerPixel; +// Silhouettes +extern __device__ bool d_showSilhouettes; +extern __device__ float d_silhouettesThreshold; const int lenStopsPythonLike = 5; const int lenStopsGrayscale = 2; diff --git a/src/gui/input/Widget.cpp b/src/gui/input/Widget.cpp index 5884138..aa35119 100644 --- a/src/gui/input/Widget.cpp +++ b/src/gui/input/Widget.cpp @@ -33,6 +33,8 @@ Widget::Widget(GLFWwindow* window) { this->alphaAcumLimit = 0.4f; this->tfComboSelected = 0; this->opacityConst = 100; + this->showSilhouettes = true; + this->silhouettesThreshold = 0.02f; }; // REFACTOR: should probably not have all the logic in one function; something like a list of ImplementedWidgets with each a Render() function (a la interface) would be better. @@ -85,6 +87,9 @@ void Widget::tick(double fps) { } ImGui::EndCombo(); } + + if (ImGui::Button(this->showSilhouettes ? "Hide Silhouettes" : "Show Silhouettes")) this->showSilhouettes = !this->showSilhouettes; + ImGui::DragFloat("Silhouettes threshold", &this->silhouettesThreshold, 0.001f, 0.0f, 0.5f, "%.3f"); ImGui::End(); ImGui::Begin("Light Controls"); @@ -138,6 +143,8 @@ void Widget::copyToDevice() { cudaMemcpyToSymbol(&d_sigmoidExp, &this->sigmoidExp, sizeof(float)); cudaMemcpyToSymbol(&d_alphaAcumLimit, &this->alphaAcumLimit, sizeof(float)); cudaMemcpyToSymbol(&d_tfComboSelected, &this->tfComboSelected, sizeof(int)); + cudaMemcpyToSymbol(&d_showSilhouettes, &this->showSilhouettes, sizeof(bool)); + cudaMemcpyToSymbol(&d_silhouettesThreshold, &this->silhouettesThreshold, sizeof(float)); this->opacityConstReal = std::pow(10.0f, (-5 + 0.05 * this->opacityConst)); cudaMemcpyToSymbol(&d_opacityConst, &this->opacityConstReal, sizeof(float)); diff --git a/src/gui/input/Widget.h b/src/gui/input/Widget.h index 0fb1d28..99a1ef2 100644 --- a/src/gui/input/Widget.h +++ b/src/gui/input/Widget.h @@ -28,6 +28,8 @@ public: float alphaAcumLimit; int opacityConst; float opacityConstReal; + bool showSilhouettes; + float silhouettesThreshold; ImGuiIO io; diff --git a/src/illumination/transferFunction.cu b/src/illumination/transferFunction.cu index 060548a..36e845b 100644 --- a/src/illumination/transferFunction.cu +++ b/src/illumination/transferFunction.cu @@ -106,7 +106,7 @@ __device__ float4 transferFunction(float density, const Vec3& grad, const Point3 // --------------------------- Silhouettes --------------------------- Vec3 N = grad.normalize(); - if (grad.length() > 0.2f && fabs(N.dot(viewDir)) < 0.02f) { + if (d_showSilhouettes && grad.length() > 0.2f && fabs(N.dot(viewDir)) < d_silhouettesThreshold) { result.x = 0.0f; result.y = 0.0f; result.z = 0.0f;