3
$\begingroup$

I am doing a voxel based raytracer.

In other words, I first voxelize the scene using rasterization and I proceed to raytrace the volume in a 3D image to generate a final frame.

Currently I noticed a circular pattern aliasing and I am not sure what could be causing it.

This video shows the aliasing (sorry for the awkward camera movement my controls are not good right now). The magenta cube is the light's position.

https://www.youtube.com/watch?v=rtFDTQoKX_A&feature=youtu.be

Here's a still from the video:

Moire Patterns

EDIT: This is the main function of the fragment shader. I can post more if it;s needed, btu won;t for now because the fragment is quite big and I think most of the function names are slef explanatory:

void main()
{
    float v_size = cube_dim/voxel_resolution;
    vec3 r = -(vec3(f_coord.xy,1.f/tan(radians(40))));
    r.y*=-1;
    r.y /= aspect_ratio;
    vec3 dir = vec3(view_m*vec4(normalize(r),0));
    dir = normalize(dir);
    r = camera_pos;
    r.z*=-1;

    float t = boxIntersection(r, dir, -vec3(cube_dim), cube_dim*2);

    if(isinf(t))
        discard;

    if(!((r.x>=-cube_dim) && (r.x<=cube_dim) && (r.y>=-cube_dim) &&
        (r.y<=cube_dim) && (r.z>=-cube_dim) && (r.z<=cube_dim)))
        r += dir*t;

    vec4 color = vec4(0);
    while(incube(r, cube_dim))
    {
        r += dir*v_size*0.5;
        vec4 val = imageLoad(normal_map, ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1)));
        if(val.w > 0)
        {
            break;
        }
    }
    vec4 normal = imageLoad(normal_map, ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1)));
    color = imageLoad(diffuse_map, ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1)));

    fragment_color = blinn_phong(r, vec3(normal), color)*(10.f/log(length(r-light)));
}
$\endgroup$
  • $\begingroup$ Could you take a still image from your video and add it to the question? You're always more likely to get answers if people can see the problem without having to click through to external links. $\endgroup$ – Dan Hulme Jul 18 '18 at 8:22
  • $\begingroup$ This looks a bit like the typical self-intersection issues you sometimes get with ray tracers, were the intersection point of a ray is sometimes slightly inside the object you are testing (rounding error), so resuming from that point can result in a instant hit on the same object. I'm guessing those rings are shadows ? $\endgroup$ – PaulHK Jul 18 '18 at 9:29
  • $\begingroup$ @PaulHK I am not sure that is the case. I am adding an offset to the rays at the start, to ensure that they begin outside of the object. $\endgroup$ – Makogan Jul 18 '18 at 20:08
  • 1
    $\begingroup$ show your code, and take a still of the pattern $\endgroup$ – opa Jul 19 '18 at 14:18
  • 1
    $\begingroup$ If you change your shadow colour to say red, does the ringed artefacts also turn red ? Just watched your video again and it seems the artefact gets stronger the further away from the centre of the mesh the camera goes. What is the dimensions of your scene ? $\endgroup$ – PaulHK Jul 20 '18 at 2:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.