Commit 26c26a64 authored by Johannes Braun's avatar Johannes Braun
Browse files

Made LS patch sizes non-uniform. Was pretty weirdly unnecessary before

parent 3d843167
......@@ -9,9 +9,9 @@
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, at_position[face_height_axis[axis]] / mesh.linespace.patch_size)
? 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, at_position[face_height_axis[axis]] / mesh.linespace.patch_size)- 1;
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;
}
struct PatchInfo
......@@ -92,7 +92,7 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
int face_tmin;
int face_tmax;
float offset = 2*mesh.linespace.patch_size;
float offset = compMin(mesh.linespace.patch_size);
Ray offset_ray = local_ray;
offset_ray.origin += local_ray.direction * offset;
......
......@@ -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, at_position[face_height_axis[axis]] / mesh.linespace.patch_size)
? 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, at_position[face_height_axis[axis]] / mesh.linespace.patch_size)- 1;
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;
}
struct PatchInfo
......@@ -134,7 +134,7 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
int face_tmin;
int face_tmax;
float offset = mesh.linespace.patch_size;//1;//e-2;//1000;//mesh.linespace.patch_size;
float offset = compMin(mesh.linespace.patch_size);
Ray offset_ray = local_ray;
offset_ray.origin += local_ray.direction * offset;
......
......@@ -20,7 +20,7 @@ uniform uint u_radial_subdivision;
// General inputs
uniform uvec3 u_subdivisions = uvec3(1, 1, 1);
uniform float u_subdivisions_size;
uniform vec3 u_subdivisions_size;
uniform float ray_bias;
uniform Bounds u_bounds;
uniform Mesh u_mesh;
......@@ -63,12 +63,12 @@ vec3 patchCenter(const in Patch p)
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_subdivisions_size + u_subdivisions_size / 2;
position[axis_height] = u_bounds.min[axis_height] + p.index_vertical * u_subdivisions_size + u_subdivisions_size / 2;
position[axis_width] = u_bounds.min[axis_width] + p.index_horizontal * u_subdivisions_size[axis_width] + u_subdivisions_size[axis_width] / 2;
position[axis_height] = u_bounds.min[axis_height] + p.index_vertical * u_subdivisions_size[axis_height] + u_subdivisions_size[axis_height] / 2;
}
else {
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);
position[axis_width] = u_bounds.max[axis_width] - (p.index_horizontal * u_subdivisions_size[axis_width] + u_subdivisions_size[axis_width] / 2);
position[axis_height] = u_bounds.max[axis_height] - (p.index_vertical * u_subdivisions_size[axis_height] + u_subdivisions_size[axis_height] / 2);
}
return position;
......
......@@ -21,7 +21,7 @@ uniform uint u_end_count;
// General inputs
uniform uvec3 u_subdivisions = uvec3(1, 1, 1);
uniform float u_subdivisions_size;
uniform vec3 u_subdivisions_size;
uniform float ray_bias;
uniform Bounds u_bounds;
uniform Mesh u_mesh;
......@@ -139,12 +139,12 @@ vec3 patchCenter(const in Patch p)
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_subdivisions_size + u_subdivisions_size / 2;
position[axis_height] = u_bounds.min[axis_height] + p.index_vertical * u_subdivisions_size + u_subdivisions_size / 2;
position[axis_width] = u_bounds.min[axis_width] + p.index_horizontal * u_subdivisions_size[axis_width] + u_subdivisions_size[axis_width] / 2;
position[axis_height] = u_bounds.min[axis_height] + p.index_vertical * u_subdivisions_size[axis_height] + u_subdivisions_size[axis_height] / 2;
}
else {
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);
position[axis_width] = u_bounds.max[axis_width] - (p.index_horizontal * u_subdivisions_size[axis_width] + u_subdivisions_size[axis_width] / 2);
position[axis_height] = u_bounds.max[axis_height] - (p.index_vertical * u_subdivisions_size[axis_height] + u_subdivisions_size[axis_height] / 2);
}
return position;
......
......@@ -32,7 +32,9 @@ struct Linespace
uint line_count;
Bounds bounds;
uvec3 resolution;
float patch_size;
int padding1;
vec3 patch_size;
int padding2;
};
#endif //!INCLUDE_UTIL_LINESPACE_GLSL
......@@ -5,8 +5,9 @@
#include <core/rendering/mesh_drawable.h>
#include <core/rendering/batch_renderer.h>
#include <core/rendering/batch_render_list.h>
#include <core/rendering/batch_render_list.h>
#include <core/objects/camera.h>
#include "util/files.h"
using namespace glare;
......
......@@ -4,6 +4,7 @@
#include <components/PlayerController.h>
#include <raytrace/tracer/pathtracer.h>
#include "util/files.h"
using namespace glare;
......
......@@ -229,7 +229,7 @@ namespace math
const int largest_axis = largestAxis();
const glm::vec3 bounds_size = glm::max(glm::vec3(size().xyz), glm::vec3(1e-5f));
const float largest_axis_value = glm::compMax(bounds_size);
subdivision.size = largest_axis_value / static_cast<float>(max_subdivisions) + 1e-5f;
float longes_size = largest_axis_value / static_cast<float>(max_subdivisions) + 1e-5f;
subdivision.resolution = glm::ivec3(0);
subdivision.resolution[largest_axis] = max_subdivisions;
......@@ -241,10 +241,14 @@ namespace math
while (side_size > 0)
{
side_size -= subdivision.size;
side_size -= longes_size;
++subdivision.resolution[side];
}
}
subdivision.size = size().xyz / glm::vec3(subdivision.resolution);
subdivision.size = glm::max(subdivision.size, glm::vec3(1e-5f));
return subdivision;
}
......
......@@ -3,6 +3,8 @@
#include <glm/gtx/matrix_decompose.hpp>
#include <ostream>
#include <thread>
#include <omp.h>
namespace math
......@@ -88,7 +90,7 @@ namespace math
//------------------------------------------------------------------
glm::uvec3 resolution;
float size;
glm::vec3 size;
};
/**
......@@ -97,7 +99,7 @@ namespace math
struct Bounds
{
Bounds() = default;
bool contains(glm::vec4 point) const;
bool contains(const math::Bounds& other) const;
float overlap(const math::Bounds& other) const;
......@@ -119,6 +121,7 @@ namespace math
void expand(const glm::vec4& include);
void expand(const Bounds& include);
void expand(const Bounds& include, const glm::mat4& transform);
template<typename TContainer, typename TValue = typename TContainer::value_type> void expand(const TContainer& container, std::function<TValue(const typename TContainer::value_type&, size_t)> make_value = [](const typename TContainer::value_type& obj) { return obj; });
glm::vec4& operator[](size_t i);
const glm::vec4& operator[](size_t i) const;
......@@ -130,6 +133,27 @@ namespace math
glm::vec4 max = glm::vec4(glm::vec3(std::numeric_limits<float>::lowest()), 1.0f);
};
template<typename TContainer, typename TValue>
void Bounds::expand(const TContainer& container, std::function<TValue(const typename TContainer::value_type&, size_t)> make_value)
{
const int concurrency = std::thread::hardware_concurrency();
std::vector<math::Bounds> threaded_bounds(concurrency);
#pragma omp parallel for default(none) num_threads(concurrency) schedule(static)
for (auto i = 0; i<container.size(); ++i)
{
//calculate triangle centroid
threaded_bounds[omp_get_thread_num()].expand(make_value(container[i], static_cast<size_t>(i)));
}
//Write the thread local bounds to the full bounds thing.
for (const auto &b : threaded_bounds)
{
expand(b);
}
max = glm::max(max, min + glm::vec4(1e-5f));
}
struct Triangle
{
glm::vec4 normal() const;
......
......@@ -24,6 +24,7 @@
#include <core/base/gl_state.h>
#include <core/res/texture2d.h>
#include <core/base/vertex_array.h>
#include <util/padding.h>
// Data
static GLFWwindow* g_Window = nullptr;
......@@ -230,11 +231,11 @@ namespace ImGui {
const int attrib_color = m_wrapper->m_program->attributeLocation("Color");
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
m_wrapper->m_vertex_array.linkAttribute(m_wrapper->m_vertex_buffer.id(), attrib_position, 2, gl::Type::eFloat, false, sizeof(ImDrawVert), OFFSETOF(ImDrawVert, pos));
m_wrapper->m_vertex_array.linkAttribute(m_wrapper->m_vertex_buffer.id(), attrib_texcoord, 2, gl::Type::eFloat, false, sizeof(ImDrawVert), OFFSETOF(ImDrawVert, uv));
m_wrapper->m_vertex_array.linkAttribute(m_wrapper->m_vertex_buffer.id(), attrib_color, 4, gl::Type::eUByte, true, sizeof(ImDrawVert), OFFSETOF(ImDrawVert, col));
#undef OFFSETOF
//#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
m_wrapper->m_vertex_array.linkAttribute(m_wrapper->m_vertex_buffer.id(), attrib_position, 2, gl::Type::eFloat, false, sizeof(ImDrawVert), offset_of(&ImDrawVert::pos));
m_wrapper->m_vertex_array.linkAttribute(m_wrapper->m_vertex_buffer.id(), attrib_texcoord, 2, gl::Type::eFloat, false, sizeof(ImDrawVert), offset_of(&ImDrawVert::uv));
m_wrapper->m_vertex_array.linkAttribute(m_wrapper->m_vertex_buffer.id(), attrib_color, 4, gl::Type::eUByte, true, sizeof(ImDrawVert), offset_of(&ImDrawVert::col));
//#undef OFFSETOF
m_wrapper->m_vertex_array.linkIndices(m_wrapper->m_element_buffer.id());
createFontsTexture();
......
......@@ -69,7 +69,7 @@ namespace glare::raytrace
Log_Info << "[Linespace Data] Lines: " << num_lines;
Log_Info << "[Linespace Data] Memory: " << memory << " 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] Patch Size: x=" << m_subdivision.size.x << ", y=" << m_subdivision.size.y << ", z=" << m_subdivision.size.z;
Log_Info << "[Linespace Data] Radial Subdivisions: " << radial_subdivisions;
Log_Info << "[Linespace Data] Object Bounds: " << collector.bounds();
}
......@@ -203,12 +203,12 @@ namespace glare::raytrace
position[FaceAxises::axis(patch.face)] = m_bounds.min[FaceAxises::axis(patch.face)] + FaceAxises::positivity(patch.face)*m_bounds.size()[FaceAxises::axis(patch.face)];
if (patch.face < Face::eNegX) {
position[FaceAxises::get(patch.face).horizontal] = m_bounds.min[FaceAxises::get(patch.face).horizontal] + patch.index_horizontal * m_subdivision.size + m_subdivision.size / 2;
position[FaceAxises::get(patch.face).vertical] = m_bounds.min[FaceAxises::get(patch.face).vertical] + patch.index_vertical * m_subdivision.size + m_subdivision.size / 2;
position[FaceAxises::get(patch.face).horizontal] = m_bounds.min[FaceAxises::get(patch.face).horizontal] + patch.index_horizontal * m_subdivision.size[FaceAxises::get(patch.face).horizontal] + m_subdivision.size[FaceAxises::get(patch.face).horizontal] / 2;
position[FaceAxises::get(patch.face).vertical] = m_bounds.min[FaceAxises::get(patch.face).vertical] + patch.index_vertical * m_subdivision.size[FaceAxises::get(patch.face).vertical] + m_subdivision.size[FaceAxises::get(patch.face).vertical] / 2;
}
else {
position[FaceAxises::get(patch.face).horizontal] = m_bounds.max[FaceAxises::get(patch.face).horizontal] - (patch.index_horizontal * m_subdivision.size + m_subdivision.size / 2);
position[FaceAxises::get(patch.face).vertical] = m_bounds.max[FaceAxises::get(patch.face).vertical] - (patch.index_vertical * m_subdivision.size + m_subdivision.size / 2);
position[FaceAxises::get(patch.face).horizontal] = m_bounds.max[FaceAxises::get(patch.face).horizontal] - (patch.index_horizontal * m_subdivision.size[FaceAxises::get(patch.face).horizontal] + m_subdivision.size[FaceAxises::get(patch.face).horizontal] / 2);
position[FaceAxises::get(patch.face).vertical] = m_bounds.max[FaceAxises::get(patch.face).vertical] - (patch.index_vertical * m_subdivision.size[FaceAxises::get(patch.face).vertical] + m_subdivision.size[FaceAxises::get(patch.face).vertical] / 2);
}
return position;
......
......@@ -3,8 +3,6 @@
#include <functional>
#include <vector>
#include <thread>
#include <omp.h>
#include <core/numeric/geometry.h>
......@@ -144,27 +142,15 @@ namespace glare::raytrace
m_ranges[0].start = 0;
m_ranges[0].end = static_cast<int>(primitives.size() - 1);
m_ranges[0].parent = -1;
const int concurrency = std::thread::hardware_concurrency();
std::vector<math::Bounds> threaded_bounds(concurrency);
#pragma omp parallel for default(none) num_threads(concurrency) schedule(static)
for (int i = 0; i < static_cast<int>(primitives.size()); ++i)
{
//calculate triangle centroid
glm::vec4 centroid = m_centroid_from_id(i);
m_centroids[i] = centroid;
threaded_bounds[omp_get_thread_num()].expand(centroid);
}
math::Bounds centroid_box;
//Write the thread local bounds to the full bounds thing.
for (const auto &b : threaded_bounds)
{
centroid_box.expand(b);
}
centroid_box.max = glm::max(centroid_box.max, centroid_box.min + glm::vec4(1e-5f));
m_ranges[0].parent = -1;
math::Bounds centroid_box;
centroid_box.expand<std::vector<TPrimitive>, glm::vec4>(primitives, [this](const TPrimitive& primitive, size_t index)
{
glm::vec4 centroid = m_centroid_from_id(static_cast<int>(index));
m_centroids[index] = centroid;
return centroid;
});
m_centroid_boxes[0] = centroid_box;
}
......
......@@ -55,7 +55,7 @@ namespace glare::raytrace
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] Patch Sizes: x=" << m_subdivision.size.x << ", y=" << m_subdivision.size.y << ", z=" << m_subdivision.size.z;
Log_Info << "[Linespace Data] Object Bounds: " << collector.bounds();
}
......@@ -210,16 +210,16 @@ namespace glare::raytrace
glm::vec3 Linespace::patchCenter(const SurfacePatch &patch) const
{
glm::vec3 position;
// (1 - (face_index / 3)) is 1 for positive planes, 0 for negative
position[FaceAxises::axis(patch.face)] = m_bounds.min[FaceAxises::axis(patch.face)] + FaceAxises::positivity(patch.face) * m_bounds.size()[FaceAxises::axis(patch.face)];
if (patch.face < Face::eNegX) {
position[FaceAxises::get(patch.face).horizontal] = m_bounds.min[FaceAxises::get(patch.face).horizontal] + patch.index_horizontal * m_subdivision.size + m_subdivision.size / 2;
position[FaceAxises::get(patch.face).vertical] = m_bounds.min[FaceAxises::get(patch.face).vertical] + patch.index_vertical * m_subdivision.size + m_subdivision.size / 2;
position[FaceAxises::get(patch.face).horizontal] = m_bounds.min[FaceAxises::get(patch.face).horizontal] + patch.index_horizontal * m_subdivision.size[FaceAxises::get(patch.face).horizontal] + m_subdivision.size[FaceAxises::get(patch.face).horizontal] / 2;
position[FaceAxises::get(patch.face).vertical] = m_bounds.min[FaceAxises::get(patch.face).vertical] + patch.index_vertical * m_subdivision.size[FaceAxises::get(patch.face).vertical] + m_subdivision.size[FaceAxises::get(patch.face).vertical] / 2;
}
else {
position[FaceAxises::get(patch.face).horizontal] = m_bounds.max[FaceAxises::get(patch.face).horizontal] - (patch.index_horizontal * m_subdivision.size + m_subdivision.size / 2);
position[FaceAxises::get(patch.face).vertical] = m_bounds.max[FaceAxises::get(patch.face).vertical] - (patch.index_vertical * m_subdivision.size + m_subdivision.size / 2);
position[FaceAxises::get(patch.face).horizontal] = m_bounds.max[FaceAxises::get(patch.face).horizontal] - (patch.index_horizontal * m_subdivision.size[FaceAxises::get(patch.face).horizontal] + m_subdivision.size[FaceAxises::get(patch.face).horizontal] / 2);
position[FaceAxises::get(patch.face).vertical] = m_bounds.max[FaceAxises::get(patch.face).vertical] - (patch.index_vertical * m_subdivision.size[FaceAxises::get(patch.face).vertical] + m_subdivision.size[FaceAxises::get(patch.face).vertical] / 2);
}
return position;
......
......@@ -105,7 +105,9 @@ namespace glare::raytrace
uint32_t line_count;
math::Bounds bounds;
glm::uvec3 resolution;
float patch_size;
int : 32;
glm::vec3 patch_size;
int : 32;
};
struct Mesh
......
#ifndef INCLUDE_PADDING_H
#define INCLUDE_PADDING_H
template<typename T, typename TMember>
constexpr size_t offset_of(TMember T::* field)
{
return reinterpret_cast<size_t>(&(reinterpret_cast<T*>(nullptr) ->* field));
}
#endif //!INCLUDE_PADDING_H
\ No newline at end of file
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