Commit 2cfa322d authored by unknown's avatar unknown
Browse files

Did something.

parent d7c97bd8
......@@ -148,11 +148,11 @@ struct Mesh
struct TraceProperties
{
float accuracy_importance;
float accuracy_importance;
float shadow_importance;
uint bounce_amount;
//Just to give the struct a good padding
uint prop_unused_01;
uint prop_unused_02;
};
......@@ -165,6 +165,16 @@ struct Trace
TraceProperties properties;
};
uint getBounceAmount(const in Trace trace, uint id)
{
return (trace.properties.bounce_amount >> (4*id)) & 0xF;
}
void addBounceAmount(inout Trace trace, uint id, uint amount)
{
trace.properties.bounce_amount += (amount & 0xF) << (4*id);
}
struct Photon
{
vec4 position;
......
......@@ -47,4 +47,5 @@ void resetImportance(int id)
{
b_traces[id].properties.accuracy_importance = 1.f;
b_traces[id].properties.shadow_importance = 1.f;
b_traces[id].properties.bounce_amount = 0;
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ void resetImportance(uint id)
{
b_traces[id].properties.accuracy_importance = 1.f;
b_traces[id].properties.shadow_importance = 1.f;
b_traces[id].properties.bounce_amount = 0;
}
void main()
......
......@@ -34,8 +34,15 @@ uniform struct LinespaceProperties
{
float accuracy_quality;
float shadow_quality;
uint bounce_count_thresholds;
} u_linespace_properties;
uint getBounceThreshold(uint id)
{
return (u_linespace_properties.bounce_count_thresholds >> (4*id)) & 0xF;
}
//In this texture, the colors will all just be added up. The final render target color is then the
//color value of this texture divided by the current sample count.
layout(rgba32f) volatile uniform image2D u_color_store;
......@@ -98,7 +105,16 @@ bool shade(int id, inout vec3 radiance, uint bounce)
float pdf;
vec3 light_influence;
Ray out_ray;
vec3 reflectance = material.sampleBSDF(random_sample, vertex, ray, out_ray, light_influence, pdf);
uint bsdf_id;
vec3 reflectance = material.sampleBSDF(random_sample, vertex, ray, out_ray, light_influence, pdf, bsdf_id);
b_traces[id].addBounceAmount(bsdf_id, 1);
if(b_traces[id].getBounceAmount(bsdf_id) > getBounceThreshold(bsdf_id))
{
b_traces[id].hit.invalidate();
return false;
}
if(out_ray.direction == vec3(0))
{
......
......@@ -7,7 +7,7 @@
#include <raytracer/properties/ray_transform.glh>
#include <raytracer/properties/fresnel.glh>
vec3 sampleDiffuse(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleDiffuse(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
bool entering = dot(-ray_in.direction.xyz, vertex.normal.xyz) > 0.f;
vec3 hemi = randCosineHemisphere(random.x, random.y);
......@@ -15,6 +15,8 @@ vec3 sampleDiffuse(const in Material material, const in vec2 random, const in Ve
ray_out.direction.xyz = normalize(localToWorldNormal(entering ? hemi : -hemi, vertex.normal.xyz));
pdf = abs(dot(vec4(ray_out.direction, 0), vertex.normal)) * ONE_OVER_PI;
bsdf_id = 0;
if (pdf == 0.f)
{
return vec3(0.f);
......@@ -29,7 +31,7 @@ vec3 sampleDiffuse(const in Material material, const in vec2 random, const in Ve
return diffuse * ONE_OVER_PI;
}
vec3 sampleTranslucent(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleTranslucent(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
bool entering = dot(-ray_in.direction, vertex.normal.xyz) > 0.f;
vec3 hemi = randCosineHemisphere(random.x, random.y);
......@@ -38,6 +40,8 @@ vec3 sampleTranslucent(const in Material material, const in vec2 random, const i
pdf = abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI;
ray_out.origin = vertex.position.xyz + 1e-5f * ray_in.direction;
bsdf_id = 1;
if (pdf == 0.f)
{
......@@ -55,7 +59,7 @@ vec3 sampleTranslucent(const in Material material, const in vec2 random, const i
return diffuse * ONE_OVER_PI;
}
vec3 sampleGlass(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleGlass(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
//Needed parameters for refraction and reflection
bool entering = dot(-ray_in.direction, vertex.normal.xyz) > 0.f;
......@@ -76,15 +80,20 @@ vec3 sampleGlass(const in Material material, const in vec2 random, const in Vert
pdf = 1.0f - fresnel;
vec3 ft = diffuse*material.getTransparent(vertex.texcoord).rgb * (1.0f - fresnel);
ft *= ( eta_i * eta_i ) / ( eta_t * eta_t );
bsdf_id = 3;
return ft / abs(dot(ray_out.direction, vertex.normal.xyz));
}
bsdf_id = 2;
ray_out.direction = reflect(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz));
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
pdf = fresnel;
return fresnel * material.getSpecular(vertex.texcoord).rgb / abs(dot(ray_out.direction, vertex.normal.xyz));
}
vec3 sampleRoughGlass(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleRoughGlass(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
//Needed parameters for refraction and reflection
bool entering = dot(-ray_in.direction, vertex.normal.xyz) > 0.f;
......@@ -118,6 +127,8 @@ vec3 sampleRoughGlass(const in Material material, const in vec2 random, const in
ft *= ( eta_i * eta_i ) / ( eta_t * eta_t );
bsdf_id = 3;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
return mix(ft / abs(dot(ray_out.direction, vertex.normal.xyz)), diffuse * ONE_OVER_PI, roughness);
}
......@@ -131,33 +142,38 @@ vec3 sampleRoughGlass(const in Material material, const in vec2 random, const in
{
ray_out.direction.xyz = localToWorldNormal(sampledPoint * vec3(-1, -1, 1), reflected);
}
bsdf_id = 2;
pdf = mix(fresnel, abs(dot(ray_out.direction, vertex.normal.xyz)) * ONE_OVER_PI, roughness);
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
return mix(fresnel * material.getSpecular(vertex.texcoord).rgb / abs(dot(ray_out.direction, vertex.normal.xyz)), diffuse * ONE_OVER_PI, roughness);
}
vec3 sampleTransparent(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleTransparent(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
//refract ray.
ray_out.direction = ray_in.direction;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
pdf = 1;
bsdf_id = 4;
light_influence = vec3(0);
return material.getTransparent(vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz));
}
vec3 sampleMirror(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleMirror(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
pdf = 1.f;
ray_out.direction = reflect(ray_in.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz));
light_influence = vec3(0);
bsdf_id = 2;
ray_out.origin = vertex.position.xyz + 1e-5 * ray_out.direction;
return material.getSpecular(vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz));
}
vec3 sampleGlossy(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleGlossy(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
float roughness = material.getRoughness();
float rad = radians(180.0f - (1.0f - roughness) * 180.0f);
......@@ -169,6 +185,8 @@ vec3 sampleGlossy(const in Material material, const in vec2 random, const in Ver
ray_out.direction.xyz = normalize(localToWorldNormal(sampledPoint, reflected));
bsdf_id = 2;
if (dot(ray_out.direction, faceforward(vertex.normal.xyz, ray_in.direction, vertex.normal.xyz)) < 0.0f)
{
ray_out.direction.xyz = normalize(localToWorldNormal(sampledPoint * vec3(-1, -1, 1), reflected));
......@@ -180,8 +198,9 @@ vec3 sampleGlossy(const in Material material, const in vec2 random, const in Ver
return mix(diffuse*material.getSpecular(vertex.texcoord).xyz / abs(dot(ray_out.direction, vertex.normal.xyz)), diffuse * ONE_OVER_PI, roughness);
}
vec3 sampleEmissive(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleEmissive(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
bsdf_id = 5;
pdf = 1.f;
ray_out.direction = vec3(0);
vec3 diffuse = material.getDiffuse(vertex.texcoord).xyz;
......@@ -199,7 +218,7 @@ const uint eTransparentDiffuse = 1 << 10;
const uint eTransparent = 1 << 11;
const uint eEmissive = 1 << 16;
vec3 sampleBSDF(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf)
vec3 sampleBSDF(const in Material material, const in vec2 random, const in Vertex vertex, const in Ray ray_in, inout Ray ray_out, out vec3 light_influence, out float pdf, out uint bsdf_id)
{
//Kind of crude but also kind of well functional bsdf selector.
ray_out.px = ray_in.px;
......@@ -221,21 +240,21 @@ vec3 sampleBSDF(const in Material material, const in vec2 random, const in Verte
{
default:
case eGlossy:
return material.sampleGlossy(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleGlossy(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
case eMirror:
return material.sampleMirror(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleMirror(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
case eDiffuse:
return material.sampleDiffuse(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleDiffuse(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
case eTransparentGlossy:
return material.sampleRoughGlass(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleRoughGlass(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
case eTransparentMirror:
return material.sampleGlass(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleGlass(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
case eTransparentDiffuse:
return material.sampleTranslucent(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleTranslucent(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
case eTransparent:
return material.sampleTransparent(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleTransparent(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
case eEmissive:
return material.sampleEmissive(random, vertex, ray_in, ray_out, light_influence, pdf);
return material.sampleEmissive(random, vertex, ray_in, ray_out, light_influence, pdf, bsdf_id);
}
}
......
<settings>
<item name="fxaa">0</item>
<item name="window_size_x">800</item>
<item name="window_size_y">600</item>
<item name="window_size_x">1280</item>
<item name="window_size_y">720</item>
<item name="vsync">0</item>
<item name="msaa_samples">4</item>
......
......@@ -49,22 +49,19 @@ namespace glare
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/ryfjallet/")));
float lsprop_accuracy = 0.5f;
float lsprop_shadow = 0.2f;
// BENCHMARKS
//initializeScene(m_current_scene_root / "benchmark_single_quad_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_single_cube_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_suzanne_x1_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_suzanne_x2_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_teapot_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
// initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_armadillo_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_dragon_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_asian_dragon_diff.dae", 1.f);
// ARTIFACT CHECK (GLASS)
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_0r.dae", 1.f);
initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_0r.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_25r.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_50r.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_75r.dae", 1.f);
......@@ -81,7 +78,7 @@ namespace glare
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_emissive.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_transparent.dae", 1.f);
initializeScene(m_current_scene_root / "floored_bunny.dae", 1.f);
// initializeScene(m_current_scene_root / "boxes.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
initializeGUI();
......
......@@ -99,6 +99,20 @@ namespace glare
m_render_shader->updateUniformFloat("u_linespace_properties.accuracy_quality", m_linespace_config.accuracy_threshold);
m_render_shader->updateUniformFloat("u_linespace_properties.shadow_quality", m_linespace_config.shadow_threshold);
m_bounce_count_thresholds[unsigned(EffectType::eDiffuse)] = 4;
m_bounce_count_thresholds[unsigned(EffectType::eTranslucent)] = 6;
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;
unsigned bounce_thresholds = 0;
for (int i = 0; i < 8; ++i)
{
bounce_thresholds |= (m_bounce_count_thresholds[i] & 0xf) << (4 * i);
}
m_render_shader->updateUniformUInt("u_linespace_properties.bounce_count_thresholds", bounce_thresholds);
m_render_shader->dispatchCompute2D(width, 4, height, 4);
++m_render_config.current_sample;
......
......@@ -5,6 +5,7 @@
#include <engine/rendering/GraphNode.h>
#include <engine/graphics/Skybox.h>
#include <filesystem>
#include <array>
#include <io/ImageUtilities.h>
#include "RayGenerator.h"
#include <advanced/meshlocal/LocalCollector.h>
......@@ -16,6 +17,16 @@ namespace glare
{
namespace fs = std::experimental::filesystem;
enum class EffectType
{
eDiffuse = 0,
eTranslucent = 1,
eReflection = 2,
eRefraction = 3,
eTransparent = 4,
eEmissive = 5
};
class Raytracer : public core::MessageReceiver
{
public:
......@@ -117,6 +128,9 @@ namespace glare
float shadow_threshold;
} m_linespace_config;
std::array<uint8_t, 8> m_bounce_count_thresholds;
std::shared_ptr<SceneCollector> m_collector;
std::unique_ptr<core::TextureRGBA_32F> m_render_target;
std::unique_ptr<core::TextureRGBA_32F> m_color_store;
......
......@@ -465,10 +465,8 @@ namespace glare
Shader::Shader(gl::ShaderType shader_type, fs::path path)
: Shader(shader_type)
{
const std::string source = loadSource((asset("/shaders/")) / path);
compileSource(source);
const auto raw = (asset("/shaders/")) / path;
compileSource(loadSource(raw));
}
void Shader::compileSource(const std::string &source)
......
......@@ -78,11 +78,12 @@ namespace glare
void ShaderProgram::use() const
{
int32_t id;
/*int32_t id;
gl::getIntegerv(gl::GetParameter::eCurrentProgram, &id);
if(id != m_handle)
gl::useProgram(m_handle);
if(id != m_handle)*/
gl::useProgram(m_handle);
}
void ShaderProgram::updateStorageBuffer(const std::string &var_name, const std::unique_ptr<Buffer<gl::BufferType::eShaderStorage>> &buffer) const
......
......@@ -24,7 +24,7 @@ namespace glare
unsigned goodSubdivision(size_t polygon_count, glm::vec3 bounds_size)
{
return 20;// io::Resources::getInstance().getPreferences("default")->get<unsigned>("linespace_max_resolution", 16);// unsigned(2 * glm::ceil(glm::log2(glm::max(size_t(2), polygon_count)) * glm::log(log2((glm::compMax(bounds_size) / glm::compMin(bounds_size)) + 2 * glm::e<float>()))));
return 64;// io::Resources::getInstance().getPreferences("default")->get<unsigned>("linespace_max_resolution", 16);// unsigned(2 * glm::ceil(glm::log2(glm::max(size_t(2), polygon_count)) * glm::log(log2((glm::compMax(bounds_size) / glm::compMin(bounds_size)) + 2 * glm::e<float>()))));
}
}
......@@ -71,15 +71,15 @@ namespace glare
core::ClockMS clock;
switch (m_generator)
{
switch (m_generator)
{
default:
case Generator::eCPU:
generateCPU(collector);
break;
case Generator::eGPU:
generateGPU(collector);
break;
break;
case Generator::eGPU:
generateGPU(collector);
break;
}
m_line_buffer.makeResident(gl::Access::eReadOnly);
......
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