Search Unity

Support for custom lightning in HDRP

Discussion in 'High Definition Render Pipeline' started by corjn, Dec 13, 2019.

  1. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    PutridEx and andrejpetelin like this.
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    Technically its not in URP, if you look through that article they simply hack in a function using custom node to get the light. Its nothing like dragging in an actual light node that is built in, which would be actual "support". You can do the same in HDRP if you expose the light via some code, the same stuff will work although the function to get the light will be different.
     
  3. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    Unless the light infos in HDRP are private (which I think is the case, as everywhere I looked on the internet, no one seems to find a solution to get the light infos in HDRP)

    Even this asset https://assetstore.unity.com/packages/vfx/shaders/nodes-for-shader-graph-124611 is delivering custom ligtning nodes for the URP but not for the HDRP. All his other nodes are compatibles for both srps.

    Edit : I asked to the dev of the asset above, based on the forum answers, it seems indeed possible :) I was just confused it was not done anywhere already. I suppose not a lot of people uses HDRP as it just came out of preview.
     
    Last edited: Dec 13, 2019
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    I think also there are less people using HDRP for NPR but it certainly is suited to it I think :)
     
  5. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    Yes, I just want to have a mix between realism and something more pictural :)

    I just got answered by amplify, and from their point of view it's not possible :

    "We would like to, but as for right now this isn't possible. Like I previously mentioned, because of how Unity is doing its light calculations over that pipeline, it's not viable to get access to certain data like light attenuation.
    Before they had different passes that dealt with directional and point/spotlights, they now calculate the final lighting for each fragment inside inside a loop which makes really hard to get that."

    So, @b4cksp4c3 @SebLagarde , would love to hear about it from the Unity HDRP team.
     
    Last edited: Dec 14, 2019
    Peter-Bailey likes this.
  6. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    437
    Also curious about this. Render Debug utility shows a lot about lighting - maybe this is a start somehow?
     
    Egad_McDad, andrejpetelin and corjn like this.
  7. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    @b4cksp4c3 @SebLagarde @Remy_Unity ,

    I'm sorry to insist, but an actual answer from unity here would be great. This is the only thing that makes me wonder if I should switch to the HDRP or not because i'm starting a long production project and I really need to be able to have precise control with lights and shadows in my shaders.

    And based on amplify answer, I think we can guess it's something a lot of people would want to see in a future update of the HDRP.

    Thanks in advance for your support,
    Jonathan
     
  8. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    Ok so I made some tests with the debug window and I was able to show only the light attenuation here :







    First image is with Directional Light, second with point light

    So, I guess that the "DebugFullScreen" shader in the HDRP package, somehow, can get the light attenuation datas.

    I even found, in that shader, what is doing that :


    Code (CSharp):
    1.  if (_DebugShadowMapMode == SHADOWMAPDEBUGMODE_SINGLE_SHADOW)
    2.                 {
    3.                     float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
    4.                     return color;
    5.                 }
    The problem here is : I can't find where is created the TEXTURE2D_X in question.

    One solution could be to recreate my own custom depth shadow map method, but it would be so much more better for my workflow to just use the shadows maps generated by the HDRP :(
    Again, some help from unity would be very much appreciated. It would be great to have a node in shader graph that is doing the exact same thing as the "single shadow" in the debug window.
     
    Egad_McDad likes this.
  9. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Hi,

    it is not possible do to custom lighting with HDRP by design (As Amplify explain it).
    Only way to do it is to write C#/ and shader code to add your own material (which require some time).

    If you want to access only to the shadow, there is a "shadow matte" functionality in Unlit shader graph in version 7.1.6
    https://docs.unity3d.com/Packages/c...ion@7.1/manual/Master-Node-Unlit.html?q=matte

    our debug mode are very slow and can't be use for production, only for debugging purpose.
     
  10. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    Hey @SebLagarde

    Thanks a lot for your answer, it really helps : ) I tried the shadow matte on shader graph, the result is cool but it does not give enough control over the shader.

    Well, it's good to know : if I switch to the HDRP I will have to create a custom shadow map solution with a camera depth texture.
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    In my work with HDRP I found the answer is best to create an unlit shader and work on that with graph or other method. You would need to keep a list of active lights, calculate your own in shader and have a manager, but it is better than fighting HDRP's lit shader.

    Have you considered working with URP and trying to add realism back? URP can match HDRP if the result is mostly a baked and not realtime workflow.
     
    andrejpetelin likes this.
  12. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    Hey, @hippocoder
    Thanks for the advice ! The thing I want to achieve is a bit tricky : I'm working on the skin shader of my character. I want a mix betwwen Subsurface Scrattering and cel shading.

    The URP, in my opinion, still lacks a lot of features compared to builtin (but i'm sure with 1 or 2 more years, it will be better),for example, let's take custom lightning : as you have to use the unlit template, if you want somethning like me, more in between realism and cartoon, you have to rewrite all the lightning inside shader graph. In the blog post Unity did about LWRP and cel shading, they made a very very flat one, that does not support light probes, that does not support spot light shadows. I'm sure there is way to support it, but if you take the builtin + amplify, well, everything is already done and is working really well. So would would I remake all the work amplify did, in shader graph, to have the exact same result ? (maybe even a less good result, because of the features lacking in URP right now, like shadow masking and the way point and spot light handle shadows)
    But again, I think Unity is taking the good path by making a "scriptable" render pipeline. The custom renderer is great for example ! But I think it's out of preview waaaay too early.

    The HDRP on the other hand feels more feature completed, if I forget about custom lightning, I think it's a solid pipeline that's actually maybe better than the builtin.

    So, I made some more tests with the HDRP (or else I will just stay with the builtin) and I'm really happy to say that I found 2 solutions to make some kind of "custom lighning" in the HDRP within the lit template (Support for light probes is very important for me as well, supporting that in an unlit template would be complicated I think + support for everything else).

    This is actually very simple :

    -Control of the shadow with a sss profile to control how sharp is the shadow (can also change the shadow color) + an occlusion slider ton control the shadow brightness.

    OR

    Get the light direction, with the vertex normal you should be able to know where the shadows area are and then have more control over it (and it's probably better for performances to do this way)

    -Control of the lighten side by making the vertex normal = object space light direction (it will flatten the light) (and of course color and birghtness will be affected by you light)
    -Support for specular / gloss can be made with a fresnel in vertex normal space and, connected in the emission output.
    -Normal is supported, just plug the map in the normal output.

    The result :





    Or else, it's untested but, I checked how you can do a toon shading in UE4 and they actually do it with post process. HDRP supports custom process. So you can probably do this in HDRP. I think they used this technique in Zelda BotW, as the Lake Hylia glitch shows a phong shaded Link.
    This second option gives more freedom I think.
     
    Last edited: Dec 21, 2019
  13. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    I was about to say that, post process
     
    corjn likes this.