-2

Code_Screenshot_1

Code_Screenshot_2

Code_Screenshot_3

OutPut or Result

Some errors is in result, Corrugated wall appears, under normal circumstances should not have ripples, it should be a simple diffuse material, but now it has ripples,but i cant find the problem.Please help me, thanks.

path trace code :

    if (r.depth >= max_ray_depth)
    return L_out;

float pdf;
Vector3D w_in;
Spectrum f = isect.bsdf->sample_f(w_out, &w_in, &pdf);
double cos_theta = std::max(0.0, w_in[2]);
if (cos_theta > 0.0 && pdf > 0.0 )
{
    Vector3D pdir = (o2w * w_in - hit_p ).unit();
    pdir.normalize();
    Ray pr(hit_p, pdir, int(r.depth + 1));
    L_out += (f*cos_theta*trace_ray(pr)*(1.0/pdf));
}
bin guo
  • 21
  • 3
  • Can you post the actual snippet of code, not just an image? – Azsgy Dec 23 '17 at 05:25
  • Sorry, i posted code. – bin guo Dec 23 '17 at 06:03
  • 1
    Can you specify more than "it has errors". What doesn't work? Does it crash? Can you provide inputs, received outputs and expected outputs for a few cases? – Azsgy Dec 23 '17 at 06:22
  • Corrugated wall appears, under normal circumstances should not have ripples, it should be a simple diffuse material, but now it has ripples. – bin guo Dec 23 '17 at 07:09
  • 1
    Then edit the question to say that. Also, post all code as Code, not as image. – Azsgy Dec 23 '17 at 07:14
  • The code is a little much,And i posted my githup above. Can you help me see what's wrong? The key code is in pathtracer.cpp – bin guo Dec 23 '17 at 08:02
  • 1
    This question should be closed because it doesn't provide the code as text in the question. If your code is too large, provide a smaller sample that reproduces the problem. – Modus Tollens Dec 23 '17 at 08:16
  • I provided the key code. – bin guo Dec 23 '17 at 08:35

2 Answers2

0

The image suggests your ray tracer is suffering from "surface acne", caused when the outbound ray intersects with the surface it just left, due to rounding errors with floating point representation of numbers.

The solution is usually to use shadow bias - add a small delta to the "time" (or parametric) value used to start the outbound ray, so that its starting point is slightly away from the surface.

More details are in the Surface Acne section on this page.

jon hanson
  • 8,722
  • 2
  • 37
  • 61
0

Note: jon-hanson already answered this

Make sure the origins of the bounce rays are very slightly off the surface. You should account for float error.

How to move a vector off the surface:

#define FLOAT_ERROR 0.0001f

// in code ...

vec3 normal = object_hit->normal; // I assume this is normalized
vec3 hit_point = object_hit->hit_point;

hit_point += normal * FLOAT_ERROR; //acount for float error

vec3 new_vector_origin = hit_point;
Joe Cool
  • 175
  • 2
  • 11