2
$\begingroup$

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

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.

$\endgroup$
  • 1
    $\begingroup$ The usual way to get rid of moire banding is to add a small amount of noise. $\endgroup$ – user1118321 Oct 14 '19 at 18:18
  • 2
    $\begingroup$ 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. $\endgroup$ – PaulHK Oct 15 '19 at 2:07
4
$\begingroup$

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

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – user1118321 Oct 15 '19 at 18:37
  • 2
    $\begingroup$ This photo of a real-world Cornell box model does show multiple images of the light source in the glass ball, FWIW: commons.wikimedia.org/wiki/… $\endgroup$ – Nathan Reed Oct 15 '19 at 21:34
  • $\begingroup$ A good test would be to compare your result against an image generated by a well tested path tracer fed with the exactly same scene and materials. I usually use Mitsuba as my ground truth (or even smallpt in some cases). $\endgroup$ – Christian Pagot Oct 16 '19 at 19:39
  • $\begingroup$ 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. $\endgroup$ – ivokabel Oct 17 '19 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.