Commit 49327f49 authored by unknown's avatar unknown
Browse files

Fixed wrong rendering depth perception with scaled objects.

parent 101b1060
......@@ -89,10 +89,11 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
for (int i = start; i <= end; i++)
{
float current_t = t_min;
const Mesh mesh = b_meshes[b_object_ids[i]];
if(force_bvh)
{
if(mesh.traverseBVH(ray.makeMeshLocal(mesh), use_first, t_min, hit, t_min)){
if(mesh.traverseBVH(ray.makeMeshLocal(mesh), use_first, current_t, hit, t_min)){
hit_triangle = true;
if (use_first)
{
......@@ -102,7 +103,7 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
}
else
{
if(mesh.traverseLineSpace(ray.makeMeshLocal(mesh), use_first, t_min, hit, t_min)){
if(mesh.traverseLineSpace(ray.makeMeshLocal(mesh), use_first, current_t, hit, t_min)){
hit_triangle = true;
if (use_first)
{
......
......@@ -23,12 +23,10 @@ void resetImportance(int id);
void main()
{
int id = invocation2D();
ivec2 target_size = u_render_target.imageSize();
if (int(gl_GlobalInvocationID.x) >= target_size.x || int(gl_GlobalInvocationID.y) >= target_size.y)
if (!u_render_target.contains(gl_GlobalInvocationID.xy))
return;
int id = invocation2D();
generate(id);
trace(id);
resetImportance(id);
......
......@@ -10,7 +10,7 @@
bool contains(layout(rgba32f) volatile image2D img, uvec2 pixel)
{
ivec2 target_size = img.imageSize();
return int(pixel.x) < target_size.x || int(pixel.y) < target_size.y;
return int(pixel.x) < target_size.x && int(pixel.y) < target_size.y;
}
#endif //__GL_UTILS_IMAGES
\ No newline at end of file
......@@ -8,7 +8,7 @@
Ray makeMeshLocal(const in Ray ray, const in Mesh mesh)
{
Ray ray_in = ray;
ray_in.direction = normalize(mat3(mesh.inverse_transformation) * ray_in.direction.xyz);
ray_in.direction = mat3(mesh.inverse_transformation) * ray_in.direction.xyz;
ray_in.origin = (mesh.inverse_transformation * vec4(ray_in.origin.xyz, 1)).xyz;
return ray_in;
......
#include <glare_core>
#include <glare_advanced>
#include <glare_io>
using namespace glare;
int main(int argc, char* argv[])
{
io::Arguments arguments(argc, argv);
std::string mask_asset_path = arguments.get("o", 0, std::string(""));
advanced::LineSpaceMaskMode mask_mode = arguments.has("ns") ? advanced::LineSpaceMaskMode::eNonSymmetrical : advanced::LineSpaceMaskMode::eSymmetrical;
unsigned mask_resolution_min = arguments.get("r", 0, 1);
unsigned mask_resolution_max = arguments.get("r", 1, 16);
bool check_after = arguments.get("check", 0, false);
advanced::LineSpaceMaskGenerator::generate(mask_mode, math::Range<unsigned>(mask_resolution_min, mask_resolution_max), mask_asset_path, check_after);
quitPromptDefault(0);
return 0;
}
\ No newline at end of file
......@@ -219,7 +219,7 @@ namespace glare
size_t mesh_id = mesh_ids[i];
//calculate triangle centroid
glm::vec4 centroid = (m_mesh_collectors[mesh_id]->m_transform * m_mesh_collectors[mesh_id]->bounds().min + m_mesh_collectors[mesh_id]->m_transform * m_mesh_collectors[mesh_id]->bounds().max) / 2.f;
glm::vec4 centroid = (m_mesh_collectors[mesh_id]->m_transform * glm::vec4(m_mesh_collectors[mesh_id]->bounds().min.xyz, 1) + m_mesh_collectors[mesh_id]->m_transform * glm::vec4(m_mesh_collectors[mesh_id]->bounds().max.xyz, 1)) / 2.f;
m_object_centroids[i] = centroid;
centroid_box.expand(centroid);
......
......@@ -28,11 +28,14 @@ namespace glare
RayGeneratorBase::generate(raytracer);
m_generator_shader_default->updateUniformImageRGBA32F("u_render_target", raytracer.renderTarget(), gl::Access::eWriteOnly);
m_generator_shader_default->updateStorageBuffer("mesh_buffer", raytracer.collector()->meshBuffer());
m_generator_shader_default->use();
m_generator_shader_default->updateUniformImageRGBA32F("u_render_target", raytracer.renderTarget(), gl::Access::eReadWrite);
m_generator_shader_default->updateStorageBuffer("trace_buffer", raytracer.traceBuffer());
m_generator_shader_default->updateUniformInt("random_seed", rand());
m_generator_shader_default->updateUniformStruct("u_camera", raytracer.collector()->getActiveCamera());
m_generator_shader_default->updateStorageBuffer("mesh_buffer", raytracer.collector()->meshBuffer());
m_generator_shader_default->updateStorageBuffer("object_bvh_buffer", raytracer.collector()->objectBVHNodeBuffer());
m_generator_shader_default->updateStorageBuffer("object_bvh_id_buffer", raytracer.collector()->objectBVHIDBuffer());
......@@ -49,11 +52,8 @@ namespace glare
m_generator_shader_gbuffer = std::make_unique<core::ShaderProgram>(shaders);
m_buffer_depthtest = core::ShaderProgram::makeUnique("raytracer/generators/gbuffer/depthtest.compute");
m_vertex_array = std::make_unique<core::VertexArray>();
}
void RayGeneratorGBuffer::generate(Raytracer &raytracer)
{
if (raytracer.width() != m_last_width || raytracer.height() != m_last_height) {
......
......@@ -79,9 +79,6 @@ namespace glare
m_render_shader->updateUniformStruct("u_camera", m_collector->getActiveCamera());
static std::default_random_engine generator;
static std::uniform_int_distribution<int> distribution(0, std::numeric_limits<int>::max());
m_render_shader->updateUniformInt("random_seed", distribution(generator));
m_render_shader->updateUniformUInt("u_render_config.current_sample", m_render_config.current_sample);
m_render_shader->updateUniformUInt("u_render_config.max_samples", m_render_config.max_samples);
m_render_shader->updateUniformUInt("u_render_config.num_bounces", m_render_config.bounces);
......@@ -102,7 +99,6 @@ 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);
core::ClockGL::instance().start();
m_render_shader->dispatchCompute2D(width, 4, height, 4);
++m_render_config.current_sample;
......
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