Search Unity

Resolved How to get boxMin and boxMax from reflection probe?

Discussion in 'Shaders' started by NarberalTools, Jun 1, 2021.

  1. NarberalTools

    NarberalTools

    Joined:
    Jul 8, 2019
    Posts:
    63
    I need boxMin and boxMax for my shader, but as i know URP 2019.4.24f1 doesnt have those parameters in build in hlsl files. First of all, what is boxMin and boxMax? And how i can get it?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    I assume you're trying to do box projection for a reflection probe. The
    boxMin
    and
    boxMax
    values are the min and max extents of an axis aligned box "bounds" of the reflection probe.

    You could calculate these yourself if you wanted using the reflection probe's transform position, box size, and box extent properties. In pseudo code:
    Code (csharp):
    1. boxMin = probe.transform.position + probe.center - (probe.size * 0.5)
    2. boxMax = probe.transform.position + probe.center + (probe.size * 0.5)
    I suspect
    probe.bounds.min
    and
    probe.bounds.max
    would give you the same values, though I don't know for sure.

    Unity's built in code for this also assumes these values are
    Vector4
    /
    float4
    , but the w component isn't ever used.


    Unity may have decided not to support box projection for the URP, but the AFAIK values are still being passed to the shader via
    unity_SpecCube0_BoxMin
    and
    unity_SpecCube0_BoxMax
    so you don't actually need to calculate and pass them in on your own unless you want custom values. You'll likely also need
    unity_SpecCube0_ProbePosition
    .
     
  3. NarberalTools

    NarberalTools

    Joined:
    Jul 8, 2019
    Posts:
    63
    Thanks you very much. Unity 2019.4.24f1 doesn't have
    unity_SpecCube0_BoxMax and unity_SpecCube0_BoxMin in UnityInput.hlsl, so i can't to use them.
     
  4. NarberalTools

    NarberalTools

    Joined:
    Jul 8, 2019
    Posts:
    63
    Do you know how to get unity_SpecCube1?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    AFAIK you can just add them to your own shader if Unity isn't defining the values in the included hlsl code. Since the URP uses the default reflection probes, these are still being set by Unity's built in rendering code.

    Again, if it's not defined, you can just add it to your shader. Look at how they're defined in the built in shaders and copy/paste that into your own shaders.
     
  6. EminemJ

    EminemJ

    Joined:
    Mar 10, 2020
    Posts:
    45
    In edit mode, I cound get
    unity_SpecCube0_BoxMax
    and
    unity_SpecCube0_BoxMin
    , but once I enter play mode , these values would turns to be 0, any ideas?
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    Well ... darn. My only thought there would be to copy the data off into your own component.
     
  8. ekakiya

    ekakiya

    Joined:
    Jul 25, 2011
    Posts:
    79