Commit 39f14ab3 authored by Johannes Braun's avatar Johannes Braun
Browse files

Fixed some issues with flat objects.

parent d9b9ebc1
......@@ -4,7 +4,7 @@ Size=353,64
Collapsed=0
[Scene]
Pos=12,93
Pos=0,67
Size=352,837
Collapsed=0
......
......@@ -73,21 +73,24 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
Ray local_ray = ray.makeRelative(mesh);
Bounds mesh_bounds = mesh.nodes[0].bounds;
float temp_tmin, temp_tmax;
if(local_ray.intersectsBounds(mesh_bounds, current_t))
if(local_ray.intersectsBounds(mesh_bounds, temp_tmin, temp_tmax, current_t))
{
vec3 voxel_size = mesh_bounds.size().xyz / vec3(mesh.grid_linespace.grid_resolution);
vec3 step = sign(local_ray.direction);
vec3 origin = local_ray.origin + int(temp_tmin == temp_tmax) * temp_tmin * local_ray.direction;
vec3 step = sign(local_ray.direction);
vec3 delta = step / local_ray.direction * voxel_size;
vec3 position = (local_ray.origin - mesh_bounds.min.xyz) / voxel_size;
vec3 position = (origin - mesh_bounds.min.xyz) / voxel_size;
ivec3 index = clamp(ivec3(position), ivec3(0), mesh.grid_linespace.grid_resolution-1);
ivec3 totalStepSign = ivec3(greaterThan(step, ivec3(0)));
//bool x;
//int a = x + (1-2*x)*blub;
// x true -> x = 1, a = 1 - blub;
// x false -> x = 0, a = 0+0*b
// x false -> x = 0, a = 0 - (-1)*blub = blub
vec3 tnext = (totalStepSign + (1-2*totalStepSign) * (position - index)) * delta;
float temp_t_min = 0.f;
......@@ -108,14 +111,11 @@ 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 (step[axis] == 0 || (index[axis] < 0) || (index[axis] >= mesh.grid_linespace.grid_resolution[axis]))
if ((index[axis] < 0) || (index[axis] >= mesh.grid_linespace.grid_resolution[axis]))
{
break;
}
tnext[axis] += delta[axis];
// TODO: endless loop sometimes.
//break;
}
}
}
......
......@@ -96,7 +96,8 @@ 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 = 1;//1e-100;
float EPSILON = FLT_EPSILON;//1e-100;
float border_epsilon = 1e-6f;
vec3 e1, e2; //Edge1, Edge2
vec3 P, Q, T;
......@@ -128,7 +129,7 @@ bool intersectsTriangle(const in Ray ray, int triangle_index, const in Mesh 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);
......@@ -136,7 +137,7 @@ bool intersectsTriangle(const in Ray ray, int triangle_index, const in Mesh 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;
......@@ -205,7 +206,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;
float border_epsilon = 1e-6f;
vec3 e1, e2; //Edge1, Edge2
vec3 P, Q, T;
......@@ -249,7 +250,7 @@ bool intersectsTriangleLocal(const in Ray ray, int triangle_index, const in Mesh
t = dot(e2, Q) * inv_det;
if (t > border_epsilon) { //ray intersection
if (t > EPSILON) { //ray intersection
return true;
}
......
......@@ -164,8 +164,7 @@ void drawSceneWindow()
ImGui::EndSelectableTree();
ImGui::EndChild();
ImGui::Separator();
core::SceneNode* selected_node = reinterpret_cast<core::SceneNode*>(ImGui::GetSelectableTreeData("tree_scene_graph"));
if(selected_node)
if(auto selected_node = reinterpret_cast<core::SceneNode*>(ImGui::GetSelectableTreeData("tree_scene_graph")))
{
ImGui::BeginChild("Settings For Tree Node");
static int curr_settings_tab = 0;
......
......@@ -5,7 +5,10 @@
int main(int argc, char* argv[])
{
if (float f = 0; f < 210)
{
Log_Debug << f;
}
return 0;
}
\ No newline at end of file
......@@ -225,11 +225,13 @@ namespace math
Subdivision Bounds::computeSubdivision(unsigned max_subdivisions) const
{
const float padding = 1e-4f;
Subdivision subdivision;
const int largest_axis = largestAxis();
const glm::vec3 bounds_size = glm::max(glm::vec3(size().xyz), glm::vec3(1e-5f));
const glm::vec3 bounds_size = glm::max(glm::vec3(size().xyz), glm::vec3(padding));
const float largest_axis_value = glm::compMax(bounds_size);
const float longest_size = largest_axis_value / static_cast<float>(max_subdivisions) + 1e-5f;
const float longest_size = largest_axis_value / static_cast<float>(max_subdivisions) + padding;
subdivision.resolution = glm::ivec3(0);
subdivision.resolution[largest_axis] = max_subdivisions;
......
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