Search Unity

Providing custom lightprobes to shader

Discussion in 'Shaders' started by jister, Jun 17, 2020.

  1. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    hey,
    I'm trying to implement the custom light probe system The Elder Scrolls Blades talks about in this video.

    only I'm not sure where to start.. my main question atm is how to find and send the correct light probe data to the shader?
    I'm spawning building prefabs with a baked lightprobe group for the interior.
    when placing the building in the scene, the player character doesn't seem to sample from these lightprobes. The group doesn't seem part of the scene light data, I tried adding them to the LightmapSettings and such but didn't get anything to work.
    So my best guess is to make a custom shader that i can feed this newly spawned light probe group to.
    But i need some pointers to tone down my confusion, do i need to detect the closest probes from this group, or can i still use unity api for this somehow? do i need to feed the SH to the shader as an array of floats or is there a different way (i don't see any of the SH functions in UnityCG.cginc taking an array of floats as params)? Does the Mesh Renderer has some api to point it to a Light Probe Group?...
     
    RPGia and Gasimo like this.
  2. RPGia

    RPGia

    Joined:
    Jan 23, 2017
    Posts:
    44
    Bump.

    Calling @bgolus god. Do you by chance know what is the name of the property we must set for the MaterialPropertyBlock, as well as what format/value that property expects? I'm lost on this as well, and I don't know anyone except you with the technical skill to know about this
     
  3. RPGia

    RPGia

    Joined:
    Jan 23, 2017
    Posts:
    44
    Could this be how we set that MPB?

    https://docs.unity3d.com/ScriptRefe...ulateInterpolatedLightAndOcclusionProbes.html

    Code (CSharp):
    1.         // Put them into the MPB
    2.         properties = new MaterialPropertyBlock();
    3.         properties.CopySHCoefficientArraysFrom(lightprobes);
    So we just cache the light probes per prefab somehow, then after we spawn the prefab, we set `LightProbeUsage.customProvided`, then we create the MPB and pass in that cached light probe data?

    Could this be the right path?
     
  4. RPGia

    RPGia

    Joined:
    Jan 23, 2017
    Posts:
    44
    Here is additional relevant material on setting the runtime light probes:

    https://catlikecoding.com/unity/tutorials/custom-srp/baked-light/

    It sounds like we can just calculate light probes at runtime? Is that correct though? I thought calculating light probes was a heavy operation, that needed to be done during light map baking? This guy calculates the light probes positions at the same positions as the instanced meshes? Huh??? So the generated light probe data will be at the center of each mesh instance?
     
  5. RPGia

    RPGia

    Joined:
    Jan 23, 2017
    Posts:
    44
    After some testing, it seems like:

    Code (CSharp):
    1. LightProbes.CalculateInterpolatedLightAndOcclusionProbes(positions, lightprobes, occlusionprobes);
    Will rely on existing light probes already having been calculated, and already in the right place. So this won't work for my runtime generated prefabs.

    And it seems like light probe positions are read-only... not sure what to do now.