1
$\begingroup$

I have implemented a ray tracer using reinforcement learning. But I see some problems. I tried to divide the planes into rectangular grids. I searched the moire effect and realized that I can solve my problem by adding noise ( for example $\epsilon = 1e-5$) to the hit points on the diffuse surfaces, but even after doing this, I haven't seen any change. I created grid using ceiling function.

It seems that I shouldn't use the ceiling function (to understand which cell current hit point is in) and use another algorithm to find in which rectangular cells, the hit points are. Could someone tell me which algorithm to use?

enter image description here

EDIT 2: I sample primary rays randomly in each pixel without jittering. Is it the cause of moire effect? Do I have to use stratified sampling?

EDIT 3: I have to show some parts of code: This function generates a ray inside patches on sphere:

function Q_dir(ith::Int64)
    i = ceil(Int64, ith/H)
    j = ith - H*(i-1)
    u = (i-rand())/V
    ϕ = 2π*(j-rand())/H
    return Vec3(cos(ϕ)*sqrt(1.0 - u*u), sin(ϕ)*sqrt(1.0 - u*u), u)
end

This function returns the index of a rectangular cell on each plane which contains the hit point:

function find_state(a::Float64, a1::Float64, a2::Float64, b::Float64, b1::Float64, b2::Float64)
    return [ceil(Int64, M*(abs(a)/(a2-a1))),   ceil(Int64, N*(abs(b)/(b2-b1)))]
end

Ant this intersection function, returns the hit point and the cell

function intersect!(plane::xzPlane, ray::Ray)
    x1 = plane.a1
    x2 = plane.a2
    z1 = plane.b1
    z2 = plane.b2
    t = (plane.y - ray.org.y)/ray.dir.y
    point = ray.org + t*ray.dir
    if x1 < point.x < x2 && z1 < point.z < z2 && 0 < t
        hsect, wsect = find_state(point.x, x1, x2, point.z, z1, z2)
        normal = Vec3(0,1,0)
        return HitPoint(t, point , normal, hsect, wsect)
    else
        return HitPoint()
    end
end

The problem is surely related to this part, because I can reproduce the results of the paper. My only problem is this artifact.

EDIT 4: When I generate a ray uniformly through each uniformly selected stratum, everything works fine. But when I generate a ray uniformly through importance sampled stratum (each stratum has a different value), I encounter this problem.

EDIT 5: Sampling discretized hemisphere is surely part of the problem. I guess the Q_dir function is causing some problems. Here is another generated photo: enter image description here

H in Q-dir function is equal to 6. The number of half-lines generated on the floor equals 6. So this sampling method is incorrect.

$\endgroup$
  • 3
    $\begingroup$ Can you provide images? With highlights for the relevant parts? $\endgroup$ – lightxbulb Nov 10 at 12:54
  • $\begingroup$ I divided the planes using regular grids and I added noise to the points, but the problem hasn't been solved. $\endgroup$ – bitWise Nov 12 at 14:42
  • $\begingroup$ You simply have a bug in your sampling somewhere. These are not moire patterns. $\endgroup$ – lightxbulb Nov 12 at 16:11
  • $\begingroup$ No, it is moire effect. Just scale down the picture you even see some concentric semicircles. I have generated some photos with different parameters and the semicircles are obvious. $\endgroup$ – bitWise Nov 12 at 16:39
  • 1
    $\begingroup$ Sorry, I was wrong. I used stratified sampling, but nothing changed. So it's not moire effect. It is a bug. I should rewrite the code. $\endgroup$ – bitWise Nov 12 at 18:05

Your Answer

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

Browse other questions tagged or ask your own question.