From 5a629815e773b9be7e955ff8fa2558d2247748f7 Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 20 Jan 2025 16:30:53 +0100 Subject: [PATCH] levoy transfer function --- src/consts.cu | 2 ++ src/consts.h | 4 ++-- src/gui/input/Widget.cpp | 7 +++++++ src/gui/input/Widget.h | 2 ++ src/illumination/shading.cu | 4 ++-- src/illumination/transferFunction.cu | 4 ++-- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/consts.cu b/src/consts.cu index 69235dd..5b7159c 100644 --- a/src/consts.cu +++ b/src/consts.cu @@ -48,6 +48,8 @@ __device__ Vec3 d_cameraDir; __device__ Point3 d_lightPos; __device__ Color3 d_backgroundColor; __device__ Vec3 d_cameraUp; +__device__ double d_specularStrength; +__device__ int d_shininess; Vec3 h_cameraUp = Vec3::init(0.0, 1.0, 0.0).normalize(); diff --git a/src/consts.h b/src/consts.h index f303c5e..3e79de7 100644 --- a/src/consts.h +++ b/src/consts.h @@ -41,8 +41,8 @@ const float stepSize = 0.02f; // Shading consts const double ambientStrength = 0.3; const double diffuseStrength = 0.8; -const double specularStrength = 0.5; -const int shininess = 32; +extern __device__ double d_specularStrength; // = 0.5; +extern __device__ int d_shininess; // = 32; const float fov = 60.0f * (M_PI / 180.0f); // Camera and Light diff --git a/src/gui/input/Widget.cpp b/src/gui/input/Widget.cpp index daa5856..9ec02fb 100644 --- a/src/gui/input/Widget.cpp +++ b/src/gui/input/Widget.cpp @@ -51,6 +51,8 @@ Widget::Widget(GLFWwindow* window) { this->silhouettesThreshold = 0.02f; this->levoyFocus = 0.5; this->levoyWidth = 1; + this->specularStrength = 0.5; + this->shininess = 32; }; // 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. @@ -71,6 +73,8 @@ void Widget::tick(double fps) { float min = -1, max = 1; ImGui::Begin("Transfer Function Controls"); + ImGui::DragFloat("Specular Strength", &this->specularStrength, 0.01f, 0.0f, 1.0f, "%.2f"); + ImGui::DragInt("Shininess", &this->shininess, 1, 1, 64, "%d", ImGuiSliderFlags_AlwaysClamp); ImGui::DragInt("Grad. exp. (log [1e-10, 1])", &this->opacityK, 1, 0, 100, "%d%%", ImGuiSliderFlags_AlwaysClamp); ImGui::DragFloat("Sig. shift", &this->sigmoidShift, 0.01f, 0.0f, 1.0f, "%.2f"); ImGui::InputFloat("Sig. sxp", &this->sigmoidExp, 10.0f, 100.0f, "%.0f"); @@ -181,6 +185,9 @@ void Widget::copyToDevice() { cudaMemcpyToSymbol(&d_silhouettesThreshold, &this->silhouettesThreshold, sizeof(float)); cudaMemcpyToSymbol(&d_levoyFocus, &this->levoyFocus, sizeof(float)); cudaMemcpyToSymbol(&d_levoyWidth, &this->levoyWidth, sizeof(float)); + double specularStrengthDouble = this->specularStrength; + cudaMemcpyToSymbol(&d_specularStrength, &specularStrengthDouble, sizeof(double)); + cudaMemcpyToSymbol(&d_shininess, &this->shininess, sizeof(int)); 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 a28a718..f578577 100644 --- a/src/gui/input/Widget.h +++ b/src/gui/input/Widget.h @@ -34,6 +34,8 @@ public: float silhouettesThreshold; float levoyFocus; float levoyWidth; + float specularStrength; + int shininess; ImGuiIO io; diff --git a/src/illumination/shading.cu b/src/illumination/shading.cu index 8fa8970..f2d067e 100644 --- a/src/illumination/shading.cu +++ b/src/illumination/shading.cu @@ -6,8 +6,8 @@ __device__ Vec3 phongShading(const Vec3& normal, const Vec3& lightDir, const Vec Vec3 diffuse = baseColor * (diffuseStrength * diff); Vec3 reflectDir = (normal * (2.0 * normal.dot(lightDir)) - lightDir).normalize(); - double spec = pow(fmax(viewDir.dot(reflectDir), 0.0), shininess); - Vec3 specular = Vec3::init(1.0, 1.0, 1.0) * (specularStrength * spec); + double spec = pow(fmax(viewDir.dot(reflectDir), 0.0), d_shininess); + Vec3 specular = Vec3::init(1.0, 1.0, 1.0) * (d_specularStrength * spec); return ambient + diffuse + specular; }; diff --git a/src/illumination/transferFunction.cu b/src/illumination/transferFunction.cu index 72dd27b..1775af3 100644 --- a/src/illumination/transferFunction.cu +++ b/src/illumination/transferFunction.cu @@ -134,8 +134,8 @@ __device__ float4 transferFunction(float density, const Vec3& grad, const Point3 result.x = 0.0f; result.y = 0.0f; result.z = 0.0f; - // result.w = alpha; - result.w = d_opacityConst; + result.w = alpha; + // result.w = d_opacityConst; } return result;