0

My AO algorithm is as follows, whith the random vectors just all over the hemisphere:

    vec3 ao_ray_position= random_in_hemisphere(gi_rec.normal);
    
    ao_ray = ray(gi_rec.p + gi_rec.normal * 0.001f, ao_ray_position);
    ao_hit = !world.hit(ao_ray, 0, infinity, gi_rec);
            
    ao_result = Color(ao_hit / gi_samples, ao_hit/ gi_samples, ao_hit/ gi_samples);

which renders this image:

enter image description here

Now this one is from V-Ray with falloff at 8,7, which is the setting I want to implement, but can't figure out how. I've seen many examples of limiting the hemisphere by cone angle but the image just renders black

enter image description here

EDIT: Thanks to Mathis I got it working, the code and the result meanwhile:

    float ao = 1.0f;
    float dist = distance(gi_rec.p, rec.p);
    if (dist < d) {
        ao = !gi_hit / dist;
    }

enter image description here

mrmanet
  • 3
  • 2

1 Answers1

0

Assume that rays with a distance larger than $D$ won't contribute to the occlusion. Since I don't know exactly of V-ray implements their interpolation, we can create a weight function $w(\frac{d}{D})$ where $w(x) = \left\{\begin{matrix} f(x), \quad 0 \geq x \geq 1 \\ 0, \quad otherwise \end{matrix}\right.$

and compute $AO = 1 - \frac{1}{N} \sum_{i=0}^N w(\frac{d_i}{D})$.

A simple example would be to let $f(x) = 1-x$ but this gives $w$ a non-continuous first derivative. Adding some additional constraints besides $f(0)=1, f(1)=0$, like $f'(1) = 0, f''(1)=0$ would give a polynomial like $f(x) = 1-3x+3x^2-x^3$ which decreases in value a bit faster than linear and would give smoother results.

Mathis
  • 71
  • 2
  • yep, you're right, thank you!! I didn't implement everything you showed but I got similar results with the code at my edited question. – mrmanet Feb 11 '23 at 05:56
  • It would be too much to ask for at least a pseudocode of your non-linear interpolation? This math is a bit over my head now lol – mrmanet Feb 11 '23 at 07:06
  • Maybe like this: https://www.shadertoy.com/view/dljSDW – Mathis Feb 11 '23 at 11:02