Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

accessing custom light-probes from shaders

Discussion in 'Shaders' started by AverageCG, Oct 13, 2019.

  1. AverageCG

    AverageCG

    Joined:
    Nov 13, 2017
    Posts:
    19
    Hey,

    For a study project i need to implement a custom sollution for GI and wanted to do so in unity. While I am fairly informed on the general theory i lack the shader code experience to figure out how i would go about efficiently fetching the right lightprobe data from the closest lightprobes in a vertex shader?

    Edit: I am mainly unsure of how to determine at runtime which probes to sample data from.
    As a simplified prototype to get me going on some basics one could imagine cube-map data from for example built in reflection probes. How could i for pass a matrix probe positions into the shader and (preferably) thread coherently sample the cube maps from a fixed number of probes?

    If anyone has an idea or some material i can read up on that would be great. Otherwise i am currently digging my way through the unity include files but I couldn't quite find how unity handles this yet. If someone could point me to that for inspiration it would also be appreciated :).

    Thanks for any advice!
     
    Last edited: Oct 14, 2019
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,555
    You can find the nearest lightprobe values in the
    unity_SH
    values that are listed in
    UnityShaderVariables.cginc
    , the "SH" stands for Spherical Harmonics, which is what the values are.

    Inside of
    UnityCG.cginc
    there are several built in methods that will give you some idea how to manually use that data, the primary ones being
    ShadeSH9()
    and the methods it calls which are listed before it, and
    SHEvalLinearL0L1_SampleProbeVolume()
    which comes after it.