levoy transfer function

This commit is contained in:
Robin 2025-01-20 16:30:53 +01:00
parent 9f7700ae80
commit 5a629815e7
6 changed files with 17 additions and 6 deletions

View File

@ -48,6 +48,8 @@ __device__ Vec3 d_cameraDir;
__device__ Point3 d_lightPos; __device__ Point3 d_lightPos;
__device__ Color3 d_backgroundColor; __device__ Color3 d_backgroundColor;
__device__ Vec3 d_cameraUp; __device__ Vec3 d_cameraUp;
__device__ double d_specularStrength;
__device__ int d_shininess;
Vec3 h_cameraUp = Vec3::init(0.0, 1.0, 0.0).normalize(); Vec3 h_cameraUp = Vec3::init(0.0, 1.0, 0.0).normalize();

View File

@ -41,8 +41,8 @@ const float stepSize = 0.02f;
// Shading consts // Shading consts
const double ambientStrength = 0.3; const double ambientStrength = 0.3;
const double diffuseStrength = 0.8; const double diffuseStrength = 0.8;
const double specularStrength = 0.5; extern __device__ double d_specularStrength; // = 0.5;
const int shininess = 32; extern __device__ int d_shininess; // = 32;
const float fov = 60.0f * (M_PI / 180.0f); const float fov = 60.0f * (M_PI / 180.0f);
// Camera and Light // Camera and Light

View File

@ -51,6 +51,8 @@ Widget::Widget(GLFWwindow* window) {
this->silhouettesThreshold = 0.02f; this->silhouettesThreshold = 0.02f;
this->levoyFocus = 0.5; this->levoyFocus = 0.5;
this->levoyWidth = 1; 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. // 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; float min = -1, max = 1;
ImGui::Begin("Transfer Function Controls"); 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::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::DragFloat("Sig. shift", &this->sigmoidShift, 0.01f, 0.0f, 1.0f, "%.2f");
ImGui::InputFloat("Sig. sxp", &this->sigmoidExp, 10.0f, 100.0f, "%.0f"); 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_silhouettesThreshold, &this->silhouettesThreshold, sizeof(float));
cudaMemcpyToSymbol(&d_levoyFocus, &this->levoyFocus, sizeof(float)); cudaMemcpyToSymbol(&d_levoyFocus, &this->levoyFocus, sizeof(float));
cudaMemcpyToSymbol(&d_levoyWidth, &this->levoyWidth, 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)); this->opacityConstReal = std::pow(10.0f, (-5 + 0.05 * this->opacityConst));
cudaMemcpyToSymbol(&d_opacityConst, &this->opacityConstReal, sizeof(float)); cudaMemcpyToSymbol(&d_opacityConst, &this->opacityConstReal, sizeof(float));

View File

@ -34,6 +34,8 @@ public:
float silhouettesThreshold; float silhouettesThreshold;
float levoyFocus; float levoyFocus;
float levoyWidth; float levoyWidth;
float specularStrength;
int shininess;
ImGuiIO io; ImGuiIO io;

View File

@ -6,8 +6,8 @@ __device__ Vec3 phongShading(const Vec3& normal, const Vec3& lightDir, const Vec
Vec3 diffuse = baseColor * (diffuseStrength * diff); Vec3 diffuse = baseColor * (diffuseStrength * diff);
Vec3 reflectDir = (normal * (2.0 * normal.dot(lightDir)) - lightDir).normalize(); Vec3 reflectDir = (normal * (2.0 * normal.dot(lightDir)) - lightDir).normalize();
double spec = pow(fmax(viewDir.dot(reflectDir), 0.0), shininess); double spec = pow(fmax(viewDir.dot(reflectDir), 0.0), d_shininess);
Vec3 specular = Vec3::init(1.0, 1.0, 1.0) * (specularStrength * spec); Vec3 specular = Vec3::init(1.0, 1.0, 1.0) * (d_specularStrength * spec);
return ambient + diffuse + specular; return ambient + diffuse + specular;
}; };

View File

@ -134,8 +134,8 @@ __device__ float4 transferFunction(float density, const Vec3& grad, const Point3
result.x = 0.0f; result.x = 0.0f;
result.y = 0.0f; result.y = 0.0f;
result.z = 0.0f; result.z = 0.0f;
// result.w = alpha; result.w = alpha;
result.w = d_opacityConst; // result.w = d_opacityConst;
} }
return result; return result;