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

Added non-working grid traversal.

parent dd60f32b
......@@ -4,7 +4,7 @@ Size=353,64
Collapsed=0
[Scene]
Pos=12,79
Pos=14,79
Size=352,837
Collapsed=0
......
......@@ -47,11 +47,67 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
}
else
{
for(int ls = 0; ls < mesh.num_linespaces; ++ls)
Ray local_ray = ray.makeRelative(mesh);
/*
float local_tmin, local_tmax;
Bounds mesh_bounds = mesh.nodes[0].bounds;
if(local_ray.intersectsBounds(mesh_bounds, local_tmin, local_tmax, t_min))
{
vec3 start_position_on_box = local_ray.origin + local_tmin * local_ray.direction;
vec3 start_position_relative = start_position_on_box - mesh_bounds.min.xyz;
start_position_relative /= mesh.grid_resolution;
ivec3 start_voxel = clamp(ivec3(start_position_relative), ivec3(0), mesh.grid_resolution-1);
vec3 end_position_on_box = local_ray.origin + local_tmax * local_ray.direction;
vec3 end_position_relative = end_position_on_box - mesh_bounds.min.xyz;
end_position_relative /= mesh.grid_resolution;
ivec3 end_voxel = clamp(ivec3(end_position_relative), ivec3(0), mesh.grid_resolution-1);
vec3 voxel_size = mesh_bounds / vec3(mesh.grid_resolution);
ivec3 direction_sign = sign(local_ray.direction);
float delta = direction_sign / local_ray.direction * voxel_size;
vec3 tnext = offset * delta;
ivec3 offset = ivec3(0);
for(; start_voxel != end_voxel; start_voxel = clamp(start_voxel + offset, ivec3(0), mesh.grid_resolution-1))
{
vec3 voxel_direction = normalize(vec3(end_voxel - start_voxel));
vec3 difference = abs(voxel_direction - local_ray.direction);
int axis = 0;
for(int ax=1; ax<3; ++ax)
{
if(difference[axis] < difference[ax])
axis = ax;
}
offset = ivec3(0);
offset[axis] = 1;
if(voxel_direction[axis] < 0)
offset[axis] = -1;
int ls_index = start_voxel.x + start_voxel.y * mesh.grid_resolution.y + start_voxel.z * mesh.grid_resolution.y * mesh.grid_resolution.z;
Hit bla;
float mint = t_min;
if(mesh.traverseLineSpace(0, local_ray, use_first, current_t, bla, mint) && mint < t_min){
hit = bla;
t_min = mint;
hit_triangle = true;
if (use_first)
{
return true;
}
}
start_voxel = vec3(start_voxel) + offset * direction_sign;
}
*/
int ls_index = 0;//start_voxel.x + start_voxel.y * mesh.grid_resolution.y + start_voxel.z * mesh.grid_resolution.y * mesh.grid_resolution.z;
Hit bla;
float mint = t_min;
if(mesh.traverseLineSpace(ls, ray.makeRelative(mesh), use_first, current_t, bla, mint) && mint < t_min){
if(mesh.traverseLineSpace(ls_index, local_ray, use_first, current_t, bla, mint) && mint < t_min){
hit = bla;
t_min = mint;
hit_triangle = true;
......@@ -60,7 +116,22 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
return true;
}
}
}
//}
// for(int ls = 0; ls < mesh.num_linespaces; ++ls)
// {
// Hit bla;
// float mint = t_min;
// if(mesh.traverseLineSpace(ls, local_ray, use_first, current_t, bla, mint) && mint < t_min){
// hit = bla;
// t_min = mint;
// hit_triangle = true;
// if (use_first)
// {
// return true;
// }
// }
// }
}
}
......@@ -144,7 +215,11 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
{
for(int ls = 0; ls < mesh.num_linespaces; ++ls)
{
if(mesh.traverseLineSpace(ls, ray.makeRelative(mesh), use_first, current_t, hit, t_min)){
Hit bla;
float mint = t_min;
if(mesh.traverseLineSpace(ls, ray.makeRelative(mesh), use_first, current_t, bla, mint) && mint < t_min){
hit = bla;
t_min = mint;
hit_triangle = true;
if (use_first)
{
......
......@@ -228,12 +228,11 @@ void main()
bounce.bounce_amount = int[num_effects](0,0,0,0);
bounce.color = vec3(0);
bounce.radiance = vec3(1);
bounce.shade();
// Nifty for-loop trick. :P
// Will execute the bounce.shade() method at the very beginning (to shade the primary ray) and then
// continue with first-trace-then-shade until either shade returns false (not hitting something or constribution too low)
// or we exceed the global bounce limit.
//if(false)
for (bounce.count = 1; bounce.shade() && bounce.count <= u_render_config.num_bounces; ++bounce.count) {
bounce.trace();
}
......
......@@ -23,11 +23,12 @@ struct Mesh
BVHNode* nodes;
Linespace* linespaces;
ivec3 grid_resolution;
int num_linespaces;
uint material;
uint id;
int p;
int p[2];
mat4 transformation;
mat4 inverse_transformation;
......
......@@ -56,6 +56,26 @@ bool intersectsBounds(const in Ray ray, const in Bounds bounds, inout float tmin
return tmax >= 0 && tmin <= tmax;
}
bool intersectsBounds(const in Ray ray, const in Bounds bounds, inout float tmin, inout float tmax, float max_t)
{
vec3 dirfrac = 1.0f / ray.direction.xyz;
//intersections with box planes parallel to x, y, z axis
float t1 = (bounds.min.x - ray.origin.x)*dirfrac.x;
float t2 = (bounds.max.x - ray.origin.x)*dirfrac.x;
float t3 = (bounds.min.y - ray.origin.y)*dirfrac.y;
float t4 = (bounds.max.y - ray.origin.y)*dirfrac.y;
float t5 = (bounds.min.z - ray.origin.z)*dirfrac.z;
float t6 = (bounds.max.z - ray.origin.z)*dirfrac.z;
tmin = max(max(min(t1, t2), min(t3, t4)), min(t5, t6));
tmax = min(max_t, min(min(max(t1, t2), max(t3, t4)), max(t5, t6)));
return tmax >= 0 && tmin <= tmax;
}
bool intersectsBounds(const in Ray ray, const in Bounds bounds, const in float max_t)
{
vec3 dirfrac = 1.0f / ray.direction.xyz;
......
......@@ -50,10 +50,10 @@ namespace glare::raytrace
int grid_index = uniform_grid_index;
glm::vec3 grid_index_3d;
grid_index_3d.x = grid_index % grid.resolution.x;
grid_index_3d.x = static_cast<float>(grid_index % grid.resolution.x);
grid_index /= grid.resolution.x;
grid_index_3d.y = grid_index % grid.resolution.y;
grid_index_3d.z = grid_index / grid.resolution.y;
grid_index_3d.y = static_cast<float>(grid_index % grid.resolution.y);
grid_index_3d.z = static_cast<float>(grid_index / grid.resolution.y);
math::Bounds replacement;
replacement.min = m_bounds.min + glm::vec4(grid_index_3d * grid.size, 0);
......
......@@ -57,10 +57,11 @@ namespace glare::raytrace
m_vertex_buffer->makeResident(gl::Access::eReadOnly);
m_triangle_buffer->makeResident(gl::Access::eReadOnly);
int subdiv_grid = 8;
int subdiv_grid = 1;
auto subdiv = m_bounds.computeSubdivision(subdiv_grid);
int count = subdiv.resolution.x * subdiv.resolution.y * subdiv.resolution.z;
m_grid_resolution = glm::ivec3(subdiv.resolution);
int count = m_grid_resolution.x * m_grid_resolution.y * m_grid_resolution.z;
pugi::xml_document doc;
doc.load_file(files::asset("preferences/linespace_default.xml").c_str());
......@@ -127,10 +128,9 @@ namespace glare::raytrace
{
mesh.linespaces = static_cast<int>(m_linespace_data.size());
mesh.linespace_buffer_ptr = m_linespace_buffer.makeResident(gl::Access::eReadOnly);
mesh.grid_resolution = m_grid_resolution;
}
//if (m_linespace) mesh.linespace = m_linespace->data();
mesh.material = material_index;
return mesh;
}
......
......@@ -55,6 +55,7 @@ namespace glare::raytrace
//glm::mat4 m_transform;
std::shared_ptr<LocalBVH> m_bvh;
glm::ivec3 m_grid_resolution;
std::vector<std::shared_ptr<Linespace>> m_linespaces;
std::vector<LinespaceData> m_linespace_data;
......
......@@ -4,7 +4,7 @@
#include <core/objects/material.h>
#include <core/objects/camera.h>
#include <core/objects/light.h>
#include <core/numeric/geometry.h>
#include <core/numeric/geometry.h>
#include <core/base/program.h>
namespace glare::raytrace
......@@ -117,11 +117,12 @@ namespace glare::raytrace
uint64_t datastructure_buffer_ptr;
uint64_t linespace_buffer_ptr;
glm::ivec3 grid_resolution;
int linespaces;
glm::uint material;
glm::uint id;
int p;
int p[2];
//LinespaceData linespace;
......
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