<p>I am doing a voxel based raytracer. </p>

<p>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.</p>

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

<p>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.</p>

<p><a href="https://www.youtube.com/watch?v=rtFDTQoKX_A&amp;feature=youtu.be" rel="nofollow noreferrer">https://www.youtube.com/watch?v=rtFDTQoKX_A&amp;feature=youtu.be</a></p>

<p>Here's a still from the video:</p>

<p><a href="https://i.sstatic.net/YttRQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YttRQ.png" alt="Moire Patterns"></a></p>

<p>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:</p>

<pre><code>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&gt;=-cube_dim) &amp;&amp; (r.x&lt;=cube_dim) &amp;&amp; (r.y&gt;=-cube_dim) &amp;&amp;
        (r.y&lt;=cube_dim) &amp;&amp; (r.z&gt;=-cube_dim) &amp;&amp; (r.z&lt;=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 &gt; 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)));
}
</code></pre>

CC BY-SA 4.0
2018-07-18T08:22:39.087Z
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.
Dan Hulme
CC BY-SA 4.0
2018-07-18T09:29:17.860Z
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 ?
PaulHK
CC BY-SA 4.0
2018-07-18T20:08:20.220Z
@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.
Makogan
CC BY-SA 4.0
2018-07-19T02:49:55.410Z
How are you offsetting the rays? Along the ray direction or the hit surface normal ?
PaulHK
CC BY-SA 4.0
2018-07-19T04:24:10.683Z
@PaulHK along the direction
Makogan
CC BY-SA 4.0
2018-07-19T14:18:51.683Z
show your code, and take a still of the pattern
Krupip
CC BY-SA 4.0
2018-07-20T02:38:32.893Z
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 ?
PaulHK
CC BY-SA 4.0
2020-04-14T06:25:44.327Z
Just to add, I've found I get much better results if the offset/epsilon is done along the normal vector of the surface and not along the ray vector. For rays that are very close to being parallel to a surface, when you go back along the ray by some epsilon, you are still very close to that surface.
PaulHK
CC BY-SA 4.0
2022-04-07T13:22:52.513Z
Hi, have you solved your problem ? I am facing the same issue and I suspect the ray intersection is the problem (as @PaulHK explained)
limserhane
<opengl><raytracing><glsl><antialiasing><debugging>
Circular pattern aliasing in voxel ray tracer
Makogan
# Circular pattern aliasing in voxel ray tracer

(Asked by: username_0 on 2018-07-17)

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](https://i.sstatic.net/YttRQ.png)](https://i.sstatic.net/YttRQ.png)

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)));
}

```

**Tags:** opengl, raytracing, glsl, antialiasing, debugging

> **Comments:**
> **username_1**: 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.  
> **username_2**: 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 ?  
> **username_0**: @username_2 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.  
> **username_2**: How are you offsetting the rays? Along the ray direction or the hit surface normal ?  
> **username_0**: @username_2 along the direction  
> **username_3**: show your code, and take a still of the pattern  
> **username_2**: 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 ?  
> **username_2**: Just to add, I've found I get much better results if the offset/epsilon is done along the normal vector of the surface and not along the ray vector. For rays that are very close to being parallel to a surface, when you go back along the ray by some epsilon, you are still very close to that surface.  
> **username_4**: Hi, have you solved your problem ? I am facing the same issue and I suspect the ray intersection is the problem (as @username_2 explained)  

---

## 0 answers

