Search Unity

GPU Ray Tracing in Unity – Part 2

Discussion in 'Community Learning & Teaching' started by Daerst, May 25, 2018.

  1. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    275
    emissive.png

    ► Read here: GPU Ray Tracing in Unity – Part 2

    In the first part of this series, we created a Whitted ray tracer capable of tracing perfect reflections and hard shadows. What’s missing are the fuzzy effects: diffuse interreflection, glossy reflections and soft shadows. Building upon the code we already have, we will iteratively solve the rendering equation formulated my James Kajiya in 1986 and transform our renderer into a path tracer able to capture the mentioned effects.

    Questions and feedback are highly appreciated!
     
    luhkius, kristoof and mgear like this.
  2. BerengerVolumiq

    BerengerVolumiq

    Joined:
    Feb 6, 2017
    Posts:
    14
    Hi Daerst, are you still working on part 3 ?
     
  3. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    275
    Hi there. Yes, it's still in the works. Unfortunately, there is no room for it in my daily schedule, so I only get around to working on it every couple of weeks for a couple of hours. But yeah, triangles are coming eventually ;)
    bronze-triangle[1].png
     
    kristoof and hippocoder like this.
  4. BerengerVolumiq

    BerengerVolumiq

    Joined:
    Feb 6, 2017
    Posts:
    14
    Awesome ! I am working on it too, learning as I go. I have a feeling that I need to solve the problem of divergence between the threads. I'm eager to see the way you'll do it, but I fully understand the difficulty of finding an hours here and there for side projects.
     
    dreamerflyer likes this.
  5. BerengerVolumiq

    BerengerVolumiq

    Joined:
    Feb 6, 2017
    Posts:
    14
    Hi Daerst,

    I think there is a mistake in part 2. I'm trying to figure out the math behind importance sampling but I'm stuck. Here is what I have so far :

    Code (CSharp):
    1.  
    2.             // Lambert BRDF with uniform probability where probability is 1 / 2π in every direction in the hemisphere
    3.             // Montecarlo : f(x) / p(x)
    4.             // f(x) = (kd / π)
    5.             // p(x) = (1 / 2π)
    6.             // (2π * kd) / π
    7.             // => 2 * kd
    8.  
    9.             // Lambert BRDF with importance sampling where probability is (ωi⋅n) / π (because α == 1)
    10.             // Montecarlo : f(x) / p(x)
    11.             // f(x) = (kd / π)
    12.             // p(x) = (ωi⋅n) / π
    13.             // (kd / π) / ((ωi⋅n) / π)
    14.             // (kd / π) * (π / (ωi⋅n))
    15.             // => (kd / (ωi⋅n))
    All is fine, once this is used in the rendering equation, ωi⋅n is removed and only kd is left. But for phong, I don't get it :

    Code (CSharp):
    1.  
    2.             // Phong BRDF, with wr the perfect reflected light direction and α the phong exponent
    3.             // With uniform probability
    4.             // Montecarlo : f(x) / p(x)
    5.             // f(x) = (ks * ((α + 2) / 2π) * (ωr.ωo)^α)
    6.             // p(x) = (1 / 2π)
    7.             // (ks * ((α + 2) / 2π) * (ωr.ωo)^α) / (1 / 2π)
    8.             // (ks * ((α + 2) / 2π) * (ωr.ωo)^α) * 2π
    9.             // ks * (α + 2) * (ωr.ωo)^α
    10.  
    11.             // with importance sampling
    12.             // Montecarlo : f(x) / p(x)
    13.             // f(x) = (ks * ((α + 2) / 2π) * (ωr.ωo)^α)
    14.             // p(x) = ((α+1) / 2π) * (ωi.n)^α
    15.             // (ks * ((α + 2) / 2π) * (ωr.ωo)^α) / (((α+1) / 2π) * (ωi.n)^α)
    16.             // (ks * ((α + 2) / 2π) * (ωr.ωo)^α) * ((2π / (α+1)) * (1 /(ωi.n)^α))
    17.             // (ks * (α + 2) * (ωr.ωo)^α) * (1 / ((α+1) * (ωi.n)^α))
    18.             // What now ???
    Should p(x) use ωr.ωo instead of ωi⋅n, ? Lafortune and Willems's paper seems to (their cos α) but that would mess the lambert sampling. I'm missing ssomething I think.
     
  6. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    ray.png
    why so big different?!