Commit efb64485 authored by unknown's avatar unknown
Browse files

Removed redundant files

parent 9eb75598
<linespace version="1.0">
<item name="subdivisions" value="20"/>
<item name="radial-subdivision" value="30"/>
<item name="subdivisions" value="50"/>
<item name="radial-subdivision" value="50"/>
<item name="generator" value="gpu"/>
</linespace>
#ifdef __GL_BVH
#define __GL_BVH
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/intersections.glsl>
#include <raytracer/std.glsl>
struct BVHNode
{
Bounds bounds;
uint type;
uint left_idx;
uint right_idx;
uint parent;
};
STD_BUFFER_R bvh_node_buffer
{
BVHNode b_bvh_nodes[];
};
//"Stackless" BVH-Traversal.
// See https://pdfs.semanticscholar.org/7e81/6b82fb92df08d7bc0d9805f8988754e0d8c1.pdf
bool traverse(const in Ray ray, inout Hit hit, const in bool nearest_only, const in float max_distance)
{
float t = 0;
float t_min = FLT_MAX;
// Check once the AABB for the whole scene
bool hit_scene = intersectsRayBounds(ray, b_bvh_nodes[0].bounds);
bool hit_triangle = false;
int current_node = 0;
int bitstack = 0;
//if (hit_scene){
while (hit_scene)
{
if (b_bvh_nodes[current_node].type == 0) //Inner node.
{
int id_left = int(b_bvh_nodes[current_node].left_idx);
bool hit_left = intersectsRayBounds(ray, b_bvh_nodes[id_left].bounds);
int id_right = int(b_bvh_nodes[current_node].right_idx);
bool hit_right = intersectsRayBounds(ray, b_bvh_nodes[id_right].bounds);
//both hit
if (hit_left && hit_right)
{
// shift bitstack and mark as branched, so we can use the marker
// when backtracking to stop here and use the right child.
bitstack = bitstack << 1;
current_node = id_left;
bitstack = bitstack | 1;
continue;
}
// only left hit
else if (hit_left && !hit_right)
{
// Not branching here, the other sibling-check won't be needed here.
bitstack = bitstack << 1;
current_node = id_left;
continue;
}
// only right hit
else if (!hit_left && hit_right)
{
// Not branching here, the other sibling-check won't be needed here.
bitstack = bitstack << 1;
current_node = id_right;
continue;
}
}
else
{
//Is leaf
// intersect ray with primitives.
//shorten ray if closer intersection found.
//intersect triangles
Triangle tri;
int start = int(b_bvh_nodes[current_node].left_idx);
int end = int(b_bvh_nodes[current_node].right_idx);
float u, v;
for (int i = start; i <= end; i++)
{
if (intersectsRayTriangle(ray, b_triangles[i], t, u, v))
{
if (t < t_min && t < max_distance) //test for ray_length
{
t_min = t;
hit_triangle = true;
//TODO: Hitparameter must be filled with information according to the ray-flag information
if (nearest_only)
{
return true;
}
hit.barycentric = vec3(u, v, 1 - u - v);
hit.triangle = i;
}
}
}
}
//Backtrace on bitstack until we find a branching point (where bit value is 1)
while ((bitstack & 1) == 0)
{
//Empty bitstack
if (bitstack == 0)
{
return hit_triangle;
}
current_node = int(b_bvh_nodes[current_node].parent);
bitstack = bitstack >> 1;
}
//Use other (right) sibling from the left child of the branched tree node.
current_node = int(b_bvh_nodes[b_bvh_nodes[current_node].parent].right_idx);
bitstack = bitstack ^ 1;
}
return hit_triangle;
}
bool bvh__nearestIntersection(const in Ray ray, inout Hit hit)
{
return traverse(ray, hit, false, FLT_MAX);
}
bool bvh__intersectsAny(const in Ray ray, const in float max_distance)
{
Hit unused_hit;
return traverse(ray, unused_hit, true, max_distance);
}
#endif //__GL_BVH
......@@ -10,13 +10,16 @@
layout(local_size_variable) in;
// Special implementation inputs
uniform uint u_face;
uniform uint u_lines_per_patch;
uniform uint u_radial_subdivision;
// General inputs
uniform uvec3 u_subdivisions = uvec3(1, 1, 1);
uniform float u_subdivisions_size;
uniform float ray_bias;
uniform Bounds u_bounds;
uniform uvec3 u_subdivisions;
uniform float u_subdivisions_size;
uniform Mesh u_mesh;
const uint face_width_axis[3] = {2, 2, 0};
......
......@@ -10,19 +10,22 @@
layout(local_size_variable) in;
uniform uvec3 u_resolution = uvec3(1, 1, 1);
uniform float u_resolution_size;
// Special implementation inputs
uniform uint u_begin_face;
uniform uint u_end_face;
uniform uint u_begin_count;
uniform uint u_end_count;
uniform uint u_offsets[15];
// General inputs
uniform uvec3 u_subdivisions = uvec3(1, 1, 1);
uniform float u_subdivisions_size;
uniform float ray_bias;
uniform Bounds u_bounds;
uniform Mesh u_mesh;
const uint c_face_width_axises[3] = {2, 2, 0};
const uint c_face_height_axises[3] = {1, 0, 1};
uniform uint u_offsets[15];
const uint face_width_axis[3] = {2, 2, 0};
const uint face_height_axis[3] = {1, 0, 1};
STD_BUFFER line_buffer
{
......@@ -59,9 +62,9 @@ uint lineIndex(const in Patch begin, const in Patch end)
uint range_section = faceRangeIndex(begin.face, end.face);
uint offset = u_offsets[range_section];
uint start_height = uint(u_resolution[c_face_height_axises[begin.face%3]]);
uint end_width = uint(u_resolution[c_face_width_axises[end.face%3]]);
uint end_height = uint(u_resolution[c_face_height_axises[end.face%3]]);
uint start_height = uint(u_subdivisions[face_height_axis[begin.face%3]]);
uint end_width = uint(u_subdivisions[face_width_axis[end.face%3]]);
uint end_height = uint(u_subdivisions[face_height_axis[end.face%3]]);
uint start_id = (begin.index_vertical + begin.index_horizontal * start_height) * end_width * end_height;
uint end_id = (end.index_vertical + end.index_horizontal * end_height);
......@@ -78,16 +81,16 @@ vec3 patchCenter(const in Patch p)
vec3 position;
position[face_index % 3] = u_bounds.min[face_index % 3] + max_factor*u_bounds.size()[face_index % 3];
uint axis_width = c_face_width_axises[face_index % 3];
uint axis_height = c_face_height_axises[face_index % 3];
uint axis_width = face_width_axis[face_index % 3];
uint axis_height = face_height_axis[face_index % 3];
if (p.face < 3) {
position[axis_width] = u_bounds.min[axis_width] + p.index_horizontal * u_resolution_size + u_resolution_size / 2;
position[axis_height] = u_bounds.min[axis_height] + p.index_vertical * u_resolution_size + u_resolution_size / 2;
position[axis_width] = u_bounds.min[axis_width] + p.index_horizontal * u_subdivisions_size + u_subdivisions_size / 2;
position[axis_height] = u_bounds.min[axis_height] + p.index_vertical * u_subdivisions_size + u_subdivisions_size / 2;
}
else {
position[axis_width] = u_bounds.max[axis_width] - (p.index_horizontal * u_resolution_size + u_resolution_size / 2);
position[axis_height] = u_bounds.max[axis_height] - (p.index_vertical * u_resolution_size + u_resolution_size / 2);
position[axis_width] = u_bounds.max[axis_width] - (p.index_horizontal * u_subdivisions_size + u_subdivisions_size / 2);
position[axis_height] = u_bounds.max[axis_height] - (p.index_vertical * u_subdivisions_size + u_subdivisions_size / 2);
}
return position;
......@@ -103,11 +106,11 @@ void generate(uint gid)
const uint begin_id = uint(gid) / u_end_count;
const uint end_id = uint(gid) % u_end_count;
const uint begin_width = uint(u_resolution[c_face_width_axises[uint(begin.face) % 3]]);
const uint begin_width = uint(u_subdivisions[face_width_axis[uint(begin.face) % 3]]);
begin.index_horizontal = begin_id % begin_width;
begin.index_vertical = begin_id / begin_width;
const uint end_width = uint(u_resolution[c_face_width_axises[uint(end.face) % 3]]);
const uint end_width = uint(u_subdivisions[face_width_axis[uint(end.face) % 3]]);
end.index_horizontal = end_id % end_width;
end.index_vertical = end_id / end_width;
......
#ifndef __GL_BVH
#define __GL_BVH
#include <raytracer/basic_structs.glsl>
#include <raytracer/buffers.glsl>
#include <raytracer/intersections.glsl>
#include <raytracer/std.glsl>
Bounds getNodeBounds(int index, const in Mesh mesh)
{
return mesh.nodes[index].bounds;
}
//"Stackless" BVH-Traversal.
// See https://pdfs.semanticscholar.org/7e81/6b82fb92df08d7bc0d9805f8988754e0d8c1.pdf
bool traverse(const in uint mesh_id, const in Ray ray, inout Hit hit, const in bool nearest_only, const in float max_distance, inout float t_min)
{
float t = 0;
Mesh mesh = b_meshes[mesh_id];
//For ease of use, substitute Ray<->OBB for Ray<->AABB by transforming the ray into object space.
Ray ray_in = ray;
ray_in.direction = vec4(normalize(mat3(mesh.inverse_transformation) * ray_in.direction.xyz), 0);
ray_in.origin = mesh.inverse_transformation * vec4(ray_in.origin.xyz, 1);
// Check once the AABB for the whole scene
bool hit_scene = intersectsRayBounds(ray_in, getNodeBounds(0, mesh), max_distance);
bool hit_triangle = false;
int current_node = 0;
int bitstack = 0;
//if (hit_scene){
while (hit_scene)
{
if (mesh.nodes[current_node].type == 0) //Inner node.
{
int id_left = int(mesh.nodes[current_node].left_idx);
bool hit_left = intersectsRayBounds(ray_in, getNodeBounds(id_left, mesh), max_distance);
int id_right = int(mesh.nodes[current_node].right_idx);
bool hit_right = intersectsRayBounds(ray_in, getNodeBounds(id_right, mesh), max_distance);
//both hit
if (hit_left && hit_right)
{
// shift bitstack and mark as branched, so we can use the marker
// when backtracking to stop here and use the right child.
bitstack = bitstack << 1;
current_node = id_left;
bitstack = bitstack | 1;
continue;
}
// only left hit
else if (hit_left && !hit_right)
{
// Not branching here, the other sibling-check won't be needed here.
bitstack = bitstack << 1;
current_node = id_left;
continue;
}
// only right hit
else if (!hit_left && hit_right)
{
// Not branching here, the other sibling-check won't be needed here.
bitstack = bitstack << 1;
current_node = id_right;
continue;
}
}
else
{
//Is leaf
// intersect ray with primitives.
//shorten ray if closer intersection found.
//intersect triangles
int start = int(mesh.nodes[current_node].left_idx);
int end = int(mesh.nodes[current_node].right_idx);
float u, v;
for (int i = start; i <= end; i++)
{
if (intersectsRayTriangleMesh(ray, i, mesh, t, u, v))
{
if (t < t_min && t < max_distance) //test for ray_length
{
t_min = t;
hit_triangle = true;
if (nearest_only)
{
return true;
}
hit.barycentric = vec3(u, v, 1 - u - v);
hit.triangle = i;
hit.mesh = mesh_id;
}
}
}
}
//Backtrace on bitstack until we find a branching point (where bit value is 1)
while ((bitstack & 1) == 0)
{
//Empty bitstack
if (bitstack == 0)
{
return hit_triangle;
}
current_node = int(mesh.nodes[current_node].parent);
bitstack = bitstack >> 1;
}
//Use other (right) sibling from the left child of the branched tree node.
current_node = int(mesh.nodes[mesh.nodes[current_node].parent].right_idx);
bitstack = bitstack ^ 1;
}
return hit_triangle;
}
bool bvh__nearestIntersection(const in Ray ray, inout Hit hit)
{
float current_t = FLT_MAX;
float min_t = FLT_MAX;
bool hits = false;
for (int i = 0; i < b_meshes.length(); ++i)
{
hits = bool(int(hits) | int(traverse(i, ray, hit, false, current_t, min_t)));
//current_t = min_t;
}
return hits;
}
bool bvh__intersectsAny(const in Ray ray, const in float max_distance)
{
Hit unused_hit;
float current_t = max_distance;
for (int i = 0; i < b_meshes.length(); ++i)
{
if (traverse(i, ray, unused_hit, true, max_distance, current_t))
return true;
}
return false;
}
#endif //__GL_BVH
......@@ -134,7 +134,7 @@ namespace glare
Log_Info << "Compiling construction shader...";
Log_Warn << "Caution: This will influence the construction time by a lot, so don't rely on the next time measurement for performance purposes.";
core::ClockMS compile_timer;
m_construction_shader = std::make_unique<core::Program>(files::shader("/raytracer/angular_linespace_generate.comp"));
m_construction_shader = std::make_unique<core::Program>(files::shader("/raytracer/linespace_build/angular_linespace_generate.comp"));
Log_Warn << "Compilation took " << compile_timer.time() << "ms";
}
......
......@@ -77,11 +77,11 @@ namespace glare
generateGPU(collector);
break;
}
size_t line_count = calculateLineCount();
m_line_buffer.makeResident(gl::Access::eReadOnly);
Log_Info << "[Linespace Data] Generation Time: " << core::ClockGL::instance().end() << "ms";
Log_Info << "[Linespace Data] Lines: " << m_lines.size();
Log_Info << "[Linespace Data] Memory: " << (m_lines.size() * sizeof(Line)) << " Bytes";
Log_Info << "[Linespace Data] Lines: " << line_count;
Log_Info << "[Linespace Data] Memory: " << (line_count * sizeof(Line)) << " Bytes";
Log_Info << "[Linespace Data] Patch Subdivisions: " << m_subdivision.resolution.x << ", " << m_subdivision.resolution.y << ", " << m_subdivision.resolution.z;
Log_Info << "[Linespace Data] Patch Size: " << m_subdivision.size;
Log_Info << "[Linespace Data] Object Bounds: " << collector.bounds();
......@@ -170,7 +170,7 @@ namespace glare
Log_Info << "Compiling construction shader...";
Log_Warn << "Caution: This will influence the construction time by a lot, so don't rely on the next time measurement for performance purposes.";
core::ClockMS compile_timer;
m_construction_shader = std::make_unique<core::Program>(files::shader("/raytracer/linespace_generate.comp"));
m_construction_shader = std::make_unique<core::Program>(files::shader("/raytracer/linespace_build/linespace_generate.comp"));
Log_Warn << "Compilation took " << compile_timer.time() << "ms";
}
m_construction_shader->use();
......@@ -183,8 +183,8 @@ namespace glare
m_construction_shader->uniform("u_bounds.max", m_bounds.max);
m_construction_shader->storageBuffer("line_buffer", m_line_buffer);
glFinish();
m_construction_shader->uniform("u_resolution", m_subdivision.resolution);
m_construction_shader->uniform("u_resolution_size", m_subdivision.size);
m_construction_shader->uniform("u_subdivisions", m_subdivision.resolution);
m_construction_shader->uniform("u_subdivisions_size", m_subdivision.size);
glFinish();
......
......@@ -58,7 +58,7 @@ namespace glare
m_triangle_buffer->makeResident(gl::Access::eReadOnly);
if (!m_linespace)
m_linespace = std::make_shared<Linespace>();
m_linespace = std::make_shared<std::remove_pointer_t<decltype(m_linespace.get())>>();
m_linespace->generate(*this, files::asset("preferences/linespace_default.xml"));
......
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