Search Unity

Get HDRP light intensity at specific distance from a light source

Discussion in 'High Definition Render Pipeline' started by Gooren, Feb 4, 2020.

  1. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    Hi,

    Is it possible to get light intensity at specific distance (specific point ideally) from a light source? On the CPU I mean.

    Cheers!
     
    Last edited: Jan 10, 2022
  2. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    One year later, still wondering the same question. I'm most unsure about the rectangle and tube area light.
     
  3. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    595

    It's gone through a few name and iteration stages since ~2019.3 LTS

    But it may be worth checking out the Render pipeline Debugger under windows > Analysis/render pipeline > render pipeline debug ( LTS /tech stream in use depends on location and naming) firstly.
    DOCS

    This may give you a good indication of how intensity is calculated at different stages.
    See automatic histogram too

    This all goes through the HDRP Volume framework on custom passes for the most part so great for manual debugging purposes.
    If you require your own scripted feedback, the Volume framework API may also help to do something similar.

    The two may help you get some insight on how to get to what you want to achieve.
     

    Attached Files:

    Gooren likes this.
  4. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    Thanks for the tips! I will check it out.

    I need to do this in built player though, at runtime, so I hope it will be possible to port these debugging solutions somehow.

    I can't simply use raycasts since I need to know not only light occlusion, but specially the actual intensity. That can be influenced by so many things... light cookie, fadeDistance etc.
     
  5. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    234
    Couldn't you just calculate it for the specific light?
    I mean it's basically the usual distance squared falloff with an additional distance falloff based on the light range.
    So in general it's;
    Code (CSharp):
    1. attenuation = pow(saturate(1 - pow(distanceSquared * range, 2)), 2) / distanceSquared
    All needed functions can be found in;
    https://github.com/Unity-Technologi...elines.core/ShaderLibrary/CommonLighting.hlsl

    Also worth reading;
    https://catlikecoding.com/unity/tutorials/custom-srp/point-and-spot-lights/
     
    Gooren likes this.
  6. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    Yes, you are correct, this works well with point light and cone shaped spot light.
    Pyramid and box shaped lights can also be handled relatively simply I guess.
    But then you have rectangle shaped area light where falloff changes based on angle etc. No idea how to handle that one, at least not with a solid accuracy.
     
  7. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    I tried searching HDRP shader code for Rectangle Area light calculation.

    However I failed to find the exact piece of code that determines how much light intensity diminishes at specific lit (within light range) point. I'm not really extra proficient at shaders. I only managed to find BoxDistanceAttenuation function in CommonLighting.hlsl

    So I reproduced it on CPU but the results don't really match. Not sure if that's because I got it wrong, or because that's not even the function I should be looking into :D

    Maybe it's the PolygonIrradiance function that handles this? From my experiments it seems that the BoxDistanceAttenuation makes sure we quickly attenuate at greater distances close to the light range. It almost doesn't change at lower distances, even though it's there that the light intensity diminishes the most in my case.

    The worst part are variables called 'ltcValue', 'diffuseDimmer' etc. I have no idea what they mean and how they might or might not affect the result I'm looking after.

    Anyone? I call for thee Mr. @bgolus ?
     
    Last edited: Jan 12, 2022