Commit 6cacbe38 authored by Johannes Braun's avatar Johannes Braun
Browse files

Changed Line struct to now only contain one triangle

parent a847a258
...@@ -93,7 +93,7 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i ...@@ -93,7 +93,7 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
// Schlick's fresnel approximation with the material's normal response // Schlick's fresnel approximation with the material's normal response
float normal_response = normalResponse(sampled_material.ior, sampled_material.metallic); float normal_response = normalResponse(sampled_material.ior, sampled_material.metallic);
float fresnel = fresnelSchlick(dot(incoming, base_micro_normal), normal_response); float fresnel = fresnelSchlick(dot(incoming, microfacet_normal), normal_response);
float k_s = fresnel; float k_s = fresnel;
float k_rest = 1-k_s; float k_rest = 1-k_s;
......
...@@ -4,13 +4,7 @@ ...@@ -4,13 +4,7 @@
#include <util/scene/mesh.glsl> #include <util/scene/mesh.glsl>
#include <util/tracing/intersections.glsl> #include <util/tracing/intersections.glsl>
#include <util/tracing/tracing.glsl> #include <util/tracing/tracing.glsl>
#ifndef USE_ANGULAR_LS
#define USE_ANGULAR_LS
//Include ls data structs with angular definition
#include <util/tracing/linespace.glsl> #include <util/tracing/linespace.glsl>
#undef USE_ANGULAR_LS
#endif //!USE_ANGULAR_LS
uvec2 getPatch(const in Mesh mesh, vec3 at_position, int axis, int face){ uvec2 getPatch(const in Mesh mesh, vec3 at_position, int axis, int face){
bool flip_indices = face != axis; bool flip_indices = face != axis;
......
...@@ -146,9 +146,10 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool ...@@ -146,9 +146,10 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
bool swapped = false; bool swapped = false;
uint line_id = lineIndex(offset_ray, mesh, tmin, tmax, face_tmin, face_tmax, swapped); uint line_id = lineIndex(offset_ray, mesh, tmin, tmax, face_tmin, face_tmax, swapped);
Line line = mesh.linespace.lines[line_id]; Line line_near = mesh.linespace.lines[line_id * 2];
Line line_far = mesh.linespace.lines[line_id * 2 + 1];
int near_data = swapped ? line.farthest : line.nearest; int near_data = swapped ? line_far.triangle : line_near.triangle;
Hit nearer; Hit nearer;
float t; float t;
...@@ -168,7 +169,7 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool ...@@ -168,7 +169,7 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
} }
} }
near_data = swapped ? line.nearest : line.farthest; near_data = swapped ? line_near.triangle : line_far.triangle;
if(near_data != -1) if(near_data != -1)
{ {
nearer.triangle = near_data; nearer.triangle = near_data;
......
...@@ -7,14 +7,7 @@ ...@@ -7,14 +7,7 @@
#include <util/math/geometry.glsl> #include <util/math/geometry.glsl>
#include <util/scene/mesh.glsl> #include <util/scene/mesh.glsl>
#include <util/tracing/tracing.glsl> #include <util/tracing/tracing.glsl>
#ifndef USE_ANGULAR_LS
#define USE_ANGULAR_LS
//Include ls data structs with angular definition
#include <util/tracing/linespace.glsl> #include <util/tracing/linespace.glsl>
#undef USE_ANGULAR_LS
#endif //!USE_ANGULAR_LS
#include <pathtracer/data/mesh_bvh.glsl> #include <pathtracer/data/mesh_bvh.glsl>
#include <pathtracer/buffers.glsl> #include <pathtracer/buffers.glsl>
......
...@@ -177,7 +177,8 @@ void generate(uint gid) ...@@ -177,7 +177,8 @@ void generate(uint gid)
ray.origin = center_begin.xyz - ray_bias * ray.direction; ray.origin = center_begin.xyz - ray_bias * ray.direction;
uint line_index = lineIndex(begin, end); uint line_index = lineIndex(begin, end);
Line line; Line line_front;
Line line_back;
//Invalidate intersections //Invalidate intersections
Hit nearest; Hit nearest;
...@@ -188,21 +189,22 @@ void generate(uint gid) ...@@ -188,21 +189,22 @@ void generate(uint gid)
nearest.barycentric = vec2(-1); nearest.barycentric = vec2(-1);
farthest.barycentric = vec2(-1); farthest.barycentric = vec2(-1);
line.nearest = -1; line_front.triangle = -1;
line.farthest = -1; line_back.triangle = -1;
float t_min = FLT_MAX; float t_min = FLT_MAX;
u_mesh.traverseBVH(ray, false, FLT_MAX, true, nearest, farthest, t_min); u_mesh.traverseBVH(ray, false, FLT_MAX, true, nearest, farthest, t_min);
if(nearest.valid()) if(nearest.valid())
{ {
line.nearest = int(nearest.triangle); line_front.triangle = int(nearest.triangle);
} }
if(farthest.valid()) if(farthest.valid())
{ {
line.farthest = int(farthest.triangle); line_back.triangle = int(farthest.triangle);
} }
lines_data[line_index] = line; lines_data[line_index * 2] = line_front;
lines_data[line_index * 2 + 1] = line_back;
} }
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#include <util/math/geometry.glsl> #include <util/math/geometry.glsl>
// Uncomment if you use the Angular LS
//#define USE_ANGULAR_LS
const uint face_width_axis[3] = {2, 2, 0}; const uint face_width_axis[3] = {2, 2, 0};
const uint face_height_axis[3] = {1, 0, 1}; const uint face_height_axis[3] = {1, 0, 1};
...@@ -22,12 +19,7 @@ const uint face_height_axis[3] = {1, 0, 1}; ...@@ -22,12 +19,7 @@ const uint face_height_axis[3] = {1, 0, 1};
*/ */
struct Line struct Line
{ {
#ifdef USE_ANGULAR_LS
int triangle; int triangle;
#else
int nearest;
int farthest;
#endif
}; };
/* /*
......
...@@ -18,15 +18,16 @@ namespace glare ...@@ -18,15 +18,16 @@ namespace glare
int logLength = 0; int logLength = 0;
gl::getProgramiv(m_handle, gl::ProgramParameter::eLogInfoLength, &logLength); gl::getProgramiv(m_handle, gl::ProgramParameter::eLogInfoLength, &logLength);
char *log = new char[logLength]; std::string log(logLength, ' ');
gl::getProgramInfoLog(m_handle, logLength, &logLength, log); gl::getProgramInfoLog(m_handle, logLength, &logLength, &log[0]);
Log_Error << log; Log_Error << log;
delete[] log; Log_Error << "Shader compiled successfully.";
for (const auto &shader : shaders) for (const auto &shader : shaders)
gl::detachShader(m_handle, shader->id()); gl::detachShader(m_handle, shader->id());
gl::deleteProgram(m_handle);
throw std::runtime_error(log);
} }
else else
{ {
......
...@@ -38,8 +38,7 @@ namespace glare ...@@ -38,8 +38,7 @@ namespace glare
const char *source_chars = precompiled.c_str(); const char *source_chars = precompiled.c_str();
gl::shaderSource(m_handle, 1, &source_chars, nullptr); gl::shaderSource(m_handle, 1, &source_chars, nullptr);
const char* root = "/."; static const char* root = "/.";
int count = 1;
if (glfwExtensionSupported("GL_ARB_shading_language_include")) { if (glfwExtensionSupported("GL_ARB_shading_language_include")) {
gl::compileShaderInclude(m_handle, 1, &root, nullptr); gl::compileShaderInclude(m_handle, 1, &root, nullptr);
...@@ -54,16 +53,13 @@ namespace glare ...@@ -54,16 +53,13 @@ namespace glare
if (!success) if (!success)
{ {
int logSize = 200; int logSize = 0;
gl::getShaderiv(m_handle, gl::GetShaderParameter::eLogInfoLength, &logSize); gl::getShaderiv(m_handle, gl::GetShaderParameter::eLogInfoLength, &logSize);
char *log = new char[logSize]; std::string log(logSize, ' ');
gl::getShaderInfoLog(m_handle, logSize, &logSize, log); gl::getShaderInfoLog(m_handle, logSize, &logSize, &log[0]);
Log_Error << log; Log_Error << log;
throw std::runtime_error(log);
m_handle.reset();
delete[] log;
} }
else else
{ {
......
...@@ -66,7 +66,7 @@ namespace glare ...@@ -66,7 +66,7 @@ namespace glare
} }
const size_t num_lines = unsigned(lineCount()); const size_t num_lines = unsigned(lineCount());
const size_t memory = sizeof(AngleLine) * num_lines; const size_t memory = sizeof(Line) * num_lines;
Log_Info << "[Linespace Data] Generation Time: " << clock.time() << "ms"; Log_Info << "[Linespace Data] Generation Time: " << clock.time() << "ms";
Log_Info << "[Linespace Data] Lines: " << num_lines; Log_Info << "[Linespace Data] Lines: " << num_lines;
...@@ -79,7 +79,7 @@ namespace glare ...@@ -79,7 +79,7 @@ namespace glare
void AngularLinespace::generateCPU(const LocalCollector &collector) void AngularLinespace::generateCPU(const LocalCollector &collector)
{ {
std::vector<AngleLine> lines(lineCount(), AngleLine{ -1 }); std::vector<Line> lines(lineCount(), Line{ -1 });
const LocalBVH &line_bvh = collector.bvh(); const LocalBVH &line_bvh = collector.bvh();
for (Face face = Face::ePosX; unsigned(face) <= unsigned(Face::eNegZ); face = Face(unsigned(face) + 1)) for (Face face = Face::ePosX; unsigned(face) <= unsigned(Face::eNegZ); face = Face(unsigned(face) + 1))
......
...@@ -16,11 +16,6 @@ namespace glare ...@@ -16,11 +16,6 @@ namespace glare
{ {
namespace raytrace namespace raytrace
{ {
struct AngleLine
{
int32_t triangle;
};
class AngularLinespace class AngularLinespace
{ {
public: public:
......
...@@ -63,7 +63,7 @@ namespace glare ...@@ -63,7 +63,7 @@ namespace glare
void Linespace::generateCPU(const LocalCollector &collector) void Linespace::generateCPU(const LocalCollector &collector)
{ {
std::vector<Line> lines(lineCount(), Line{ -1, -1 }); std::vector<Line> lines(lineCount(), Line{ -1 });
const LocalBVH &line_bvh = collector.bvh(); const LocalBVH &line_bvh = collector.bvh();
for (const auto& configuration : configurations) { for (const auto& configuration : configurations) {
...@@ -110,8 +110,8 @@ namespace glare ...@@ -110,8 +110,8 @@ namespace glare
line_bvh.nearestAndFarthestIntersection(ray, nearest, farthest); line_bvh.nearestAndFarthestIntersection(ray, nearest, farthest);
const size_t line_index = lineIndex(begin, end); const size_t line_index = lineIndex(begin, end);
if (nearest) lines[line_index].nearest = nearest.triangle; if (nearest) lines[line_index * 2].triangle = nearest.triangle;
if (farthest) lines[line_index].farthest = farthest.triangle; if (farthest) lines[line_index * 2 + 1].triangle = farthest.triangle;
} }
} }
...@@ -257,9 +257,9 @@ namespace glare ...@@ -257,9 +257,9 @@ namespace glare
const size_t patches_y = patchCount(Face::ePosY); const size_t patches_y = patchCount(Face::ePosY);
const size_t patches_z = patchCount(Face::ePosZ); const size_t patches_z = patchCount(Face::ePosZ);
return 2 * patches_x * (patches_y + patches_z) + patches_x * patches_x return 2 * (2 * patches_x * (patches_y + patches_z) + patches_x * patches_x
+ 2 * patches_y * (patches_x + patches_z) + patches_y * patches_y + 2 * patches_y * (patches_x + patches_z) + patches_y * patches_y
+ 2 * patches_z * (patches_x + patches_y) + patches_z * patches_z; + 2 * patches_z * (patches_x + patches_y) + patches_z * patches_z);
} }
LinespaceData Linespace::data() const LinespaceData Linespace::data() const
......
...@@ -47,8 +47,7 @@ namespace glare ...@@ -47,8 +47,7 @@ namespace glare
struct Line struct Line
{ {
//hit triangle id's //hit triangle id's
int32_t nearest; int32_t triangle;
int32_t farthest;
}; };
class Linespace class Linespace
...@@ -73,6 +72,8 @@ namespace glare ...@@ -73,6 +72,8 @@ namespace glare
void generateGPU(const LocalCollector &collector); void generateGPU(const LocalCollector &collector);
size_t offsetOf(const Face in, const Face out) const; size_t offsetOf(const Face in, const Face out) const;
// Computes the bidirectionally staggered line block index. The total index will then be x*2, or x*2 + 1, depending on whether you want to have the nearer or the farther line.
size_t lineIndex(const SurfacePatch &in, const SurfacePatch &out) const; size_t lineIndex(const SurfacePatch &in, const SurfacePatch &out) const;
size_t lineCount() const; size_t lineCount() const;
......
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