<p>I solved my problem by adding a small value to t value when the ray is getting refracted.
But I still doubt the result is true. Below is the new generated photo:</p>

<p><a href="https://i.sstatic.net/jziQ0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jziQ0.png" alt="enter image description here"></a></p>

<p>Why is the area light reflected twice on top of the sphere? Is there still a bug in my path tracer? The glass sphere is closer to the camera than the area light.</p>

CC BY-SA 4.0
2019-10-15T18:37:02.740Z
The double reflection might be from internal reflections. Maybe you're getting one reflection from the light above and one reflection of the bright spot from the bottom of the sphere?
user1118321
CC BY-SA 4.0
2019-10-15T21:34:58.343Z
This photo of a real-world Cornell box model does show multiple images of the light source in the glass ball, FWIW: https://commons.wikimedia.org/wiki/File:Cornell_Box_with_3_balls_of_different_materials.jpg
Nathan Reed
CC BY-SA 4.0
2019-10-17T15:33:57.267Z
One useful debugging technique is to display contribution of path of certain length(s): length equal to 1 is just directly visible emission of materials, 2 is just direct illumination, >2 is whole indirect illumination, 2 is single-bounce indirect illumination, >3 multi-bounce indirect illumination, etc. This way you can separate certain groups of paths to better understand what's going on under the hood.
ivokabel
CC BY-SA 4.0
2019-10-15T17:53:48.767Z
2019-10-15T17:53:48.767Z
bitWise
<p>I am trying to render a dielectric sphere inside the Cornell Box. Some circles are generated on the sphere. Here is the photo generated by path tracer:</p>

<p><a href="https://i.sstatic.net/kEAYT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kEAYT.png" alt="enter image description here"></a></p>

<p>And below is my main function:</p>

<pre><code>function trace(surfaces::Array{Surfaces, 1}, ray::Ray, depth::Int64, maxDepth::Int64)
if depth &gt;= maxDepth
    return Vec3(0,0,0)
end
t, material = nearest(surfaces, ray, Inf)
if typeof(material) == Empty
    return Vec3(0,0,0)
end
if material.isLight == true
    return material.emittance
end
ρ = material.reflectance
n = material.normal
if material.isDielectric == true
    cosθ = -dot(n, ray.d)
    ref = material.ni/material.nt
    if cosθ &lt; 0
        cosθ = -cosθ
        n = -1.0*n
        ref = 1/ref
    end
    disc = 1 - ref*ref*(1-cosθ*cosθ)
    if disc &lt; 0
        R = ray.d - 2*dot(ray.d, n)*n
        In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
        return In
    elseif disc &gt; 0
        R0 = (ref-1)/(ref+1)
        R0 = R0*R0
        Rθ = R0 + (1-R0)*(1-cosθ)*(1-cosθ)*(1-cosθ)*(1-cosθ)*(1-cosθ)
        u = rand()
        if u &lt; Rθ
            R = ray.d - 2*dot(ray.d, n)*n
            In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
            return In
        else
            R = ref*ray.d + (ref*cosθ - sqrt(disc))*n
            In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
            return In
        end
    end
end      
BRDF = ρ/Π
R = hemiRand(n)
In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
return Π*BRDF*In
end
</code></pre>

<p>And I think the fresenl effect of the area light on the sphere looks strange and wrong! Am I correct? </p>

<p>EDIT: I searched a bit and I guess it's the moire effect. But I don't know how to get rid of it.</p>

CC BY-SA 4.0
2019-10-14T18:18:46.463Z
The usual way to get rid of moire banding is to add a small amount of noise.
user1118321
CC BY-SA 4.0
2019-10-15T02:07:52.663Z
Those circles are usually a symptom of numerical problems, these tend to 
come from the intersection distance. Sometimes the starting point for a reflected ray starts slightly below the surface because of rounding errors. Try subtracting a small epsilon from the intersection distance to see if it improves things.
PaulHK
<pathtracing>
Strange artifacts while rendering a dielectric material
bitWise
# Strange artifacts while rendering a dielectric material

(Asked by: username_0 on 2019-10-14)

I am trying to render a dielectric sphere inside the Cornell Box. Some circles are generated on the sphere. Here is the photo generated by path tracer:

[![enter image description here](https://i.sstatic.net/kEAYT.png)](https://i.sstatic.net/kEAYT.png)

And below is my main function:

```
function trace(surfaces::Array{Surfaces, 1}, ray::Ray, depth::Int64, maxDepth::Int64)
if depth >= maxDepth
    return Vec3(0,0,0)
end
t, material = nearest(surfaces, ray, Inf)
if typeof(material) == Empty
    return Vec3(0,0,0)
end
if material.isLight == true
    return material.emittance
end
ρ = material.reflectance
n = material.normal
if material.isDielectric == true
    cosθ = -dot(n, ray.d)
    ref = material.ni/material.nt
    if cosθ < 0
        cosθ = -cosθ
        n = -1.0*n
        ref = 1/ref
    end
    disc = 1 - ref*ref*(1-cosθ*cosθ)
    if disc < 0
        R = ray.d - 2*dot(ray.d, n)*n
        In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
        return In
    elseif disc > 0
        R0 = (ref-1)/(ref+1)
        R0 = R0*R0
        Rθ = R0 + (1-R0)*(1-cosθ)*(1-cosθ)*(1-cosθ)*(1-cosθ)*(1-cosθ)
        u = rand()
        if u < Rθ
            R = ray.d - 2*dot(ray.d, n)*n
            In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
            return In
        else
            R = ref*ray.d + (ref*cosθ - sqrt(disc))*n
            In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
            return In
        end
    end
end      
BRDF = ρ/Π
R = hemiRand(n)
In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)
return Π*BRDF*In
end

```

And I think the fresenl effect of the area light on the sphere looks strange and wrong! Am I correct?

EDIT: I searched a bit and I guess it's the moire effect. But I don't know how to get rid of it.

**Tags:** pathtracing

> **Comments:**
> **username_1**: The usual way to get rid of moire banding is to add a small amount of noise.  
> **username_2**: Those circles are usually a symptom of numerical problems, these tend to  come from the intersection distance. Sometimes the starting point for a reflected ray starts slightly below the surface because of rounding errors. Try subtracting a small epsilon from the intersection distance to see if it improves things.  

---

## 1 answers

### Answer by username_0 on 2019-10-15. Score: 4

I solved my problem by adding a small value to t value when the ray is getting refracted.
But I still doubt the result is true. Below is the new generated photo:

[![enter image description here](https://i.sstatic.net/jziQ0.png)](https://i.sstatic.net/jziQ0.png)

Why is the area light reflected twice on top of the sphere? Is there still a bug in my path tracer? The glass sphere is closer to the camera than the area light.

> **Comments:**
> **username_1**: The double reflection might be from internal reflections. Maybe you're getting one reflection from the light above and one reflection of the bright spot from the bottom of the sphere?  
> **username_3**: This photo of a real-world Cornell box model does show multiple images of the light source in the glass ball, FWIW: https://commons.wikimedia.org/wiki/File:Cornell_Box_with_3_balls_of_different_materials.jpg  
> **username_4**: One useful debugging technique is to display contribution of path of certain length(s): length equal to 1 is just directly visible emission of materials, 2 is just direct illumination, >2 is whole indirect illumination, 2 is single-bounce indirect illumination, >3 multi-bounce indirect illumination, etc. This way you can separate certain groups of paths to better understand what's going on under the hood.  

---

