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

Brute-force grid linespace finished.

parent 5bb79eab
......@@ -4,7 +4,7 @@ Size=353,64
Collapsed=0
[Scene]
Pos=4,67
Pos=12,79
Size=352,837
Collapsed=0
......
<linespace version="1.0">
<item name="subdivisions" value="6"/>
<item name="subdivisions" value="12"/>
<item name="radial-subdivision" value="50"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -81,7 +81,7 @@ bool traverseBVH(const in Mesh mesh, const in Ray local_ray, const in bool use_f
nearest.mesh = mesh.id;
}
if (also_farthest && t > t_max) {
if (also_farthest && t > t_max && t < max_distance) {
t_max = t;
farthest.barycentric = vec2(u, v);
......
......@@ -147,7 +147,7 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
bool swapped = false;
uint line_id = lineIndex(loc, mesh, index, tmin, tmax, face_tmin, face_tmax, swapped);
Line line_near = mesh.linespaces[index].lines[line_id * 2];
Line line_far = mesh.linespaces[index].lines[line_id * 2 + 1];
......@@ -161,8 +161,7 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
nearer.mesh = mesh.id;
if(loc.intersectsTrianglePlane(near_data, mesh, t, nearer.barycentric.x, nearer.barycentric.y))
{
float nearest_distance = t;
if(nearest_distance > 0 && max_distance > nearest_distance && t < t_min){
if(t > 0 && t < max_distance && t < t_min){
hit = nearer;
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.
......@@ -178,9 +177,9 @@ bool traverseLineSpace(const in Mesh mesh, int index, const in Ray local_ray, co
nearer.mesh = mesh.id;
if(loc.intersectsTrianglePlane(near_data, mesh, t, nearer.barycentric.x, nearer.barycentric.y))
{
float farthest_distance = t;
//float farthest_distance = t;
if(farthest_distance > 0 && max_distance > farthest_distance && t < t_min){
if(t > 0 && t < max_distance && t < t_min){
hit = nearer;
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.
......
......@@ -18,6 +18,7 @@ uniform uint u_begin_face;
uniform uint u_end_face;
uniform uint u_begin_count;
uniform uint u_end_count;
uniform uint u_offset;
// General inputs
uniform uvec3 u_subdivisions = uvec3(1, 1, 1);
......@@ -51,70 +52,9 @@ void main()
generate(gid);
}
uint faceRangeIndex(uint in_face, uint out_face)
{
return uint((((-0.5f * float(in_face)) + 4.5f) * float(in_face))) - 1u + out_face;
}
uint linesBetweenFaces(uint inface, uint outface)
{
uint axis_in_width = u_subdivisions[face_width_axis[inface % 3]];
uint axis_in_height = u_subdivisions[face_height_axis[inface % 3]];
uint axis_out_width = u_subdivisions[face_width_axis[outface % 3]];
uint axis_out_height = u_subdivisions[face_height_axis[outface % 3]];
return axis_in_width * axis_in_height * axis_out_width * axis_out_height;
}
uint offsetOf(uint inface, uint outface)
{
uint offset = 0;
// Caution! Fallthrough switch. Seemed to perform much better than a for-loop, usually even being faster than precalculated offsets in release builds.
switch (faceRangeIndex(inface, outface))
{
case 15:
offset += linesBetweenFaces(4, 5);
case 14:
offset += linesBetweenFaces(3, 5);
case 13:
offset += linesBetweenFaces(3, 4);
case 12:
offset += linesBetweenFaces(2, 5);
case 11:
offset += linesBetweenFaces(2, 4);
case 10:
offset += linesBetweenFaces(2, 3);
case 9:
offset += linesBetweenFaces(1, 5);
case 8:
offset += linesBetweenFaces(1, 4);
case 7:
offset += linesBetweenFaces(1, 3);
case 6:
offset += linesBetweenFaces(1, 2);
case 5:
offset += linesBetweenFaces(0, 5);
case 4:
offset += linesBetweenFaces(0, 4);
case 3:
offset += linesBetweenFaces(0, 3);
case 2:
offset += linesBetweenFaces(0, 2);
case 1:
offset += linesBetweenFaces(0, 1);
case 0:
default:
break;
}
return offset;
}
uint lineIndex(const in Patch begin, const in Patch end)
{
uint offset = offsetOf(begin.face, end.face);
uint offset = u_offset;
uint start_height = uint(u_subdivisions[face_height_axis[begin.face%3]]);
uint end_width = uint(u_subdivisions[face_width_axis[end.face%3]]);
......@@ -186,14 +126,14 @@ void generate(uint gid)
nearest.mesh = nearest.triangle = -1;
farthest.mesh = farthest.triangle = -1;
nearest.barycentric = vec2(-1);
farthest.barycentric = vec2(-1);
nearest.invalidate();
farthest.invalidate();
line_front.triangle = -1;
line_back.triangle = -1;
float t_min = FLT_MAX;
u_mesh.traverseBVH(ray, false, FLT_MAX, true, nearest, farthest, t_min);
float t_min = distance(center_end, center_begin) + 2*ray_bias;
u_mesh.traverseBVH(ray, false, t_min, true, nearest, farthest, t_min);
if(nearest.valid())
{
......
......@@ -233,7 +233,7 @@ void main()
// 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)
//if(false)
for (bounce.count = 1; bounce.shade() && bounce.count <= u_render_config.num_bounces; ++bounce.count) {
bounce.trace();
}
......
......@@ -192,6 +192,7 @@ namespace glare::raytrace
construction_shader->uniform("u_end_face", static_cast<unsigned>(end_face));
construction_shader->uniform("u_begin_count", begin_count);
construction_shader->uniform("u_end_count", end_count);
construction_shader->uniform("u_offset", offsetOf(begin_face, end_face));
construction_shader->dispatch1D(begin_count * end_count, 1024);
}
......
......@@ -57,7 +57,7 @@ namespace glare::raytrace
m_vertex_buffer->makeResident(gl::Access::eReadOnly);
m_triangle_buffer->makeResident(gl::Access::eReadOnly);
int subdiv_grid = 2;
int subdiv_grid = 8;
auto subdiv = m_bounds.computeSubdivision(subdiv_grid);
int count = subdiv.resolution.x * subdiv.resolution.y * subdiv.resolution.z;
......
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