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

Added break in grid traversal. Needs further refinement because sometimes its endless.

parent 3a4dfe22
<linespace version="1.0">
<item name="subdivisions" value="10"/>
<item name="grid-subdivisions" value="5"/>
<item name="subdivisions" value="32"/>
<item name="grid-subdivisions" value="1"/>
<item name="radial-subdivision" value="50"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -71,6 +71,7 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
else
{
Ray local_ray = ray.makeRelative(mesh);
Bounds mesh_bounds = mesh.nodes[0].bounds;
if(local_ray.intersectsBounds(mesh_bounds, current_t))
......@@ -112,6 +113,9 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
break;
}
tnext[axis] += delta[axis];
// TODO: endless loop sometimes.
break;
}
}
}
......
......@@ -31,5 +31,5 @@ void main()
vec2 random = settings.u_random_subpixel ? vec2(0, 0) : rand2D(random_seed + id, target_size.x*target_size.y);
traces_data[id].ray = u_camera.getRayFromPixel(vec2(gl_GlobalInvocationID.xy), random, vec2(target_size));
traces_data[id].hit.invalidate();
traces_data[id].ray.nearestIntersection(traces_data[id].hit, false);
traces_data[id].ray.nearestIntersection(traces_data[id].hit, true);
}
......@@ -18,8 +18,12 @@ layout(local_size_variable) in;
//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) uniform image2D u_color_store;
layout(rgba32f) uniform image2D u_render_target;
uniform struct
{
layout(rgba32f) image2D render_target;
} textures;
uniform Environment u_environment;
uniform int random_seed;
subroutine uniform lightSample u_light_sample[4];
......@@ -149,7 +153,7 @@ bool shade(inout Bounce bounce)
// generate a random sample on each bounce so there won't be any notifiable patterns
const vec2 base_random = vec2(bounce.ray.px, bounce.ray.py) - ivec2(floor(bounce.ray.px), floor(bounce.ray.py));
const ivec2 img_size = u_render_target.imageSize();
const ivec2 img_size = textures.render_target.imageSize();
const int img_dimen = img_size.x * img_size.y;
const vec2 random_sample = rand2D((random_seed + int(gl_GlobalInvocationID.y * uint(img_size.x) + gl_GlobalInvocationID.x))%img_dimen, img_size.x * img_size.y);
......@@ -210,7 +214,7 @@ void trace(inout Bounce bounce)
void main()
{
ivec2 target_size = u_render_target.imageSize();
ivec2 target_size = textures.render_target.imageSize();
int id = target_size.x * int(gl_GlobalInvocationID.y) + int(gl_GlobalInvocationID.x);
//Discard pixel if it's not visible to avoid artifacts
......@@ -238,10 +242,10 @@ void main()
}
ivec2 pixel = ivec2(bounce.ray.px, bounce.ray.py);
vec4 color = u_render_target.imageLoad(pixel);
vec4 color = textures.render_target.imageLoad(pixel);
// Divide color storage by sample count to retrieve the final color.
// A float type render target should provide enough precision to not need a secondary color storage.
color = mix(color, vec4(bounce.color, 1), 1 / float(u_render_config.current_sample + 1));
u_render_target.imageStore(pixel, color);
textures.render_target.imageStore(pixel, color);
}
......@@ -95,6 +95,7 @@ namespace glare::core
{
int length;
std::string name;
name.resize(max_length);
gl::getActiveSubroutineName(m_handle, shader->type(), sr, max_length, &length, name.data());
name.resize(length);
SubroutineInfo info;
......
......@@ -97,7 +97,7 @@ namespace glare::raytrace
m_trace_buffer.reserve<Trace>(width * height, gl::BufferUsage::eDynamicCopy);
m_render_target = std::make_unique<core::Texture>(core::Image<float>({ static_cast<int>(width), static_cast<int>(height) }, 4));
m_render_shader->uniform("u_render_target", m_render_target->imageAddress(gl::Access::eReadWrite));
m_render_shader->uniform("textures.render_target", m_render_target->imageAddress(gl::Access::eReadWrite));
m_render_shader->storageBuffer("trace_buffer", m_trace_buffer);
m_samples_current = 0;
......
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