Commit 647c93c8 authored by Johannes Braun's avatar Johannes Braun
Browse files

Starting uniform grid implementation of hierarchical LS

parent 2240be3b
......@@ -4,7 +4,7 @@ Size=353,64
Collapsed=0
[Scene]
Pos=-3,66
Pos=-2,68
Size=352,837
Collapsed=0
......
......@@ -70,9 +70,9 @@ uint offsetOf(const in Linespace linespace, uint inface, uint outface)
uvec2 getPatch(const in Mesh mesh, vec3 at_position, int axis, int face){
bool flip_indices = face != axis;
return !flip_indices
? uvec2(at_position[face_width_axis[axis]] / mesh.linespace.patch_size[face_width_axis[axis]], at_position[face_height_axis[axis]] / mesh.linespace.patch_size[face_height_axis[axis]])
: uvec2(mesh.linespace.resolution[face_width_axis[axis]], mesh.linespace.resolution[face_height_axis[axis]]) -
uvec2(at_position[face_width_axis[axis]] / mesh.linespace.patch_size[face_width_axis[axis]], at_position[face_height_axis[axis]] / mesh.linespace.patch_size[face_height_axis[axis]])- 1;
? uvec2(at_position[face_width_axis[axis]] / mesh.linespaces[0].patch_size[face_width_axis[axis]], at_position[face_height_axis[axis]] / mesh.linespaces[0].patch_size[face_height_axis[axis]])
: uvec2(mesh.linespaces[0].resolution[face_width_axis[axis]], mesh.linespaces[0].resolution[face_height_axis[axis]]) -
uvec2(at_position[face_width_axis[axis]] / mesh.linespaces[0].patch_size[face_width_axis[axis]], at_position[face_height_axis[axis]] / mesh.linespaces[0].patch_size[face_height_axis[axis]])- 1;
}
struct PatchInfo
......@@ -86,7 +86,7 @@ struct PatchInfo
uint lineIndex(const in Ray ray, const in Mesh mesh, float tmin, float tmax, int face_in, int face_out, inout bool direction_swapped)
{
Linespace linespace = mesh.linespace;
Linespace linespace = mesh.linespaces[0];
PatchInfo entry_info;
PatchInfo exit_info;
......@@ -142,15 +142,15 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
Ray offset_ray = local_ray;
offset_ray.origin += local_ray.direction * offset;
if(!offset_ray.intersectsBounds(mesh.linespace.bounds, tmin, tmax, face_tmin, face_tmax) || t_min <= tmin-offset || tmin-offset > max_distance)
if(!offset_ray.intersectsBounds(mesh.linespaces[0].bounds, tmin, tmax, face_tmin, face_tmax) || t_min <= tmin-offset || tmin-offset > max_distance)
{
return false;
}
bool swapped = false;
uint line_id = lineIndex(offset_ray, mesh, tmin, tmax, face_tmin, face_tmax, swapped);
Line line_near = mesh.linespace.lines[line_id * 2];
Line line_far = mesh.linespace.lines[line_id * 2 + 1];
Line line_near = mesh.linespaces[0].lines[line_id * 2];
Line line_far = mesh.linespaces[0].lines[line_id * 2 + 1];
int near_data = swapped ? line_far.triangle : line_near.triangle;
Hit nearer;
......
......@@ -21,11 +21,13 @@ struct Mesh
Vertex* vertices;
Triangle* triangles;
BVHNode* nodes;
Linespace* linespaces;
uint material;
uint id;
Linespace linespace;
int p[2];
//Linespace linespace;
mat4 transformation;
mat4 inverse_transformation;
......
#include <raytrace/data/grid_linespace.h>
#include <core/numeric/geometry.h>
int main(int argc, char* argv[])
{
math::Bounds bounds{ {0, 0, 0, 1}, {10, 10, 10, 1} };
glare::raytrace::compute(bounds, 4, 10);
return 0;
}
\ No newline at end of file
......@@ -28,7 +28,7 @@ namespace glare::core
return gl::isNamedBufferResident(m_handle);
}
uint64_t Buffer::makeResident(gl::Access access)
uint64_t Buffer::makeResident(gl::Access access) const
{
if (!resident())
{
......
......@@ -44,7 +44,7 @@ namespace glare::core
/**
* \brief Makes the buffer resident only if it's not already. Returns the resulting gpu address.
*/
uint64_t makeResident(gl::Access access);
uint64_t makeResident(gl::Access access) const;
void makeNonResident() const;
bool resident() const;
......@@ -105,7 +105,7 @@ namespace glare::core
protected:
gl::handle::buffer m_handle;
uint64_t m_resident_address = 0;
mutable uint64_t m_resident_address = 0;
};
// -------------------------------------------------------------------------------------------------------------------------
......
#ifndef INCLUDE_GRID_LINESPACE_H
#define INCLUDE_GRID_LINESPACE_H
#include <core/numeric/geometry.h>
#include "linespace.h"
namespace glare::raytrace
{
inline int patchCount(const math::Subdivision& subdivision, Face face)
{
return subdivision.resolution[FaceAxises::get(face).horizontal] * subdivision.resolution[FaceAxises::get(face).vertical];
}
inline int lineCount(const math::Subdivision& subdivision)
{
const unsigned patches_x = patchCount(subdivision, Face::ePosX);
const unsigned patches_y = patchCount(subdivision, Face::ePosY);
const unsigned patches_z = patchCount(subdivision, Face::ePosZ);
return 2 * (2 * patches_x * (patches_y + patches_z) + patches_x * patches_x
+ 2 * patches_y * (patches_x + patches_z) + patches_y * patches_y
+ 2 * patches_z * (patches_x + patches_y) + patches_z * patches_z);
}
inline int compute(math::Bounds bounds, int res_voxels, int res_linespace)
{
auto subdiv = bounds.computeSubdivision(res_voxels);
math::Bounds sub_bounds_sample{ {0,0,0,1}, glm::vec4(subdiv.size, 1) };
auto subsubdiv = sub_bounds_sample.computeSubdivision(res_linespace);
glm::vec3 effective_resolution = subdiv.resolution * subsubdiv.resolution;
int count = subdiv.resolution.x * subdiv.resolution.y * subdiv.resolution.z * lineCount(subsubdiv);
int memory = count * sizeof(Line);
return 0;
}
}
#endif // !INCLUDE_GRID_LINESPACE_H
......@@ -56,11 +56,14 @@ namespace glare::raytrace
m_vertex_buffer->makeResident(gl::Access::eReadOnly);
m_triangle_buffer->makeResident(gl::Access::eReadOnly);
if (!m_linespace)
m_linespace = std::make_shared<std::remove_pointer_t<decltype(m_linespace.get())>>();
m_linespaces.resize(1, std::make_shared<Linespace>());
m_linespace->generate(*this, files::asset("preferences/linespace_default.xml"));
m_linespaces[0]->generate(*this, files::asset("preferences/linespace_default.xml"));
m_linespace_data.resize(1);
m_linespace_data[0] = m_linespaces[0]->data();
m_linespace_buffer.upload(m_linespace_data, gl::BufferUsage::eDynamicDraw);
}
int64_t LocalCollector::meshID() const
......@@ -99,7 +102,10 @@ namespace glare::raytrace
mesh.vertex_buffer_ptr = m_vertex_buffer->residentAddress();
mesh.triangle_buffer_ptr = m_triangle_buffer->residentAddress();
if (m_linespace) mesh.linespace = m_linespace->data();
if(!m_linespaces.empty() && !m_linespace_data.empty())
mesh.linespace_buffer_ptr = m_linespace_buffer.makeResident(gl::Access::eReadOnly);
//if (m_linespace) mesh.linespace = m_linespace->data();
mesh.material = material_index;
return mesh;
......
......@@ -35,13 +35,10 @@ namespace glare::raytrace
/**
* @brief Sets the world transform of this LocalCollector.
*/
//void updateTransform(const core::MeshDrawable &mesh);
const std::vector<math::Vertex>& vertices() const;
const std::vector<TriangleIDs>& triangles() const;
const LocalBVH& bvh() const;
const math::Bounds& bounds() const;
//const glm::mat4& transform() const;
Mesh makeMesh(glm::uint material_index, const glm::mat4& transform) const;
......@@ -58,13 +55,15 @@ namespace glare::raytrace
//glm::mat4 m_transform;
std::shared_ptr<LocalBVH> m_bvh;
std::shared_ptr<Linespace> m_linespace;
std::vector<std::shared_ptr<Linespace>> m_linespaces;
std::vector<LinespaceData> m_linespace_data;
std::vector<math::Vertex> m_vertices;
std::vector<TriangleIDs> m_triangles;
std::shared_ptr<core::Buffer> m_triangle_buffer;
std::shared_ptr<core::Buffer> m_vertex_buffer;
core::Buffer m_linespace_buffer;
};
struct InstancedCollector
......
......@@ -115,11 +115,14 @@ namespace glare::raytrace
uint64_t vertex_buffer_ptr;
uint64_t triangle_buffer_ptr;
uint64_t datastructure_buffer_ptr;
uint64_t linespace_buffer_ptr;
glm::uint material;
glm::uint id;
LinespaceData linespace;
int p[2];
//LinespaceData linespace;
glm::mat4 transformation;
glm::mat4 inverse_transformation;
......
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