Commit 12be8967 authored by Johannes Braun's avatar Johannes Braun
Browse files

Finally fixed the border-wall-issue

parent 24753245
......@@ -20,7 +20,7 @@ uniform struct
bool u_random_subpixel; //defaults to false.
} settings;
void generate(int id, int pixels);
void generate(int id, ivec2 pixels);
void trace(int id);
void resetImportance(int id);
......@@ -31,14 +31,14 @@ void main()
return;
int id = target_size.x * int(gl_GlobalInvocationID.y) + int(gl_GlobalInvocationID.x);
generate(id, target_size.x * target_size.y);
generate(id, target_size);
trace(id);
resetImportance(id);
}
void generate(int id, int pixels)
void generate(int id, ivec2 pixels)
{
traces_data[id].ray = u_camera.getRayFromPixel(vec2(gl_GlobalInvocationID.xy), settings.u_random_subpixel ? vec2(0, 0) : rand2D(random_seed + id, pixels));
traces_data[id].ray = u_camera.getRayFromPixel(vec2(gl_GlobalInvocationID.xy), settings.u_random_subpixel ? vec2(0, 0) : rand2D(random_seed + id, pixels.x*pixels.y), vec2(pixels));
}
void trace(int id)
......
......@@ -36,7 +36,7 @@ void main()
vec4 texel_01 = u_gbuffer_texture_01.imageLoad(ivec2(pixel), random_sample);
traces_data[id].ray = u_camera.getRayFromPixel(pixel, rand2D(random_seed + int(id), target_size.x * target_size.y));
traces_data[id].ray = u_camera.getRayFromPixel(pixel, rand2D(random_seed + int(id), target_size.x * target_size.y), vec2(target_size));
traces_data[id].hit.invalidate();
if (length(texel_01) != 0) {
......
......@@ -120,7 +120,7 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
//As the px and py values of the ray are floats instead of integers,
//we can extract the random sample by extracting the subpixel offset.
//That means the random sample will always have a value between (0,0) and (1,1).
vec2 random_sample = vec2(ray.px, ray.py) - ivec2(ray.px, ray.py);
vec2 random_sample = vec2(ray.px, ray.py) - ivec2(floor(ray.px), floor(ray.py));
BSDFResult bsdf_result = material.computeBSDF(random_sample, vertex, ray);
......
......@@ -68,20 +68,13 @@ void expand(inout Bounds bounds, const in vec3 include)
vec3 localToWorld(const in vec3 vector, const in vec3 normal) {
// Find an axis that is not parallel to normal
vec3 majorAxis;
majorAxis = normalize(mix(vec3(0, 1, 0), vec3(0, 0, 1), abs(dot(normal, vec3(0, 1, 0)))));
// Use majorAxis to create a coordinate system relative to world space
vec3 u = normalize(cross(normal, majorAxis));
vec3 pseudo_perpendicular = (abs(normal.x) <= 0.6f) ? vec3(1, 0, 0) : vec3(0, 1, 0);
vec3 u = normalize(cross(normal, pseudo_perpendicular));
vec3 v = cross(normal, u);
vec3 w = normal;
// Transform from local coordinates to world coordinates
return normalize(u * vector.x +
v * vector.y +
w * vector.z
);
return normalize(u * vector.x + v * vector.y + w * vector.z);
}
#endif //!INCLUDE_UTIL_GEOMETRY_GLSL
......@@ -3,6 +3,7 @@
#include <util/math/constants.glsl>
#include <util/tracing/tracing.glsl>
#include <util/math/random.glsl>
////////////////////////////////////////////////////////////////////
////
......@@ -42,24 +43,22 @@ void depthOfField(const in Camera camera, inout Ray ray, const in vec2 random)
ray.direction = normalize(focus - ray.origin);
}
Ray getRayFromPixel(const in Camera camera, const in vec2 pixel, const in vec2 sub_pixel)
Ray getRayFromPixel(const in Camera camera, const in vec2 pixel, const in vec2 sub_pixel, const in vec2 pixel_count)
{
// Correct subpixel offset for an overall smoother image.
const float sub_pixel_correction = sqrt(2);
const vec2 sub_pixel_offset = 2*sub_pixel - 1;
// Take a direction jittering that is different from the subpixel offset. Otherwise it will result in weirdness.
const vec2 directional_offset = rand2D(int(pixel.x + pixel.y * pixel_count.x), int(pixel_count.x*pixel_count.y));
Ray ray;
ray.origin = camera.position;
ray.direction = camera.bottom_left +
(pixel.x + sub_pixel_offset.x) * camera.axis_x_scaled +
(pixel.y + sub_pixel_offset.y) * camera.axis_y_scaled -
(pixel.x + directional_offset.x) * camera.axis_x_scaled +
(pixel.y + directional_offset.y) * camera.axis_y_scaled -
camera.position;
vec2 final_pixel = pixel + sub_pixel;
ray.px = final_pixel.x;
ray.py = final_pixel.y;
camera.depthOfField(ray, sub_pixel_offset);
camera.depthOfField(ray, directional_offset);
return ray;
}
......
......@@ -149,6 +149,7 @@ namespace glare
std::vector<T> out(count);
memcpy(out.data(), map(count, offset, gl::BufferMapBit::eRead), count * sizeof(T));
unmap();
return out;
}
template<gl::BufferType TBuffer>
......
......@@ -153,7 +153,7 @@ namespace glare
m_trace_buffer->reserve<Trace>(width * height, gl::BufferUsage::eDynamicCopy);
m_render_target = std::make_unique<core::TextureRGBA_32F>(width, height);
m_color_store = std::make_unique<core::TextureRGBA_32F>(width, height);
m_render_shader->uniform("u_render_target", m_render_target->makeImageResident(gl::Access::eReadWrite));
m_render_shader->uniform("u_color_store", m_color_store->makeImageResident(gl::Access::eReadWrite));
m_render_shader->storageBuffer("trace_buffer", *m_trace_buffer);
......@@ -178,7 +178,7 @@ namespace glare
const static std::unique_ptr<RayGenerator> ray_generator = std::make_unique<RayGenerator>();
ray_generator->generate(*this);
m_render_shader->use();
m_render_shader->uniform("u_render_config.current_sample", m_render_config.current_sample);
m_render_shader->dispatch2d(width, 4, height, 4);
......@@ -366,8 +366,8 @@ namespace glare
}
float Pathtracer::getClampDirect() const
{
return m_render_config.clamp_direct;
{
return m_render_config.clamp_direct;
}
void Pathtracer::setClampIndirect(float clamp_indirect)
......@@ -376,8 +376,8 @@ namespace glare
}
float Pathtracer::getClampIndirect() const
{
return m_render_config.clamp_indirect;
{
return m_render_config.clamp_indirect;
}
void Pathtracer::setAccuracyThreshold(float accuracy_threshold)
......@@ -386,8 +386,8 @@ namespace glare
}
float Pathtracer::getAccuracyThreshold() const
{
return m_linespace_config.accuracy_threshold;
{
return m_linespace_config.accuracy_threshold;
}
void Pathtracer::setShadowThreshold(float shadow_threshold)
......@@ -396,8 +396,8 @@ namespace glare
}
float Pathtracer::getShadowThreshold() const
{
return m_linespace_config.shadow_threshold;
{
return m_linespace_config.shadow_threshold;
}
void Pathtracer::setDistanceThreshold(float distance_threshold)
......@@ -407,7 +407,7 @@ namespace glare
float Pathtracer::getDistanceThreshold() const
{
return m_linespace_config.distance_threshold;
return m_linespace_config.distance_threshold;
}
}
}
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