Commit 0ff587f2 authored by unknown's avatar unknown
Browse files

Probably maybe made a little bit of progress? Dunno.

parent 9a51510e
......@@ -133,7 +133,8 @@ struct Mesh
Line* lines;
uint material;
uint p[3];
uint id;
uint p[2];
LineSpace linespace;
......
......@@ -6,160 +6,7 @@
#include <raytracer/intersections.glh>
#include <raytracer/std.glh>
#include <raytracer/utilities.glh>
const uvec3 c_face_width_axises = { 2, 2, 0 };
const uvec3 c_face_height_axises = { 1, 0, 1 };
uint faceRangeIndex(uint in_face, uint out_face)
{
return uint((((-0.5f * in_face) + 4.5f)*in_face) - 1u + out_face);
}
uvec2 getPatch(const in Mesh mesh, vec3 at_position, int axis, int face){
bool flip_indices = face>2;
return clamp(uvec2(
flip_indices ? (mesh.linespace.resolution[c_face_width_axises[axis]] - (at_position[c_face_width_axises[axis]] / mesh.linespace.patch_size)) : (at_position[c_face_width_axises[axis]] / mesh.linespace.patch_size),
flip_indices ? (mesh.linespace.resolution[c_face_height_axises[axis]] - (at_position[c_face_height_axises[axis]] / mesh.linespace.patch_size)) : (at_position[c_face_height_axises[axis]] / mesh.linespace.patch_size)
), uvec2(0), uvec2(mesh.linespace.resolution[c_face_width_axises[axis]], mesh.linespace.resolution[c_face_height_axises[axis]]));
}
struct PatchInfo
{
int face;
int axis;
uvec2 patch_index;
vec3 position;
float t;
};
float getDistance(const in Ray ray, const in Hit hit, inout float dir_sign)
{
Mesh mesh = b_meshes[hit.mesh];
Triangle triangle = mesh.triangles[hit.triangle];
Vertex v1 = mesh.vertices[triangle.indices[1]];
Vertex v2 = mesh.vertices[triangle.indices[2]];
Vertex v3 = mesh.vertices[triangle.indices[0]];
vec3 vector = hit__getFromBarycentric(hit.barycentric, triangle, position).xyz - ray.origin;
dir_sign = dot(vector, ray.direction);
return length(vector);
}
bool getLineIndex(const in Ray ray, const in Mesh mesh, inout uint line_id, inout bool direction_swapped)
{
float tmin, tmax;
int face_in, face_out;
direction_swapped = false;
//If the AABB is not intersected, cancel the traversal.
Ray very_long_ray = ray;
if (!intersectsRayBounds(very_long_ray, mesh.linespace.bounds, tmin, tmax, face_in, face_out))
return false;
PatchInfo entry_info;
PatchInfo exit_info;
// face_in > face_out is an unsupported configuration for reasons of generation performance and memory conservation.
// If that happens, flip tmin, tmax and the two faces accordingly and mark it as flipped to we can take the farthest intersection in the shaft instead of the nearest.
direction_swapped = face_in > face_out;
// -------- t values -------------
entry_info.t = direction_swapped ? tmax : tmin;
exit_info.t = direction_swapped ? tmin : tmax;
// -------- faces ----------------
entry_info.face = direction_swapped ? face_out : face_in;
exit_info.face = direction_swapped ? face_in : face_out;
/////////////////////////////////////////////////////////////
//calculate entry and exit points on the minimum-normalized bounding box
//(so that bounds.min is at (0,0,0) and bounds.max is at the former bounding box's size)
entry_info.position = ray.origin + entry_info.t * ray.direction - mesh.linespace.bounds.min.xyz;
exit_info.position = ray.origin + exit_info.t * ray.direction - mesh.linespace.bounds.min.xyz;
entry_info.axis = entry_info.face % 3;
exit_info.axis = exit_info.face % 3;
// getPatch mirrors the patches on the negative axises per definition.
entry_info.patch_index = getPatch(mesh, entry_info.position, entry_info.axis, entry_info.face);
exit_info.patch_index = getPatch(mesh, exit_info.position, exit_info.axis, exit_info.face);
//Now with all that information, we can retrieve the line index.
uint offset_index = faceRangeIndex(entry_info.face, exit_info.face);
uint offset = mesh.offsets[offset_index];
uint start_height = mesh.linespace.resolution[c_face_height_axises[entry_info.axis]];
uint end_width = mesh.linespace.resolution[c_face_width_axises[exit_info.axis]];
uint end_height = mesh.linespace.resolution[c_face_height_axises[exit_info.axis]];
uint start = (entry_info.patch_index.y + entry_info.patch_index.x * start_height) * end_width * end_height;
uint end = (exit_info.patch_index.y + exit_info.patch_index.x * end_height);
line_id = clamp(offset + start + end, 0, mesh.line_count);
return true;
}
bool linespace__traverse(const in uint mesh_id, const in Ray ray, inout Hit hit) {
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 = normalize(mat3(mesh.inverse_transformation) * ray_in.direction.xyz);
ray_in.origin = (mesh.inverse_transformation * vec4(ray_in.origin.xyz, 1)).xyz;
Ray real = ray_in;
real.origin = real.origin - 1000*real.direction;
uint line_id;
bool direction_swapped;
if (getLineIndex(real, mesh, line_id, direction_swapped))
{
// TODO: Add a distance check.
Line line = mesh.lines[line_id];
// Hit first = direction_swapped ? line.farthest : line.nearest;
// Hit second = direction_swapped ? line.nearest : line.farthest;
// bool use_second = false;
// float dir_sign;
// float nearest_distance = getDistance(ray_in, first, dir_sign);
// if(dir_sign < 0){
// float farthest_distance = getDistance(ray_in, second, dir_sign);
// use_second = true;
// if(dir_sign < 0)
// {
// return false; // }
// }
hit = direction_swapped ? line.farthest : line.nearest;
float dir_sign;
float nearest_distance = getDistance(ray_in, hit, dir_sign);
if(dir_sign > 0 && nearest_distance > 1){
hit.mesh = mesh_id;
//Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step.
return hit.barycentric.x != -1;
}
hit = direction_swapped ? line.nearest : line.farthest;
float farthest_distance = getDistance(ray_in, hit, dir_sign);
if(dir_sign > 0 && farthest_distance > 1) {
hit.mesh = mesh_id;
//Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step.
return hit.barycentric.x != -1;
}
}
return false;
}
#include <raytracer/mesh_ls.glh>
Bounds getNodeBounds(int index, const in Mesh mesh)
{
......@@ -285,8 +132,21 @@ bool traverse(const in uint mesh_id, const in Ray ray, inout Hit hit, const in b
bool bvh__nearestIntersection(const in Ray ray, inout Hit hit)
{
#ifdef USE_LS
return linespace__traverse(0, ray, hit);
#endif
bool ls_hits = false;
float distance = FLT_MAX;
ls_hits = bool(int(ls_hits) | int(linespace__traverse(0, ray, hit, distance)));
// ls_hits = bool(int(ls_hits) | int(linespace__traverse(1, ray, hit, distance)));
// ls_hits = bool(int(ls_hits) | int(linespace__traverse(2, ray, hit, distance)));
// ls_hits = bool(int(ls_hits) | int(linespace__traverse(3, ray, hit, distance)));
// ls_hits = bool(int(ls_hits) | int(linespace__traverse(4, ray, hit, distance)));
// for(int mesh_id = 0; mesh_id < 5; ++mesh_id){
// ls_hits = linespace__traverse(mesh_id, ray, hit);
// //ls_hits = bool(int(ls_hits) | int(linespace__traverse(mesh_id, ray, hit)));
// }
return ls_hits;
//return linespace__traverse(4, ray, hit);
//bool hits = false;
//for (int i = 0; i < b_meshes.length(); ++i)
//{
......@@ -295,7 +155,7 @@ bool bvh__nearestIntersection(const in Ray ray, inout Hit hit)
//}
//return hits;
#else
float current_t = FLT_MAX;
float min_t = FLT_MAX;
bool hits = false;
......@@ -306,16 +166,21 @@ bool bvh__nearestIntersection(const in Ray ray, inout Hit hit)
}
return hits;
#endif
}
bool bvh__intersectsAny(const in Ray ray, const in float max_distance)
{
return false;
Hit unused_hit;
float dist = FLT_MAX;
#ifdef USE_LS
//return false;
return linespace__traverse(0, ray, unused_hit);
for (int i = 1; i < 2; ++i)
{
return linespace__traverse(i, ray, unused_hit, dist);
}
#endif
......
......@@ -48,7 +48,7 @@ namespace glare
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/ryfjallet/")));
initializeScene(m_current_scene_root / "monkey.dae", 1.f);
initializeScene(m_current_scene_root / "boxes.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
initializeGUI();
......
......@@ -79,7 +79,8 @@ namespace glare
uint64_t lines_buffer;
glm::uint material;
glm::uint p[3];
glm::uint id;
glm::uint p[2];
LineSpaceData linespace;
......
......@@ -17,6 +17,8 @@ namespace glare
void LocalCollector::collect(const core::MeshRenderer &mesh, std::shared_ptr<LocalDatastructure> datastructure)
{
Log_Info << "############## CURRENTLY PROCESSED MESH NAME: " << mesh.getOwner()->name() << " #################";
m_id = mesh.id();
m_material_id = mesh.getMaterial()->id();
m_datastructure = datastructure;
......@@ -89,6 +91,7 @@ namespace glare
Mesh LocalCollector::makeMesh(glm::uint material_index) const
{
Mesh mesh;
mesh.id = id();
mesh.datastructure_buffer_ptr = m_datastructure->buffer().getResidentAddress();
mesh.transformation = m_transform;
mesh.inverse_transformation = glm::inverse(m_transform);
......
......@@ -157,8 +157,10 @@ namespace glare
gl::framebufferTexture2D(gl::FramebufferTarget::eDefault, gl::Attachment::eDepth, gl::FramebufferTextureTarget::e2DMultisample, m_depth_attachment->getID(), 0);
m_draw_buffers.push_back(gl::Attachment::eDepth);
gl::drawBuffers(m_draw_buffers);
if (std::find(m_draw_buffers.begin(), m_draw_buffers.end(), gl::Attachment::eDepth) == m_draw_buffers.end()) {
m_draw_buffers.push_back(gl::Attachment::eDepth);
gl::drawBuffers(m_draw_buffers);
}
gl::FramebufferStatus status = gl::checkFramebufferStatus(gl::FramebufferTarget::eDefault);
if (status != gl::FramebufferStatus::eComplete)
......
......@@ -20,7 +20,7 @@ namespace glare
unsigned goodSubdivision(size_t polygon_count, glm::vec3 bounds_size)
{
return unsigned(4*glm::ceil(glm::log2(glm::max(size_t(2), polygon_count)) * glm::log(log2((glm::compMax(bounds_size) / glm::compMin(bounds_size)) + 2 * glm::e<float>()))));
return 4;// unsigned(5 * glm::ceil(glm::log2(glm::max(size_t(2), polygon_count)) * glm::log(log2((glm::compMax(bounds_size) / glm::compMin(bounds_size)) + 2 * glm::e<float>()))));
}
}
......
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