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
// Schlick's fresnel approximation with the material's normal response
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_rest = 1-k_s;
......
......@@ -4,13 +4,7 @@
#include <util/scene/mesh.glsl>
#include <util/tracing/intersections.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>
#undef USE_ANGULAR_LS
#endif //!USE_ANGULAR_LS
uvec2 getPatch(const in Mesh mesh, vec3 at_position, int axis, int face){
bool flip_indices = face != axis;
......
......@@ -146,9 +146,10 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
bool swapped = false;
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;
float t;
......@@ -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)
{
nearer.triangle = near_data;
......
......@@ -7,14 +7,7 @@
#include <util/math/geometry.glsl>
#include <util/scene/mesh.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>
#undef USE_ANGULAR_LS
#endif //!USE_ANGULAR_LS
#include <pathtracer/data/mesh_bvh.glsl>
#include <pathtracer/buffers.glsl>
......
......@@ -177,7 +177,8 @@ void generate(uint gid)
ray.origin = center_begin.xyz - ray_bias * ray.direction;
uint line_index = lineIndex(begin, end);
Line line;
Line line_front;
Line line_back;
//Invalidate intersections
Hit nearest;
......@@ -188,21 +189,22 @@ void generate(uint gid)
nearest.barycentric = vec2(-1);
farthest.barycentric = vec2(-1);
line.nearest = -1;
line.farthest = -1;
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);
if(nearest.valid())
{
line.nearest = int(nearest.triangle);
line_front.triangle = int(nearest.triangle);
}
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 @@
#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_height_axis[3] = {1, 0, 1};
......@@ -22,12 +19,7 @@ const uint face_height_axis[3] = {1, 0, 1};
*/
struct Line
{
#ifdef USE_ANGULAR_LS
int triangle;
#else
int nearest;
int farthest;
#endif
};
/*
......
......@@ -18,15 +18,16 @@ namespace glare
int logLength = 0;
gl::getProgramiv(m_handle, gl::ProgramParameter::eLogInfoLength, &logLength);
char *log = new char[logLength];
gl::getProgramInfoLog(m_handle, logLength, &logLength, log);
std::string log(logLength, ' ');
gl::getProgramInfoLog(m_handle, logLength, &logLength, &log[0]);
Log_Error << log;
delete[] log;
Log_Error << "Shader compiled successfully.";
for (const auto &shader : shaders)
gl::detachShader(m_handle, shader->id());
gl::deleteProgram(m_handle);
throw std::runtime_error(log);
}
else
{
......
......@@ -38,8 +38,7 @@ namespace glare
const char *source_chars = precompiled.c_str();
gl::shaderSource(m_handle, 1, &source_chars, nullptr);
const char* root = "/.";
int count = 1;
static const char* root = "/.";
if (glfwExtensionSupported("GL_ARB_shading_language_include")) {
gl::compileShaderInclude(m_handle, 1, &root, nullptr);
......@@ -54,16 +53,13 @@ namespace glare
if (!success)
{
int logSize = 200;
int logSize = 0;
gl::getShaderiv(m_handle, gl::GetShaderParameter::eLogInfoLength, &logSize);
char *log = new char[logSize];
gl::getShaderInfoLog(m_handle, logSize, &logSize, log);
std::string log(logSize, ' ');
gl::getShaderInfoLog(m_handle, logSize, &logSize, &log[0]);
Log_Error << log;
m_handle.reset();
delete[] log;
throw std::runtime_error(log);
}
else
{
......
......@@ -66,7 +66,7 @@ namespace glare
}
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] Lines: " << num_lines;
......@@ -79,7 +79,7 @@ namespace glare
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();
for (Face face = Face::ePosX; unsigned(face) <= unsigned(Face::eNegZ); face = Face(unsigned(face) + 1))
......
......@@ -16,11 +16,6 @@ namespace glare
{
namespace raytrace
{
struct AngleLine
{
int32_t triangle;
};
class AngularLinespace
{
public:
......
......@@ -63,7 +63,7 @@ namespace glare
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();
for (const auto& configuration : configurations) {
......@@ -110,8 +110,8 @@ namespace glare
line_bvh.nearestAndFarthestIntersection(ray, nearest, farthest);
const size_t line_index = lineIndex(begin, end);
if (nearest) lines[line_index].nearest = nearest.triangle;
if (farthest) lines[line_index].farthest = farthest.triangle;
if (nearest) lines[line_index * 2].triangle = nearest.triangle;
if (farthest) lines[line_index * 2 + 1].triangle = farthest.triangle;
}
}
......@@ -257,9 +257,9 @@ namespace glare
const size_t patches_y = patchCount(Face::ePosY);
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_z * (patches_x + patches_y) + patches_z * patches_z;
+ 2 * patches_z * (patches_x + patches_y) + patches_z * patches_z);
}
LinespaceData Linespace::data() const
......
......@@ -47,8 +47,7 @@ namespace glare
struct Line
{
//hit triangle id's
int32_t nearest;
int32_t farthest;
int32_t triangle;
};
class Linespace
......@@ -73,6 +72,8 @@ namespace glare
void generateGPU(const LocalCollector &collector);
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 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