Commit 9eb75598 authored by unknown's avatar unknown
Browse files

Several fixes for uniform parameter collection

parent deb7d519
<linespace version="1.0">
<item name="subdivisions" value="150"/>
<item name="radial-subdivision" value="10"/>
<item name="subdivisions" value="20"/>
<item name="radial-subdivision" value="30"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -117,7 +117,7 @@ struct line_hit
int triangle;
};
#define USE_ANGULAR_LS
//#define USE_ANGULAR_LS
struct Line
{
......
......@@ -2,8 +2,8 @@
#define __GL_MESH_DATASTRUCTURE
#include <raytracer/datastructure/mesh_bvh.glsl>
#include <raytracer/datastructure/mesh_angular_linespace.glsl>
//#include <raytracer/datastructure/mesh_linespace.glsl>
//#include <raytracer/datastructure/mesh_angular_linespace.glsl>
#include <raytracer/datastructure/mesh_linespace.glsl>
uniform bool u_use_ls;
......
......@@ -10,19 +10,19 @@
layout(local_size_variable) in;
uniform uvec3 u_resolution = uvec3(1, 1, 1);
uniform float u_resolution_size;
uniform uint u_begin_face;
uniform uint u_end_face;
uniform uint u_begin_count;
uniform uint u_end_count;
uniform float ray_bias;
uniform Bounds u_bounds;
uniform vec3 u_subdivisions;
uniform float u_subdivisions_size;
uniform uint u_offsets[15];
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];
STD_BUFFER line_buffer
{
......@@ -59,9 +59,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_subdivisions[c_face_height_axises[begin.face%3]]);
uint end_width = uint(u_subdivisions[c_face_width_axises[end.face%3]]);
uint end_height = uint(u_subdivisions[c_face_height_axises[end.face%3]]);
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_id = (begin.index_vertical + begin.index_horizontal * start_height) * end_width * end_height;
uint end_id = (end.index_vertical + end.index_horizontal * end_height);
......@@ -82,12 +82,12 @@ vec3 patchCenter(const in Patch p)
uint axis_height = c_face_height_axises[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_resolution_size + u_resolution_size / 2;
position[axis_height] = u_bounds.min[axis_height] + p.index_vertical * u_resolution_size + u_resolution_size / 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_resolution_size + u_resolution_size / 2);
position[axis_height] = u_bounds.max[axis_height] - (p.index_vertical * u_resolution_size + u_resolution_size / 2);
}
return position;
......@@ -103,11 +103,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_subdivisions[c_face_width_axises[uint(begin.face) % 3]]);
const uint begin_width = uint(u_resolution[c_face_width_axises[uint(begin.face) % 3]]);
begin.index_horizontal = begin_id % begin_width;
begin.index_vertical = begin_id / begin_width;
const uint end_width = uint(u_subdivisions[c_face_width_axises[uint(end.face) % 3]]);
const uint end_width = uint(u_resolution[c_face_width_axises[uint(end.face) % 3]]);
end.index_horizontal = end_id % end_width;
end.index_vertical = end_id / end_width;
......
......@@ -118,8 +118,8 @@ namespace glare
//initializeScene(m_current_scene_root / "glass.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_mirror_0r.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_transparent.dae", 1.f);
initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "kubas.dae", 1.f);
//initializeScene(m_current_scene_root / "stmirror.dae", 1.f);
initializeScene(m_current_scene_root / "artifact_suzanne_x2_transparent.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
......
......@@ -58,9 +58,23 @@ namespace glare
int length = max_length;
char* name = new char[length];
gl::getActiveUniform(m_handle, i, length, &data.size, &data.type, name);
data.index = i;
data.name = name;
data.index = uniformLocation(name);
m_uniforms[data.name] = data;
if (data.size > 1 && std::string(data.name.data() + data.name.length() - 3) == "[0]")
{
const auto idx = data.name.find_last_of('[', 0);
for (int i = 1; i < data.size; ++i)
{
std::string last_ending = "[" + std::to_string(i-1) + "]";
std::string ending = "[" + std::to_string(i) + "]";
data.name = std::string(data.name.data(), data.name.data() + data.name.length() - last_ending.length()) + ending;
data.index = uniformLocation(data.name);
m_uniforms[data.name] = data;
}
}
delete[] name;
}
}
......
......@@ -173,8 +173,30 @@ namespace glare
m_construction_shader = std::make_unique<core::Program>(files::shader("/raytracer/linespace_generate.comp"));
Log_Warn << "Compilation took " << compile_timer.time() << "ms";
}
m_construction_shader->use();
m_line_buffer.reserve<Line>(calculateLineCount(), gl::BufferUsage::eDynamicDraw);
//An offset length with which the generator ray will be offset backwards to assure intersecting all possible faces.
const float ray_bias = 1e-2f;
m_construction_shader->uniform("ray_bias", ray_bias);
m_construction_shader->uniform("u_bounds.min", m_bounds.min);
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);
glFinish();
for (int i = 0; i < 15; ++i) {
m_construction_shader->uniform("u_offsets[" + std::to_string(i) + "]", unsigned(m_offsets[i]));
}
auto mesh = collector.makeMesh(0);
m_construction_shader->uniform("u_mesh.triangles", mesh.triangle_buffer_ptr);
m_construction_shader->uniform("u_mesh.id", mesh.id);
m_construction_shader->uniform("u_mesh.vertices", mesh.vertex_buffer_ptr);
m_construction_shader->uniform("u_mesh.nodes", mesh.datastructure_buffer_ptr);
for (int config = 0; config < 15; ++config) {
......@@ -188,31 +210,14 @@ namespace glare
const unsigned begin_count = m_face_widths[unsigned(begin_face) % 3] * m_face_heights[unsigned(begin_face) % 3];
const unsigned end_count = m_face_widths[unsigned(end_face) % 3] * m_face_heights[unsigned(end_face) % 3];
//An offset length with which the generator ray will be offset backwards to assure intersecting all possible faces.
const float ray_bias = 1e-2f;
m_construction_shader->use();
m_construction_shader->uniform("u_begin_face", unsigned(begin_face));
m_construction_shader->uniform("u_end_face", unsigned(end_face));
m_construction_shader->uniform("u_begin_count", unsigned(begin_count));
m_construction_shader->uniform("u_end_count", unsigned(end_count));
m_construction_shader->uniform("ray_bias", ray_bias);
m_construction_shader->uniform("u_bounds.min", m_bounds.min);
m_construction_shader->uniform("u_bounds.max", m_bounds.max);
m_construction_shader->uniform("u_subdivisions", m_subdivision.resolution);
m_construction_shader->uniform("u_subdivisions_size", m_subdivision.size);
m_construction_shader->storageBuffer("line_buffer", m_line_buffer);
for (int i = 0; i < 15; ++i) {
m_construction_shader->uniform("u_offsets[" + std::to_string(i) + "]", unsigned(m_offsets[i]));
}
auto mesh = collector.makeMesh(0);
m_construction_shader->uniform("u_mesh.triangles", mesh.triangle_buffer_ptr);
m_construction_shader->uniform("u_mesh.id", mesh.id);
m_construction_shader->uniform("u_mesh.vertices", mesh.vertex_buffer_ptr);
m_construction_shader->uniform("u_mesh.nodes", mesh.datastructure_buffer_ptr);
/* glProgramUniform1f(m_construction_shader->id(), m_construction_shader->uniformLocation("u_subdivisions_size"), m_subdivision.size);
glFinish();
glProgramUniform3ui(m_construction_shader->id(), m_construction_shader->uniformLocation("u_subdivisions"), m_subdivision.resolution.x, m_subdivision.resolution.y, m_subdivision.resolution.z);
glFinish();*/
m_construction_shader->dispatch1d(begin_count * end_count, 1024);
}
......
......@@ -45,11 +45,21 @@ namespace glare
};
};
struct bla
{
int i;
void operator=(int b)
{
i = b;
}
};
struct Line
{
//hit triangle id's
int nearest;
int farthest;
bla nearest;
bla farthest;
};
const glm::uvec3 face_width_axises = { 2, 2, 0 };
......
......@@ -58,7 +58,7 @@ namespace glare
m_triangle_buffer->makeResident(gl::Access::eReadOnly);
if (!m_linespace)
m_linespace = std::make_shared<AngularLinespace>();
m_linespace = std::make_shared<Linespace>();
m_linespace->generate(*this, files::asset("preferences/linespace_default.xml"));
......
......@@ -12,7 +12,7 @@ namespace glare
{
namespace raytrace
{
class LineSpace;
class Linespace;
class AngularLinespace;
/**
* @brief The LocalCollector is used to apply a datastructure to any given mesh and provide buffers for raytracing.
......@@ -57,7 +57,7 @@ namespace glare
glm::mat4 m_transform;
std::shared_ptr<LocalBVH> m_bvh;
std::shared_ptr<AngularLinespace> m_linespace;
std::shared_ptr<Linespace> m_linespace;
std::vector<math::Vertex> m_vertices;
std::vector<raytrace::TriangleIDs> m_triangles;
......
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