Search Unity

converting reflection probe -> light probe

Discussion in 'General Graphics' started by laurentlavigne, Jan 29, 2017.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,327
    When used in a shader that samples them in world space, Reflection probes are a neat way to cheat 1 bounce GI at runtime but they are quite costly and pop when 3 probes are involved.
    Light probes are fast and don't pop so I'd like to convert reflection probes to light probes.
    Before I dive into sampling reflection probes and convert that to spherical harmonics, has anyone done some legwork?
     
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,327
  3. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Today I got the same dirty thought.
    That I might convert reflection probe into light probe, this could allow me to use light probes without baking lightmap.
    Were you able to do it ?
     
  4. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    I'm interested too, I'm basically doing that as a GI but with one simple trick to get infinite bounce (the cubemap don't store colors, but a reference to a lightmap in which you recursively accumulate the light for bounces).

    I plan to adapt it to a RTX GI (DDGI) style of GI solution in the end, but without the RT part.
     
  5. mabulous

    mabulous

    Joined:
    Jan 4, 2013
    Posts:
    198
    For some internal work I created a native plugin (windows only!) to convert reflection maps (or any spherical function really) to spherical harmonics.

    The test code in the scene attached simply takes a cubemap and converts it using the native plugin to an order 4 spherical harmonics, which is then sampled by a custom shader:


    But for your usecase of converting reflectionprobes to lightprobes, you should be able to simply set
    const int ORDER = 2;
    in Test.cs to get order 2 spherical harmonics (3*9 coefficients), which you then should be able to fill a https://docs.unity3d.com/ScriptReference/Rendering.SphericalHarmonicsL2.html with to use with your lightprobe.

    Hope it can be of use:
    https://www.dropbox.com/s/4vx8amw7ahz55w6/spherical_harmonics_native_plugin.unitypackage?dl=0
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The result looks really great to be honest! Didn't expect it to look quite as good. Was there any need for the native plugin (Unity can't do it for some reason?)
     
    mabulous likes this.
  7. mabulous

    mabulous

    Joined:
    Jan 4, 2013
    Posts:
    198
    Just performance reasons, the code in the native plugin is heavily performance optimized
     
    hippocoder likes this.
  8. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
  9. mabulous

    mabulous

    Joined:
    Jan 4, 2013
    Posts:
    198
    Wouldn't mind to, but I'd first have to clean it up a bit to open-source it (it is basically built around an enhanced and performance-improved version of google's opensource spherical harmonics c++ repository, but that original code should also have the necessary functionality that just needs to be exposed through a native plugin).

    If enough other's would have use for this, I can see to allocate some time for it.
     
    Last edited: Mar 16, 2022
    koirat likes this.
  10. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    That's an 4th order SH, so it's going to look a lot more detailed than a light probe 2nd order SH.
     
    hippocoder and mabulous like this.
  11. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,327
    Because a thread isn't dead until the sun is extinguished, I just saw that cubemap can easily be sampled for each of the 6 cardinal directions. GetPixel with each CubemapFace enum and mipmap level 5 can then be fed as direction light colors.
    Not as precise as 4th order but good enough for GI.
     
  12. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    I did a custom reflection probe convolution. Main problem is that switching two set of probes(LightmapSettings.lightProbes.bakedProbes), and manually sampling it with GetInterpolatedProbe is too slow.
     
  13. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,327
    Did you find out what is slow in that operation?
    I'm going the voxel GI route for now. will revisit in a few years ;)
     
  14. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Copying probe data to unity c++ side.
     
  15. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,327
    Weird. For how many probes?