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

LS grid does not work particularily correctly yet.

parent 205b3018
...@@ -4,7 +4,7 @@ Size=353,64 ...@@ -4,7 +4,7 @@ Size=353,64
Collapsed=0 Collapsed=0
[Scene] [Scene]
Pos=-4,66 Pos=-5,66
Size=352,837 Size=352,837
Collapsed=0 Collapsed=0
......
<linespace version="1.0"> <linespace version="1.0">
<item name="subdivisions" value="25"/> <item name="subdivisions" value="6"/>
<item name="radial-subdivision" value="50"/> <item name="radial-subdivision" value="50"/>
<item name="generator" value="gpu"/> <item name="generator" value="gpu"/>
</linespace> </linespace>
...@@ -134,10 +134,13 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co ...@@ -134,10 +134,13 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
int face_tmin; int face_tmin;
int face_tmax; int face_tmax;
// LS can be empty.
if (mesh.linespaces[index].line_count == 0) return false;
Ray loc = local_ray; Ray loc = local_ray;
loc.origin += 0.05f * loc.direction; loc.origin += 0.05f * loc.direction;
float offset = -1.f;//compMin(mesh.linespace.patch_size); float offset = 0;//-1.f;//compMin(mesh.linespace.patch_size);
Ray offset_ray = local_ray; Ray offset_ray = local_ray;
offset_ray.origin += local_ray.direction * offset; offset_ray.origin += local_ray.direction * offset;
...@@ -163,7 +166,7 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co ...@@ -163,7 +166,7 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
if(loc.intersectsTrianglePlane(near_data, mesh, t, nearer.barycentric.x, nearer.barycentric.y)) if(loc.intersectsTrianglePlane(near_data, mesh, t, nearer.barycentric.x, nearer.barycentric.y))
{ {
float nearest_distance = t-offset; float nearest_distance = t-offset;
if(nearest_distance > 0 && max_distance > nearest_distance){ if(nearest_distance > 0 && max_distance > nearest_distance && t < t_min){
hit = nearer; hit = nearer;
t_min = t; t_min = t;
//Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step. //Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step.
...@@ -181,7 +184,7 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co ...@@ -181,7 +184,7 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
{ {
float farthest_distance = t-offset; float farthest_distance = t-offset;
if(farthest_distance > 0 && max_distance > farthest_distance){ if(farthest_distance > 0 && max_distance > farthest_distance && t < t_min){
hit = nearer; hit = nearer;
t_min = t; t_min = t;
//Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step. //Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step.
......
...@@ -31,5 +31,5 @@ void main() ...@@ -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); 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].ray = u_camera.getRayFromPixel(vec2(gl_GlobalInvocationID.xy), random, vec2(target_size));
traces_data[id].hit.invalidate(); 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);
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <core/Time.h> #include <core/Time.h>
#include <core/res/res.h> #include <core/res/res.h>
#include "pugixml/pugixml.hpp" #include "pugixml/pugixml.hpp"
#include <raytrace/intersect.h>
namespace glare::raytrace namespace glare::raytrace
{ {
...@@ -44,10 +45,36 @@ namespace glare::raytrace ...@@ -44,10 +45,36 @@ namespace glare::raytrace
{ {
Log_Info << "Building Line Space for collector id " << collector.id() << "..."; Log_Info << "Building Line Space for collector id " << collector.id() << "...";
core::ClockGL::instance().start(); core::ClockGL::instance().start();
m_bounds = collector.bounds(); m_bounds = collector.bounds();
auto grid = m_bounds.computeSubdivision(uniform_grid_subdivision);
int grid_index = uniform_grid_index;
glm::vec3 grid_index_3d;
grid_index_3d.x = 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;
math::Bounds replacement;
replacement.min = m_bounds.min + glm::vec4(grid_index_3d * grid.size, 0);
replacement.max = replacement.min + glm::vec4(grid.size, 0);
m_bounds = replacement;
m_subdivision = m_bounds.subdivide(max_subdivisions); m_subdivision = m_bounds.subdivide(max_subdivisions);
m_filled = collector.triangles().cend() != std::find_if(collector.triangles().cbegin(), collector.triangles().cend(), [this, &collector](const TriangleIDs& tri)
{
math::Triangle triangle;
triangle.a = collector.vertices()[tri.indices[0]].position;
triangle.b = collector.vertices()[tri.indices[1]].position;
triangle.c = collector.vertices()[tri.indices[2]].position;
return intersect::intersects(triangle, m_bounds);
});
// if LS does not contain any triangles, don't try to generate.
if (!m_filled)
return;
switch (generator) switch (generator)
{ {
default: default:
...@@ -269,8 +296,8 @@ namespace glare::raytrace ...@@ -269,8 +296,8 @@ namespace glare::raytrace
data.bounds = m_bounds; data.bounds = m_bounds;
data.patch_size = m_subdivision.size; data.patch_size = m_subdivision.size;
data.resolution = m_subdivision.resolution; data.resolution = m_subdivision.resolution;
data.lines = m_line_buffer.residentAddress(); data.lines = m_filled ? m_line_buffer.residentAddress() : 0;
data.line_count = lineCount(); data.line_count = m_filled ? lineCount() : 0;
return data; return data;
} }
...@@ -288,4 +315,4 @@ namespace glare::raytrace ...@@ -288,4 +315,4 @@ namespace glare::raytrace
{ {
return m_subdivision; return m_subdivision;
} }
} }
\ No newline at end of file
...@@ -117,6 +117,7 @@ namespace glare::raytrace ...@@ -117,6 +117,7 @@ namespace glare::raytrace
math::Bounds m_bounds; math::Bounds m_bounds;
math::Subdivision m_subdivision; math::Subdivision m_subdivision;
core::Buffer m_line_buffer; core::Buffer m_line_buffer;
bool m_filled = false;
//Collection of startpatch-endpatch configurations for merging two loops //Collection of startpatch-endpatch configurations for merging two loops
//in the generation process into one parallel loop. //in the generation process into one parallel loop.
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <raytrace/data/linespace.h> #include <raytrace/data/linespace.h>
#include <core/rendering/batch_renderer.h> #include <core/rendering/batch_renderer.h>
#include <pugixml/pugixml.hpp>
namespace glare::raytrace namespace glare::raytrace
{ {
...@@ -56,11 +57,32 @@ namespace glare::raytrace ...@@ -56,11 +57,32 @@ namespace glare::raytrace
m_vertex_buffer->makeResident(gl::Access::eReadOnly); m_vertex_buffer->makeResident(gl::Access::eReadOnly);
m_triangle_buffer->makeResident(gl::Access::eReadOnly); m_triangle_buffer->makeResident(gl::Access::eReadOnly);
m_linespaces.resize(1, std::make_shared<Linespace>()); int subdiv_grid = 5;
m_linespaces[0]->generate(*this, files::asset("preferences/linespace_default.xml"));
m_linespace_data.resize(1); auto subdiv = m_bounds.computeSubdivision(subdiv_grid);
m_linespace_data[0] = m_linespaces[0]->data(); int count = subdiv.resolution.x * subdiv.resolution.y * subdiv.resolution.z;
pugi::xml_document doc;
doc.load_file(files::asset("preferences/linespace_default.xml").c_str());
const auto& linespace_tag = doc.child("linespace");
const int max_subdivisions = linespace_tag.find_child_by_attribute("item", "name", "subdivisions").attribute("value").as_int(16);
const std::string gen = linespace_tag.find_child_by_attribute("item", "name", "generator").attribute("value").as_string("cpu");
const Platform generator = gen == "gpu" ? Platform::eGPU : Platform::eCPU;
m_linespaces.resize(count);
for (int i = 0; i < count; ++i)
{
m_linespaces[i] = std::make_shared<Linespace>();
m_linespaces[i]->generate(*this, subdiv_grid, i, max_subdivisions, generator);
}
m_linespace_data.resize(count);
for (int i = 0; i < count; ++i)
{
m_linespace_data[i] = m_linespaces[i]->data();
}
m_linespace_buffer.upload(m_linespace_data, gl::BufferUsage::eDynamicDraw); m_linespace_buffer.upload(m_linespace_data, gl::BufferUsage::eDynamicDraw);
} }
......
Supports Markdown
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