Commit 13305151 authored by Johannes Braun's avatar Johannes Braun
Browse files

Reduced number of effects to be set up to fit bsdf model

parent cbfc9266
<pathtracer version="1.0">
<group name="bounces">
<item name="diffuse" value="4"/>
<item name="translucent" value="4"/>
<item name="reflect" value="5"/>
<item name="refract" value="8"/>
<item name="transparent" value="9"/>
<item name="emissive" value="1"/>
<item name="diffusion" value="5"/>
<item name="reflection" value="6"/>
<item name="transmission" value="10"/>
<item name="emission" value="1"/>
</group>
<group name="ls-thresholds">
<item name="diffuse" value="4"/>
<item name="translucent" value="4"/>
<item name="reflect" value="5"/>
<item name="refract" value="8"/>
<item name="transparent" value="9"/>
<item name="emissive" value="1"/>
<item name="diffusion" value="3"/>
<item name="reflection" value="3"/>
<item name="transmission" value="3"/>
<item name="emission" value="1"/>
<item name="accuracy" value="0.4"/>
<item name="shadow" value="0.04"/>
......
......@@ -44,22 +44,22 @@ uniform struct
uint getBounceAmount(const in Trace trace, uint id)
{
return (trace.properties.bounce_amount >> (4*id)) & 0xF;
return (trace.properties.bounce_amount >> (8*id)) & 0xFF;
}
void addBounceAmount(inout Trace trace, uint id, uint amount)
{
trace.properties.bounce_amount += (amount & 0xF) << (4*id);
trace.properties.bounce_amount += (amount & 0xFF) << (8*id);
}
uint getLSBounceThreshold(uint id)
{
return (u_linespace_properties.bounce_thresholds >> (4*id)) & 0xF;
return (u_linespace_properties.bounce_thresholds >> (8*id)) & 0xFF;
}
uint getBounceThreshold(uint id)
{
return (u_render_config.bounce_thresholds >> (4*id)) & 0xF;
return (u_render_config.bounce_thresholds >> (8*id)) & 0xFF;
}
//////////////////////////////////////////////////////////////////////////
......
......@@ -50,7 +50,7 @@ int main(int argc, char* argv[])
// Sun light source
auto sun_node = std::make_shared<core::GraphNode>("light_sun");
sun_node->transform()->rotate({ glm::radians(80.f), 0, 0 });
auto light_sun = sun_node->makeComponent<core::LightComponent>(color::rgba32f{ 0.4f, 0.4f, 0.4f, 1.f }, core::Attenuation{ 1,0,0 }, core::LightParameters::makeDirectionalLight());
auto light_sun = sun_node->makeComponent<core::LightComponent>(color::rgba32f{ 0.4f, 0.4f, 0.4f, 1.f }, core::Attenuation{ 1,0,0 }, core::LightParameters::makeDirectionalLight(0.1f));
// Make Environment lighting node
auto lighting_node = std::make_shared<core::GraphNode>("environment");
......
......@@ -253,13 +253,12 @@ namespace glare
std::shared_ptr<core::Material> Map::makeMaterial()
{
std::shared_ptr<core::Material> material = std::make_shared<core::Material>("terrain");
material->color_diffuse = color::preset::white.rgb;
material->color_specular = 2 * color::preset::white.rgb;
material->specular_exponent = 80;
material->map_diffuse = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048.png"));
material->base.value = color::preset::white.rgb;
material->roughness.value = 0.2f;
material->base.texture = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048.png"));
material->map_normal = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_n.png"));
material->map_displacement = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_h.png"));
material->map_specular = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_s.png"));
material->roughness.texture = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_s.png"));
return material;
}
......
......@@ -233,16 +233,14 @@ void drawDebugGui()
static auto effectBounces = [](const std::string &label, raytrace::EffectType effect)
{
int val = pathtracer->getEffectBounces(effect);
if (ImGui::DragInt(label.c_str(), &val, 0.1f, 0, 15))
if (ImGui::DragInt(label.c_str(), &val, 0.1f, 0, 255))
pathtracer->setEffectBounces(effect, uint8_t(val));
};
effectBounces("Diffuse", raytrace::EffectType::eDiffuse);
effectBounces("Translucent", raytrace::EffectType::eTranslucent);
effectBounces("Reflective", raytrace::EffectType::eReflection);
effectBounces("Refractive", raytrace::EffectType::eRefraction);
effectBounces("Transparency", raytrace::EffectType::eTransparent);
effectBounces("Emissive", raytrace::EffectType::eEmissive);
effectBounces("Diffusion", raytrace::EffectType::eDiffusion);
effectBounces("Reflection", raytrace::EffectType::eReflection);
effectBounces("Transmission", raytrace::EffectType::eTransmission);
effectBounces("Emission", raytrace::EffectType::eEmission);
ImGui::TreePop();
}
}
......@@ -293,12 +291,10 @@ void drawDebugGui()
pathtracer->setLinespaceBounceThresholds(effect, uint8_t(val));
};
bounceControl("Diffuse", raytrace::EffectType::eDiffuse);
bounceControl("Translucent", raytrace::EffectType::eTranslucent);
bounceControl("Reflective", raytrace::EffectType::eReflection);
bounceControl("Refractive", raytrace::EffectType::eRefraction);
bounceControl("Transparence", raytrace::EffectType::eTransparent);
bounceControl("Emissive", raytrace::EffectType::eEmissive);
bounceControl("Diffusion", raytrace::EffectType::eDiffusion);
bounceControl("Reflection", raytrace::EffectType::eReflection);
bounceControl("Transmission", raytrace::EffectType::eTransmission);
bounceControl("Emission", raytrace::EffectType::eEmission);
}
}
......
......@@ -12,42 +12,7 @@
namespace glare
{
namespace raytrace
{
enum class BVHNodeType
{
eInner = 0,
eLeaf = 1
};
struct bvh_node_t
{
math::Bounds bounds;
BVHNodeType type;
//Children, can be either child nodes or array start- and end indices.
uint32_t left_idx;
uint32_t right_idx;
//Parent
uint32_t parent;
};
struct index_range_t
{
uint32_t start;
uint32_t end;
uint32_t parent; //Parent node index
uint32_t padding;
};
/**
* Bins are used in the split(...) method of the MeshBVH for the Binned SAH Split algorithm.
*/
struct bin_t
{
math::Bounds bounds;
int object_count;
};
{
/**
* @brief An abstraction class for the huge, but well reusable parts of a BVH. Included are a construction algorithm based on the binned SAH split, as well as a stackless traversal method.
......@@ -55,7 +20,44 @@ namespace glare
template<typename TPrimitive>
class BVH
{
public:
public:
struct Node
{
enum class Type
{
eInner = 0,
eLeaf = 1
};
math::Bounds bounds;
Type type;
//Children, can be either child nodes or array start- and end indices.
uint32_t left_idx;
uint32_t right_idx;
//Parent
uint32_t parent;
};
struct IndexRange
{
uint32_t start;
uint32_t end;
uint32_t parent; //Parent node index
uint32_t padding;
};
/**
* Bins are used in the split(...) method of the MeshBVH for the Binned SAH Split algorithm.
*/
struct Bin
{
math::Bounds bounds;
int object_count;
};
BVH() {};
~BVH() {};
......@@ -65,7 +67,7 @@ namespace glare
* @param centroid_from_id A function that should return a centroid coordinate for the parameter id (referring to the index in the primitive list).
* @param node_from_range A function that builds a bvh_node_t containing all primitives from index "start" to index "end".
*/
void build(std::vector<TPrimitive> &primitives, std::function<glm::vec4(int id)> centroid_from_id, std::function<bvh_node_t(int start, int end)> node_from_range);
void build(std::vector<TPrimitive> &primitives, std::function<glm::vec4(int id)> centroid_from_id, std::function<Node(int start, int end)> node_from_range);
/**
* @brief The stackless traversal, also based on parameter functions for core functionality.
......@@ -77,13 +79,13 @@ namespace glare
bool traverse(const Ray &ray, float max_distance, bool finish_after_hit, std::function<bool(const Ray &ray, float max_distance, bool finish_after_hit, int primitive_id)> check_traversal_primitive) const;
const core::Buffer<gl::BufferType::eShaderStorage>& buffer() const;
const std::vector<bvh_node_t> &nodes() const;
const std::vector<Node> &nodes() const;
private:
void reset(std::vector<TPrimitive> &primitives);
void split(std::vector<TPrimitive> &primitives, uint32_t global_id);
std::function<bvh_node_t(int start, int end)> m_node_from_range;
std::function<Node(int start, int end)> m_node_from_range;
std::function<glm::vec4(int id)> m_centroid_from_id;
const int32_t m_bin_count = 16;
......@@ -92,12 +94,12 @@ namespace glare
core::Buffer<gl::BufferType::eShaderStorage> m_node_buffer;
std::vector<bvh_node_t> m_nodes;
std::vector<Node> m_nodes;
std::vector<math::Bounds> m_centroid_boxes;
std::vector<math::Bounds> m_safe_centroid_boxes;
std::vector<index_range_t> m_ranges;
std::vector<index_range_t> m_safe_ranges;
std::vector<IndexRange> m_ranges;
std::vector<IndexRange> m_safe_ranges;
std::vector<glm::vec4> m_centroids;
std::atomic_int m_buffer_position;
......@@ -116,7 +118,7 @@ namespace glare
}
template<typename TPrimitive>
const std::vector<bvh_node_t> &BVH<TPrimitive>::nodes() const
const std::vector<typename BVH<TPrimitive>::Node> &BVH<TPrimitive>::nodes() const
{
return m_nodes;
}
......@@ -166,7 +168,7 @@ namespace glare
}
template<typename TPrimitive>
void BVH<TPrimitive>::build(std::vector<TPrimitive> &primitives, std::function<glm::vec4(int id)> centroid_from_id, std::function<bvh_node_t(int start, int end)> node_from_range)
void BVH<TPrimitive>::build(std::vector<TPrimitive> &primitives, std::function<glm::vec4(int id)> centroid_from_id, std::function<Node(int start, int end)> node_from_range)
{
m_centroid_from_id = centroid_from_id;
m_node_from_range = node_from_range;
......@@ -240,8 +242,8 @@ namespace glare
//inner node
//pos is the position in which the new ranges will be stored
int range_index = m_buffer_position.fetch_add(1);
index_range_t left_range;
index_range_t right_range;
IndexRange left_range;
IndexRange right_range;
math::Bounds left_centbox;
math::Bounds right_centbox;
......@@ -250,10 +252,10 @@ namespace glare
m_kernel_counter.fetch_add(2);
// 1. the AABB which contains the range's triangle information is added for later processing (traversal)
bvh_node_t node = m_node_from_range(start, end);
Node node = m_node_from_range(start, end);
// 0 is the flag for inner node in the node buffer
node.type = BVHNodeType::eInner;
node.type = Node::Type::eInner;
// 2. the split plane which causes the least cost is determined by iterating over the 3 axes (since it's axis aligned)
struct {
......@@ -266,7 +268,7 @@ namespace glare
for (int axis = 0; axis < 3; ++axis)
{
bin_t bins[16];
Bin bins[16];
const float cbox_min = centroid_box.min[axis];
const float cbox_max = centroid_box.max[axis];
const float cbox_diff = cbox_max - cbox_min;
......@@ -289,7 +291,7 @@ namespace glare
++(bins[bin_id].object_count);
}
bin_t left_bounds[15];
Bin left_bounds[15];
//Again, initialize all bounds.
for (int i = 0; i < m_plane_count; ++i)
{
......@@ -307,7 +309,7 @@ namespace glare
left_bounds[plane].object_count = left_bounds[plane - 1].object_count + bins[plane].object_count;
}
bin_t right_bounds[15];
Bin right_bounds[15];
//Again and again, initialize bounds.
for (int i = 0; i < m_plane_count; ++i)
{
......@@ -447,8 +449,8 @@ namespace glare
}
else //leaf node
{
bvh_node_t node = m_node_from_range(start, end);
node.type = BVHNodeType::eLeaf;
Node node = m_node_from_range(start, end);
node.type = Node::Type::eLeaf;
node.left_idx = start;
node.right_idx = end;
node.parent = parent;
......@@ -481,7 +483,7 @@ namespace glare
//if (hit_scene){
while (hit_scene)
{
if (m_nodes[current_node].type == BVHNodeType::eInner) //Inner node.
if (m_nodes[current_node].type == Node::Type::eInner) //Inner node.
{
const int id_left = int(m_nodes[current_node].left_idx);
const bool hit_left = intersect::intersects(ray, m_nodes[id_left].bounds, max_distance);
......
......@@ -132,7 +132,7 @@ namespace glare
return (m_local_collectors[mesh_id]->transform() * glm::vec4(m_local_collectors[mesh_id]->bounds().min.xyz, 1) +
m_local_collectors[mesh_id]->transform() * glm::vec4(m_local_collectors[mesh_id]->bounds().max.xyz, 1)) / 2.f;
}, [&](int start, int end) {
bvh_node_t node;
BVH<unsigned>::Node node;
glm::vec4 best_min = glm::vec4(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), 1.0f);
glm::vec4 best_max = glm::vec4(std::numeric_limits<float>::lowest(), std::numeric_limits<float>::lowest(), std::numeric_limits<float>::lowest(), 1.0f);
node.bounds.min = best_min;
......
......@@ -33,7 +33,7 @@ namespace glare
+ vertices[triangle.indices[2]].position)
/ 3.f;
}, [&](int start, int end) {
bvh_node_t node;
BVH<TriangleIDs>::Node node;
glm::vec4 best_min = glm::vec4(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), 1.0f);
glm::vec4 best_max = glm::vec4(std::numeric_limits<float>::lowest(), std::numeric_limits<float>::lowest(), std::numeric_limits<float>::lowest(), 1.0f);
for (int id = start; id <= end; id++)
......
......@@ -41,19 +41,15 @@ namespace glare
Pathtracer::Pathtracer(std::shared_ptr<SceneCollector> collector, RayGeneratorType ray_generator)
{
m_bounce_count_thresholds[unsigned(EffectType::eDiffuse)] = 4;
m_bounce_count_thresholds[unsigned(EffectType::eTranslucent)] = 6;
m_bounce_count_thresholds[unsigned(EffectType::eDiffusion)] = 4;
m_bounce_count_thresholds[unsigned(EffectType::eReflection)] = 6;
m_bounce_count_thresholds[unsigned(EffectType::eRefraction)] = 12;
m_bounce_count_thresholds[unsigned(EffectType::eTransparent)] = 12;
m_bounce_count_thresholds[unsigned(EffectType::eEmissive)] = 0;
m_bounce_count_thresholds[unsigned(EffectType::eTransmission)] = 12;
m_bounce_count_thresholds[unsigned(EffectType::eEmission)] = 1;
m_ls_bounce_count_thresholds[unsigned(EffectType::eDiffuse)] = 1;
m_ls_bounce_count_thresholds[unsigned(EffectType::eTranslucent)] = 3;
m_ls_bounce_count_thresholds[unsigned(EffectType::eDiffusion)] = 1;
m_ls_bounce_count_thresholds[unsigned(EffectType::eReflection)] = 3;
m_ls_bounce_count_thresholds[unsigned(EffectType::eRefraction)] = 6;
m_ls_bounce_count_thresholds[unsigned(EffectType::eTransparent)] = 8;
m_ls_bounce_count_thresholds[unsigned(EffectType::eEmissive)] = 0;
m_ls_bounce_count_thresholds[unsigned(EffectType::eTransmission)] = 3;
m_ls_bounce_count_thresholds[unsigned(EffectType::eEmission)] = 6;
m_linespace_config.distance_threshold = 8.f;
m_render_config.bounces = 16;
......@@ -84,21 +80,17 @@ namespace glare
//bounces
const auto bounces_child = pt_child.find_child_by_attribute("group", "name", "bounces");
m_bounce_count_thresholds[unsigned(EffectType::eDiffuse)] = bounces_child.find_child_by_attribute("item", "name", "diffuse").attribute("value").as_uint(2);
m_bounce_count_thresholds[unsigned(EffectType::eTranslucent)] = bounces_child.find_child_by_attribute("item", "name", "translucent").attribute("value").as_uint(4);
m_bounce_count_thresholds[unsigned(EffectType::eReflection)] = bounces_child.find_child_by_attribute("item", "name", "reflect").attribute("value").as_uint(4);
m_bounce_count_thresholds[unsigned(EffectType::eRefraction)] = bounces_child.find_child_by_attribute("item", "name", "refract").attribute("value").as_uint(8);
m_bounce_count_thresholds[unsigned(EffectType::eTransparent)] = bounces_child.find_child_by_attribute("item", "name", "transparent").attribute("value").as_uint(8);
m_bounce_count_thresholds[unsigned(EffectType::eEmissive)] = bounces_child.find_child_by_attribute("item", "name", "emissive").attribute("value").as_uint(1);
m_bounce_count_thresholds[unsigned(EffectType::eDiffusion)] = bounces_child.find_child_by_attribute("item", "name", "diffusion").attribute("value").as_uint(2);
m_bounce_count_thresholds[unsigned(EffectType::eReflection)] = bounces_child.find_child_by_attribute("item", "name", "reflection").attribute("value").as_uint(4);
m_bounce_count_thresholds[unsigned(EffectType::eTransmission)] = bounces_child.find_child_by_attribute("item", "name", "transmission").attribute("value").as_uint(4);
m_bounce_count_thresholds[unsigned(EffectType::eEmission)] = bounces_child.find_child_by_attribute("item", "name", "emission").attribute("value").as_uint(8);
//ls thresholds
const auto ls_thresholds_child = pt_child.find_child_by_attribute("group", "name", "ls-thresholds");
m_ls_bounce_count_thresholds[unsigned(EffectType::eDiffuse)] = ls_thresholds_child.find_child_by_attribute("item", "name", "diffuse").attribute("value").as_uint(2);
m_ls_bounce_count_thresholds[unsigned(EffectType::eTranslucent)] = ls_thresholds_child.find_child_by_attribute("item", "name", "translucent").attribute("value").as_uint(4);
m_ls_bounce_count_thresholds[unsigned(EffectType::eReflection)] = ls_thresholds_child.find_child_by_attribute("item", "name", "reflect").attribute("value").as_uint(4);
m_ls_bounce_count_thresholds[unsigned(EffectType::eRefraction)] = ls_thresholds_child.find_child_by_attribute("item", "name", "refract").attribute("value").as_uint(8);
m_ls_bounce_count_thresholds[unsigned(EffectType::eTransparent)] = ls_thresholds_child.find_child_by_attribute("item", "name", "transparent").attribute("value").as_uint(8);
m_ls_bounce_count_thresholds[unsigned(EffectType::eEmissive)] = ls_thresholds_child.find_child_by_attribute("item", "name", "emissive").attribute("value").as_uint(1);
m_ls_bounce_count_thresholds[unsigned(EffectType::eDiffusion)] = ls_thresholds_child.find_child_by_attribute("item", "name", "diffusion").attribute("value").as_uint(2);
m_ls_bounce_count_thresholds[unsigned(EffectType::eReflection)] = ls_thresholds_child.find_child_by_attribute("item", "name", "reflection").attribute("value").as_uint(4);
m_ls_bounce_count_thresholds[unsigned(EffectType::eTransmission)] = ls_thresholds_child.find_child_by_attribute("item", "name", "transmission").attribute("value").as_uint(4);
m_ls_bounce_count_thresholds[unsigned(EffectType::eEmission)] = ls_thresholds_child.find_child_by_attribute("item", "name", "emission").attribute("value").as_uint(8);
m_linespace_config.accuracy_threshold = ls_thresholds_child.find_child_by_attribute("item", "name", "accuracy").attribute("value").as_float(0.5f);
m_linespace_config.shadow_threshold = ls_thresholds_child.find_child_by_attribute("item", "name", "shadow").attribute("value").as_float(0.5f);
......@@ -125,16 +117,16 @@ namespace glare
m_render_shader->uniform("u_linespace_properties.distance_threshold", m_linespace_config.distance_threshold);
unsigned bounce_thresholds = 0;
for (int i = 0; i < 8; ++i)
for (int i = 0; i < 4; ++i)
{
bounce_thresholds |= (m_bounce_count_thresholds[i] & 0xf) << (4 * i);
bounce_thresholds |= (m_bounce_count_thresholds[i] & 0xff) << (8 * i);
}
m_render_shader->uniform("u_render_config.bounce_thresholds", bounce_thresholds);
m_linespace_config.bounce_thresholds = 0;
for (int i = 0; i < 8; ++i)
for (int i = 0; i < 4; ++i)
{
m_linespace_config.bounce_thresholds |= (m_ls_bounce_count_thresholds[i] & 0xf) << (4 * i);
m_linespace_config.bounce_thresholds |= (m_ls_bounce_count_thresholds[i] & 0xff) << (8 * i);
}
m_render_shader->uniform("u_linespace_properties.bounce_thresholds", m_linespace_config.bounce_thresholds);
......
......@@ -22,12 +22,10 @@ namespace glare
enum class EffectType
{
eDiffuse = 0,
eTranslucent = 1,
eReflection = 2,
eRefraction = 3,
eTransparent = 4,
eEmissive = 5
eDiffusion = 0,
eReflection = 1,
eTransmission = 2,
eEmission = 3
};
class Pathtracer : public messaging::Receiver
......@@ -119,8 +117,8 @@ namespace glare
float distance_threshold;
} m_linespace_config;
std::array<uint8_t, 8> m_bounce_count_thresholds;
std::array<uint8_t, 8> m_ls_bounce_count_thresholds;
std::array<uint8_t, 4> m_bounce_count_thresholds;
std::array<uint8_t, 4> m_ls_bounce_count_thresholds;
std::shared_ptr<SceneCollector> m_collector;
std::unique_ptr<core::TextureRGBA_32F> m_render_target;
......
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