Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Extending HDRP for custom light shape.

Discussion in 'High Definition Render Pipeline' started by koirat, Apr 24, 2021.

  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Is it possible to extend HDRP with custom light shapes.
    What I'm trying to achieve is spotlight that will have non uniform range so later I can place some torches on walls and not have a light outside building.
     
  2. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Y-Hello there,

    Idk if this is what you mean by custom shape:
    flashlight-28129-003-scaled.jpg

    but you can achieve this by setting a texture in the cookie setting of the spot light.
     
  3. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    I think he's looking for custom fall-off, which is not uniform in very direction
     
  4. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Alright, that's quite the question then. Curious to see if there's something that doesn't involve heavy physics calculation.

    [Edit] I guess it would be possible to generate a fall-off BW map where white would be cast ray toward infinity and black is don't cast ray, this is just an idea, idk if it's possible to tinker with unity this much.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    yep I'm talking about custom fall-off/range.
    As I stated in the beginning this is so I can have lights on a thin wall that will not lit other side of the wall corridors. Right now the only solution would be to have light created of multiple spotlights with different range, but this is not looking good and less performant solution.
     
  6. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    If lights are leaking through walls that's another issue tho. Can you show an example of what the problem actually is? Maybe there's a different more ready solution to this.

    Also, take a look at this blog post: http://arthurdaurio.com/2018/05/13/inverse-square-falloff-in-unity/
     
    Ruchir likes this.
  7. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    It's not a mistake.
    It's real time lighting, no shadows because of performance - naturally it is radiating through walls.

    Interesting read is this HDRP ?
     
  8. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Without shadows, that's tricky...

    What about setting the shadows UpdateMode OnEnable and giving it a very small res like 16? shouldn't be much of a performance impact.

    I don't believe so, but it could be a starting point for what you're trying to achieve.
     
  9. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Well you also have the new "Mixed cached shadow maps" or just bake the shadow maps and use mixed lighting with shadows disabled
     
  10. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Unfortunately my world is of medium size so lightmaps are rather out of the question.
    Mixed cached shadow maps are rather for dynamic not static geometry.
    There is theoretically an option to generate lightmap for only selected objects but there still are the problems with this solution.
     
  11. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Maybe some hacked workaround then?

    Detach the exterior part of the wall into a separate object and set it to a different light layer, for example.

    If you need to see the torches only when inside the building, place its insides into a separate HDRP volume and make these lights visible only when inside this volume.

    Etc.
     
  12. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    I don't think so, They can be applied to static objects as well
     
  13. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    My characters and dynamic objects are going to be lit anyway.
    yes I'm considering some degree of some kind of volumes but are you talking About HDRP Volumes ?
    How can I attach anything (lights for example) to them ? i got this question some time ago. it went unanswered.
     
  14. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Mmmh...Volumes work with profile data, I don't think you can encompass lights in them.

    @koirat I don't know much about your project, but, if lights aren't moving (you were talking about torches on wall), why not consider the baking option and use light probes for dynamic elements? If the end device is either PC or Console they can support a few (actually much more) 2048x2048 lightmap textures.
     
  15. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    My level is to big for lightmaping I tried on a smaller level and even then it could not bake.
    My game is semi-open world. (one scene = whole game)
     
  16. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Well, you could have a look at the bakery, it's pretty good for all kind of scenarios and much better than unity's lightmapper
    I really have no idea after using that asset, why does even Unity's lightmapping have to be so slow(even the GPU one) :mad:
     
  17. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    Hey, you most likely want to look into light layers if you are dealing with light leaking.

    https://docs.unity3d.com/Packages/c...high-definition@11.0/manual/Light-Layers.html

    You can control which lights affect which objects. It's very powerful.
     
    rz_0lento likes this.
  18. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    No light layer will give me nothing.
    Even when I use different light layer for a corridor my character is still going to be lit through walls.
     
  19. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    What about a mix of light fade distance, shadow fade distance, and light layers, as well as scripting based on player camera position?

    For torchlights, a simple and proven solution would be placing a spotlight facing towards the inside of the room (perpendicular to the wall surface), while using a small, low distance, point light to still provide illumination against the wall. This might however be more complicated for multi-storey rooms, if the player can see other storeys than the current one.

    Also, HDRP 12 (for upcoming Unity 2021.2) is providing 2 new features to refresh lights when a dynamic (moving) object is inside the light volume, as well as when the light itself moves:
    upload_2021-5-13_18-7-21.png

    This could be a way to maintain shadows active on "On Enable" lights, and only refresh their shadows when needed, without having to script their refresh nor pay the cost of "Every frame" shadows. This, on top of all the other solutions mentioned above, should get you there.

    See "Mixed cached shadowmaps" in the doc:
    https://docs.unity3d.com/Packages/c...h-definition@12.0/manual/Shadows-in-HDRP.html
     
    Last edited: May 14, 2021
    koirat and Ruchir like this.
  20. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    OnEnable is generally doing the trick. Thank you.
    Still there are some limitations to the light count and atlas size.
    May I ask what is the method to determine in what priority lights are selected ?
    Might it be distance to the origin , closest distance to the range or some other ?

    May I also ask about performance of cached shadows ?
    Since I will probably go for real time lights I assume my project will have a lot of lights to mitigate lack of baked lights should I be concerned about performance ?
     
  21. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    433
    Currently, the shadows in the atlas are in a "first in - last out" configuration, based on the position of the light in the hierarchy. This means if the cache is already full and you activate a new light with shadows, the latter won't be added to the atlas (= missing shadows). This is to minimize the cost as much as possible and not constantly check the state of the scene.

    However, it doesn't mean we won't offer a primitive auto-update solution based on light distance, size and time, at some point in the future (something I requested). Doing these auto-updates will add a cost indeed (spikes). So, for advanced users, it'll still be highly recommended to handle these updates on their own for their specific scenarios.
     
    Ruchir and koirat like this.
  22. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Thank you for your answer.
    I hope your proposition is going to be accepted, position in hierarchy is totally useless.