Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: mi_sample and unified sampling

  1. #1
    Join Date
    Oct 2009
    Posts
    52

    Default mi_sample and unified sampling

    I'm having a go at converting my shader to be optimised unified. A question I've come across is calling mi_sample for glossy rays. Now that I'm only shooting 1 ray, I only call mi_sample once and give that to the glossy function to set the vector to shoot.

    If mi_sample is called in single hits like this, will it affect convergence? I'm calling it once here and there for different purposes, where as before it would be called in a loop.

  2. #2
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default

    It should still be able to converge. Is this glossy reflection supposed to be weighted agains other behavior, such as diffuse?

    The key is to weight it appropriately, which may include a fresnel blend factor. That is what the mi_sample is used for. For example, if the weight is 0.6, then if mi_sample returns less than 0.6 shoot your glossy ray (or rays), otherwise compute your diffuse.

    Now, you may also use the mi_sample for choosing a direction for the glossy ray, or altering the normal for computing the reflection, like the way mib_glossy/mia do it. See mib_glossy code for example.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  3. #3
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default

    For wider glossiness, blurrier look, you may still wish to shoot more than 1 glossy sample, somewhere between 1 and 4 as we're approaching brute force with unified.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  4. #4
    Join Date
    Oct 2009
    Posts
    52

    Default

    I'm using mi_sample to choose which kind of ray to execute, as well as choose a random direction for glossy samples. I'm also weighting the different types of ray (diffuse, reflection, etc) depending on energy conservation and how glossy it might be.

  5. #5
    Join Date
    Oct 2009
    Posts
    52

    Default

    After some experimenting, I've had mixed results. Just to go over the basics, only evaluate 1 ray path per execution of the shader. So does that mean after multiple executions, you'll have some diffuse, some specular, raytraced reflection etc. But is the summation of these executions an average, rather than addition? It seems to be what's happening for me.

  6. #6
    Join Date
    Oct 2009
    Posts
    52

    Default

    Thinking about it some more. Each execution of a shader for a pixel will be summed and then divided by the number of samples fired by the renderer? So the results of multiple samples by the renderer will give an average.

    With the method being said at the moment of only doing one kind of shading per shader execution, eg :diffue, reflection, refraction, the results will be incorrect. These "passes" need to be added, but they're being averaged.

    Is this correct?

  7. #7
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default

    It is an average of the samples, but you should be shooting samples according to energy weighting, and then not multiplying by a weight.

    For example, if you have 70% specular and 30% diffuse, instead of calculating both and multiplying by the weights, take 7/10 samples as specular calculations and 3/10 as diffuse. Then, the average of these samples, automatically weights correctly.

    If you split the weighting by specular/glossy and diffuse, and you use direct, you may need to add direct specular/glossy to the indirect specular/glossy reflection ray for the specular/glossy sample.

    Pure brute force would trace everything without a direct calculation, because all lights could be hit and there really wouldn't be something exactly like a traditional point light source. A bsdf would give you the probability for shooting a ray in a particular direction.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  8. #8
    Join Date
    Oct 2009
    Posts
    52

    Default

    I'm still having issues. The averaging is giving different results, when the specular is averaging against a diffuse black colour, it's pulling down down the result, as opposed to the usual add.

    My example is using black for diffuse colour, reflection is white (255,255,255) with a BRDF modifying the reflection colour. The sample weighting is determined by the modified reflection colour luminance. Say it ends up being .7 when the normals face the camera, so the diffuse gets sampled .3.

    So there are 7 reflection samples being averaged against 3 diffuse samples, the diffuse is black, so it pulls down the reflection result.

  9. #9
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default

    It should be pulled down by 30% as it would if you weighted the specular by 0.7 as you are indicating would be done. You aren't also multiplying specular calculation by 0.7, are you?

    When you say specular and reflection, are those the same, or are you referring to direct specular/glossy reflection and indirect specular/glossy reflection, respectively?

    What is the brdf you say is modifying the reflection color?
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  10. #10
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default

    For example, lets say we are using a fresnel blend, like in mia_material, and after calculation based on the normal and the eye direction, we end up with 70%.

    If it were a traditional shader, we would multiply the result of both direct and indirect specular/glossy reflection by 0.7 and add that to diffuse (direct and indirect) multiplied by 0.3.

    So, in unified optimization, instead we don't weight by 0.7 and 0.3 and calculate both. We calculate one at full strength 7 out of 10 times, and calculate the other at full strength 3 out of 10 times. When I say one, I mean both indirect and direct for that one type of reflection, as both energies sum to represent that part of the the reflection response, eg, either diffuse, or a specular/glossy lobe.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •