Added some GUI options

This commit is contained in:
Jack Christensen 2023-11-07 01:17:16 -05:00
parent 9bca8907aa
commit 4983acd4eb
4 changed files with 26 additions and 28 deletions

View File

@ -4,7 +4,7 @@ Size=400,400
Collapsed=0
[Window][Debug Window]
Pos=1,7
Size=370,123
Pos=9,8
Size=785,130
Collapsed=0

View File

@ -15,8 +15,7 @@ uniform vec3 kd;
uniform vec3 ks;
uniform float smoothing;
in vec3 v_pos;
uniform vec3 sphere_center;
out vec4 FragColor;
@ -44,7 +43,7 @@ void initTorus()
void initSphere()
{
sphere.center = vec3(0.0, 0.25, 0.0);
sphere.center = sphere_center;
sphere.r = 0.25;
}
@ -76,17 +75,15 @@ vec3 estimateNormalsTorus(vec3 p)
}
float smoothMinSDF(float d1, float d2, float k) {
if (k == 0.0) k = 0.000001;
float h = max(k - abs(d1 - d2), 0) / k;
return min(d1, d2) - h * h * h * k * 1.0 / 6.0;
}
float smoothMaxSDF(float d1, float d2, float k) {
float h = clamp(0.5 + 0.5 * (d2 - d1) / k, 0.0, 1.0);
return mix(d2, d1, h) - k * h * (1.0 - h);
}
float blendSDF(float d1, float d2) {
return (d1 * d2) / (d1 + d2);
if (k == 0.0) k = 0.000001;
float h = min(k - abs(d1 - d2), 0) / k;
return min(d1, d2) - h * h * h * k * 1.0 / 6.0;
}
vec3 estimateSmoothNormals(vec3 p, float smoothness) {
@ -97,6 +94,14 @@ vec3 estimateSmoothNormals(vec3 p, float smoothness) {
float nz = smoothMinSDF(torusSDF(vec3(p.x, p.y, p.z + epsilon), torus.R, torus.r), sphereSDF(vec3(p.x, p.y, p.z + epsilon), sphere.center, sphere.r), smoothness) - d;
return normalize(vec3(nx, ny, nz));
}
vec3 estimateNormalsMax(vec3 p, float smoothness) {
float epsilon = 0.001;
float d = max(torusSDF(p, torus.R, torus.r), sphereSDF(p, sphere.center, sphere.r));
float nx = max(torusSDF(vec3(p.x + epsilon, p.y, p.z), torus.R, torus.r), sphereSDF(vec3(p.x + epsilon, p.y, p.z), sphere.center, sphere.r)) - d;
float ny = max(torusSDF(vec3(p.x, p.y + epsilon, p.z), torus.R, torus.r), sphereSDF(vec3(p.x, p.y + epsilon, p.z), sphere.center, sphere.r)) - d;
float nz = max(torusSDF(vec3(p.x, p.y, p.z + epsilon), torus.R, torus.r), sphereSDF(vec3(p.x, p.y, p.z + epsilon), sphere.center, sphere.r)) - d;
return normalize(vec3(nx, ny, nz));
}
void main(void)
@ -106,7 +111,7 @@ void main(void)
vec4 ray_pos = vec4(cam_pos, 1.0);
float ray_dist = 0.0;
float max_dist = 100.0;
float epsilon = 0.001;
float epsilon = 0.0001;
int steps = 0;
int max_steps = 1000;
vec3 light_pos = vec3(0.0, 1.0, 0.0);
@ -129,6 +134,7 @@ void main(void)
float distTorus = torusSDF(ray_pos.xyz, torus.R, torus.r);
float distSphere = sphereSDF(ray_pos.xyz, sphere.center, sphere.r);
float minDist = smoothMinSDF(distTorus, distSphere, k);
//float minDist = max(distTorus, distSphere);
//bool isTorus = distTorus < distSphere;
//float minDist = min(distTorus, distSphere);

View File

@ -1,15 +1,8 @@
#version 400
uniform mat4 P;
uniform mat4 V;
uniform mat4 M;
layout(location = 0) in vec3 pos_attrib;
out vec3 v_pos;
void main(void)
{
gl_Position = vec4(pos_attrib, 1.0);
//v_pos = pos_attrib;
}

View File

@ -59,6 +59,7 @@ namespace scene
int specular_exponent = 10.f;
float smoothing = 0.001f;
glm::vec3 sphere_center = { 0.0, 0.0, 0.0 };
}
namespace mouse
@ -169,7 +170,8 @@ void draw_gui(GLFWwindow* window)
}
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::SliderFloat("Smoothing", &scene::smoothing, 0.001f, 1.0f);
ImGui::SliderFloat("Smoothing", &scene::smoothing, 0.0f, 1.0f);
ImGui::SliderFloat3("Sphere Position", glm::value_ptr(scene::sphere_center), -2.0f, 2.0f);
ImGui::End();
static bool show_test = false;
@ -234,6 +236,11 @@ void display(GLFWwindow* window)
{
glUniform1f(smoothing_loc, scene::smoothing);
}
int sphere_center_loc = glGetUniformLocation(scene::shader, "sphere_center");
if (sphere_center_loc != -1)
{
glUniform3fv(sphere_center_loc, 1, glm::value_ptr(scene::sphere_center));
}
glUniform3fv(glGetUniformLocation(scene::shader, "light_pos"), 1, glm::value_ptr(scene::Lp));
glUniform3fv(glGetUniformLocation(scene::shader, "la"), 1, glm::value_ptr(scene::La));
@ -342,13 +349,6 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
scene::camera.zoom((float)yoffset * -0.1f);
}
//void framebuffer_size_callback(GLFWwindow* window, int width, int height)
//{
// window::size[0] = width;
// window::size[1] = height;
// glViewport(0, 0, width, height);
//}
void window_size_callback(GLFWwindow* window, int width, int height)
{
window::size[0] = width;
@ -380,7 +380,6 @@ int main()
}
glfwMakeContextCurrent(window);
//glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetKeyCallback(window, keyboard_callback);
glfwSetCursorPosCallback(window, cursor_pos_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);