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:
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.