Commit d9b9ebc1 authored by Johannes Braun's avatar Johannes Braun
Browse files

Fixed local triangle intersection not intersecting triangles if exactly hitting the border.

parent d8912216
......@@ -4,7 +4,7 @@ Size=353,64
Collapsed=0
[Scene]
Pos=11,89
Pos=12,93
Size=352,837
Collapsed=0
......
<linespace version="1.0">
<item name="subdivisions" value="32"/>
<item name="grid-subdivisions" value="1"/>
<item name="subdivisions" value="20"/>
<item name="grid-subdivisions" value="10"/>
<item name="radial-subdivision" value="50"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -108,14 +108,14 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
}
temp_t_min = tnext[axis];
index[axis] += int( step[axis] );
if ((index[axis] < 0) || (index[axis] >= mesh.grid_linespace.grid_resolution[axis]))
if (step[axis] == 0 || (index[axis] < 0) || (index[axis] >= mesh.grid_linespace.grid_resolution[axis]))
{
break;
}
tnext[axis] += delta[axis];
// TODO: endless loop sometimes.
break;
//break;
}
}
}
......
......@@ -31,5 +31,5 @@ void main()
vec2 random = settings.u_random_subpixel ? vec2(0, 0) : rand2D(random_seed + id, target_size.x*target_size.y);
traces_data[id].ray = u_camera.getRayFromPixel(vec2(gl_GlobalInvocationID.xy), random, vec2(target_size));
traces_data[id].hit.invalidate();
traces_data[id].ray.nearestIntersection(traces_data[id].hit, true);
traces_data[id].ray.nearestIntersection(traces_data[id].hit, false);
}
......@@ -96,7 +96,7 @@ bool intersectsBounds(const in Ray ray, const in Bounds bounds, const in float m
bool intersectsTriangle(const in Ray ray, int triangle_index, const in Mesh mesh, inout float t, inout float u, inout float v)
{
float EPSILON = 1e-10;
float EPSILON = 1;//1e-100;
vec3 e1, e2; //Edge1, Edge2
vec3 P, Q, T;
......@@ -205,6 +205,7 @@ bool intersectsTrianglePlane(const in Ray ray, int triangle_index, const in Mesh
bool intersectsTriangleLocal(const in Ray ray, int triangle_index, const in Mesh mesh, inout float t, inout float u, inout float v)
{
float EPSILON = FLT_EPSILON;
float border_epsilon = 0.0000001f;
vec3 e1, e2; //Edge1, Edge2
vec3 P, Q, T;
......@@ -236,7 +237,7 @@ bool intersectsTriangleLocal(const in Ray ray, int triangle_index, const in Mesh
u = dot(T, P) * inv_det;
//The intersection lies outside of the triangle
if (u < 0.f || u > 1.f) return false;
if (u < -border_epsilon || u > 1.f+border_epsilon) return false;
//Prepare to test v parameter
Q = cross(T, e1);
......@@ -244,11 +245,11 @@ bool intersectsTriangleLocal(const in Ray ray, int triangle_index, const in Mesh
//Calculate V parameter and test bound
v = dot(ray.direction.xyz, Q) * inv_det;
//The intersection lies outside of the triangle
if (v < 0.f || u + v > 1.f) return false;
if (v < -border_epsilon || u + v > 1.f+border_epsilon) return false;
t = dot(e2, Q) * inv_det;
if (t > EPSILON) { //ray intersection
if (t > border_epsilon) { //ray intersection
return true;
}
......
......@@ -31,7 +31,7 @@ namespace glare::core
gl::textureParameter(m_handle, gl::TextureParameter::eCompareMode, m_latest_parameters.compare_mode);
gl::textureParameter(m_handle, gl::TextureParameter::eCompareFunc, m_latest_parameters.compare_func);
//gl::generateTextureMipmap(m_handle);
gl::generateTextureMipmap(m_handle);
}
unsigned Texture::id() const
......
......@@ -361,11 +361,10 @@ namespace glare::core
m_depth = image.depth();
gl::pixelStorei(gl::PixelStoreAlignment::eUnpack, 1);
clear(0);
gl::textureImage(m_handle, t, level, m_format, texture_format, { image.width(), image.height(), image.depth() }, image.data().empty() ? nullptr : image.data().data());
if (!no_apply)
apply(std::move(parameters));
gl::textureImage(m_handle, t, level, m_format, texture_format, { image.width(), image.height(), image.depth() }, image.data().empty() ? nullptr : image.data().data());
gl::generateTextureMipmap(m_handle);
}
......
......@@ -9,7 +9,7 @@
Window::Window(unsigned int width, unsigned int height, std::string title) { initialize(width, height, title); }
Window::Window() : m_main_window(nullptr), m_vsync(VSync::eOn60), m_width(0), m_height(0) {
} void Window::initialize(unsigned int width, unsigned int height, std::string title) { m_width = width; m_height = height;
glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
// To enable some more debug messages and hints glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
// To enable robust buffer access on out-of-bounds accesses. glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_NO_RESET_NOTIFICATION);
if (width * height == 0) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
......
......@@ -88,7 +88,7 @@ namespace glare::raytrace
m_render_shader->bindSubroutine(gl::ShaderType::eCompute, "u_light_sample[3]", "sampleAmbient");
}
const core::Texture &Pathtracer::render(uint32_t width, uint32_t height)
const core::Texture &Pathtracer::render(unsigned width, unsigned height)
{
if (width != m_width || height != m_height) {
m_width = width;
......@@ -112,9 +112,9 @@ namespace glare::raytrace
if (m_samples_current >= m_samples_max)
return *m_render_target;
const static std::unique_ptr<RayGenerator> ray_generator = std::make_unique<RayGenerator>();
{
LogTime("Generate Primary Rays", m_debug_times);
const static std::unique_ptr<RayGenerator> ray_generator = std::make_unique<RayGenerator>();
ray_generator->generate(*this);
}
......@@ -122,7 +122,7 @@ namespace glare::raytrace
LogTime("Trace and Bounce", m_debug_times);
m_render_shader->use();
m_render_shader->uniform("u_render_config.current_sample", m_samples_current);
m_render_shader->uniform("random_seed", ray_generator->randomSeed());
m_render_shader->uniform("random_seed", RayGenerator::randomSeed());
m_render_shader->dispatch2D(width, 16, height, 16);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment