Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to disable specular completely for certain objects?

Discussion in 'High Definition Render Pipeline' started by Passeridae, Sep 16, 2021.

  1. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Hi!
    I can't find a way to disable direct specular impact from real-time lights on a per-object / per-material basis. I can globally disable it either by toggling it off in the HDRP settings or in the light component settings. But that obviously disables it for everything.

    If I turn down the smoothness value on the standard lit material to 0 then there's still a lot of specular lighting left:
    upload_2021-9-16_16-57-37.png

    If I set the material type to Specular and also turn down the specular value all the way down to the pure black, there' still some specular response, but its way better.
    upload_2021-9-16_16-58-22.png

    But what I want is the complete absence of the direct specular like when I turn it off in the light component:
    upload_2021-9-16_17-1-8.png

    I know that it's not physically correct, because "everything has fresnel" and other stuff, probably, but I want to provide my own specular lighting response for certain objects. And if it will be overlaid on top of the existing stubborn real-time specular, it will also be incorrect.

    Is there some workaround for this?

    Thanks!
     
  2. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Bump. Anyone?
     
  3. Win3xploder

    Win3xploder

    Joined:
    Dec 5, 2014
    Posts:
    159
    Use the fabric shader model instead.
     
  4. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    431
    Hey, you can probably use a reflection probe with a custom black reflection map. And use the light layer system to only affect these specific objects. This way they will receive no reflections.
     
  5. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    It has even less specular left than the Lit + specular, but it doesn't disable it completely, unfortunately.
     
  6. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Unfortunately, reflection probes don't affect/override the direct specular that comes from real-time lights. A custom pure-black reflection probe disables only itself...

    I thought that maybe I can render the direct specular component into a rendertexture with the help of AOV somehow, but I was told in the other thread that it's not possible without performance impact.
     
  7. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    431
    You can still use the light layer system to prevent this.

    Here's a test where I set all the objects on a given layer to not receive any reflection. The bronze ball is entirely black as a result:
    upload_2021-9-22_16-4-39.png


    And if you use a black reflection probe like I mentioned above, you can kill the reflection. The probe doesn't disable itself like you mentioned.

    In the example below, it does indeed receive direct specular from nearby lights, but again, you can use the light layer system to prevent nearby lights from affecting this particular object.
    upload_2021-9-22_15-59-21.png

    You can tell the lights to not affect the layer the ball is on, and you get zero influence from the nearby black probe nor from the spotlight above as a result. And if you don't want the black probe to affect other objects than the sphere, again the light layer system comes to the rescue. ;)
    upload_2021-9-22_16-4-47.png

    It's perfectly doable.
     
    rz_0lento likes this.
  8. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Thanks for the detailed explanation, and I'm sorry if I get it wrong, but that's exactly the issue. I don't want to prevent the lights from affecting the objects completely. I want them to affect albedo, normals, provide shadows, etc. and the only thing that I want to exclude is the direct specular component. It's like if the "affect specular" option wasn't an off/on the switch, but rather a layer selection:

    upload_2021-9-22_20-56-29.png

    In other words, I need "affect specular" disabled for certain objects, while "affect diffuse" and the rest of the light impact enabled for all objects.
     
  9. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    431
    You could duplicate some lights in this room, set them to only affect the "no specular" light layer that you create, and then set them to not "Affect Specular". Then all objects you add to the "no specular" light layer won't receive specular from said lights.

    It requires some duplication, but in the end, you can separate entirely the "normal lights" from the "no specular lights" easily. And if your lights are in a prefab, it's just a matter of having another prefab instance of the same light, with 1 override only on the "Affect Specular" property.
     
  10. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Yes, I thought of this option. But wouldn't such light duplication affect performance in a serious way?
     
  11. pierred_unity

    pierred_unity

    Unity Technologies

    Joined:
    May 25, 2018
    Posts:
    431
    This is something that you would have to profile for yourself. If it's just a few lights, it might be imperceptible. If it's several dozens, there might be a cost. The pixel shading pass *might* even be cheaper.
     
  12. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    927
    Last edited: Sep 23, 2021
    DrSeltsam likes this.
  13. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    That's interesting, it was merged in 2020. Why is it only in the latest alphas? I'm using 2021.2 beta 11.
     
  14. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    927
    It's still open, not merged for some reason o_O
     
  15. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    I wonder what my chances are if I merge it myself into the 2021.2 beta...
     
  16. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    This is hilarious. Im sorry you cant get good help OP. I would just set the reflection probe usage to OFF for the mesh renderer. Now when you put the smoothness to 0 there will be no light shine at all.
     
  17. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Also, when you set a material type to specular (versus metallic), all you are doing is aenabling a specular map for the shader. This is a map that only affect the Color of the specular shine, thats it.
     
  18. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    There are no reflection probes in my screenshots. All the specular response is produced by two area real-time lights.
     
  19. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    There is a default reflection probe that is applied in your scene.
     
  20. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    What i mean is, if you dont have probe Unity will put a default one there that you cant see.
     
  21. DrSeltsam

    DrSeltsam

    Joined:
    Jul 24, 2019
    Posts:
    100
    I'd also love to have a way to turn off specular completely for a certain material. Having a separate light for specular only doesn't work for directional lights unfortunately (because only 1 directional light can cast shadows)...
    Thanks for pointing out the PR @Ruchir btw, I'm also wondering why it hasn't been merged yet :eek:
     
    Ruchir likes this.
  22. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    So, for anyone who is interested in this, the PR that @Ruchir has pointed out indeed fixes this behaviour. I've carefully merged it myself into 2021.2 b14 and it works perfectly. If the specular is set to 0 then the result is identical to disabling specular in the light component. Now I wonder how to correctly convert metallic workflow (metalness map) to specular workflow...
     
    Ruchir likes this.
  23. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    481
    Hi. I double the request. Setting the specular color to black to cut the specular highlights is a great addition, but it is not usable for all material types, except the specular one.

    I work a lot with vegetation, where you would use transmission or sss, where there is no way to control the spec color and you get that shiny metallic yellow white ish shading on backfaces. This can be easily disabled by changing one line of code in the shader in the forward pass, but no way to do it in deferred.

    Having 2 directional lights it's not working with shadow casting as DrSeltsam said.

    This is one of the most asked question when it comes to hdrp and vegetation rendering on my discord, so having this option on the material would be great. Thank you!
     
    jjbish and Ruchir like this.
  24. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    481
    To exemplify, here is a branch using the lit shader:
    upload_2021-10-25_8-37-23.png

    And here it is with disabled specular:
    upload_2021-10-25_8-39-16.png
     
  25. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    481
    Hey, you could use this function from UnityStandardUtils:
    upload_2021-10-25_8-45-52.png
    or this one if you are using ASE:
    upload_2021-10-25_8-48-18.png

    I guess it still applies to HDRP. I hope it helps.
     

    Attached Files:

    Reanimate_L and Ruchir like this.
  26. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Seems like what I need. Thanks! :)
     
    BOXOPHOBIC likes this.
  27. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    481
    Ruchir likes this.
  28. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,120
    I faced this problem recently, originally I thought it was a problem with one of the shaders I'm using, but turns out it's caused by the specular on the vegetation. My night scene is almost impossible to do because of this issue.



    this picture is mild, it gets worse
     
    Ruchir likes this.
  29. Deleted User

    Deleted User

    Guest

  30. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    330
    Bump, any news?
     
  31. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    Bump, Unity pls fix this. Foliage with white specular is so ugly.
     
    Fooslie and Deleted User like this.
  32. DrSeltsam

    DrSeltsam

    Joined:
    Jul 24, 2019
    Posts:
    100
    Are there any updates on this? It's annoying that there is still no proper way to get fully rid of specular light. The original PR on git is more than 1.5 years old. It was recently closed with the message that this will be recreated in the private repo...
     
  33. francescoc_unity

    francescoc_unity

    Unity Technologies

    Joined:
    Sep 19, 2018
    Posts:
    193
    The internal PR has been approved today; it will soon go through the process so I don't have a precise release date, but should be there "soon" :)
     
    Ruchir, DrSeltsam and PutridEx like this.
  34. DrSeltsam

    DrSeltsam

    Joined:
    Jul 24, 2019
    Posts:
    100
    These are great news, thanks for letting us know! :)
     
  35. EricFFG

    EricFFG

    Joined:
    May 10, 2021
    Posts:
    176
    Just use a shader with custom specular occlusion enabled and put in black
     
  36. DrSeltsam

    DrSeltsam

    Joined:
    Jul 24, 2019
    Posts:
    100
    Even if you set custom specular occlusion to 0, you still won't get rid of specular highlights from direct lighting. Currently there is no proper solution to get rid of specular light per object/material, but that should be fixed with the PR mentioned above.
     
  37. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    481
    I really wish the PR is applied on Smoothness instead of Spec Color. There is only one shader having the specular color, for the rest the PR is useless and most of us want it on transmission shaders.
     
  38. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    God damn, unity, are you serious? Why we are still not have a control for specular?
     
  39. StuwuStudio

    StuwuStudio

    Joined:
    Feb 4, 2015
    Posts:
    165
    In URP, for a pure-mirror metal (metallic=1, smoothness=1), clicking the "turn off specular highlight option" looks like an absolute mess. How has this not been fixed? I don't want to fix these kinds of thing myself because I know it'll just break something next time URP gets updated with a new feature.
     
  40. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    631
    Hi, the specular highlight off option in URP material isn't physically-based (for artistic use), which means you usually don't need to disable it.

    Specular Highlight Off: disable (direct) specular highlights from Unity lights. This also seems to set metallic to 0 in Deferred rendering path.
    Environment Reflection Off: disable (indirect) specular lighting from environment (reflection probes).
     
  41. StuwuStudio

    StuwuStudio

    Joined:
    Feb 4, 2015
    Posts:
    165
    I'm not sure what you're suggesting here.
    The specular option should turn off the specular highlight. Why is it just smearing white all over a metallic surface?
    Am I just stuck manually editing the shader files? Because this just looks like to me like a weird bug.
     
  42. StuwuStudio

    StuwuStudio

    Joined:
    Feb 4, 2015
    Posts:
    165
    Looks like I accidentally cropped the shader parameters at the bottom but right one has specular off, left has them on.
     
  43. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    631
    If the ring highlight is from skybox or reflection probe, this is called indirect reflection and you should remove it yourself.

    As I mentioned, "Specular Highlights Off" also seems to set metallic to 0 in Deferred rendering path.
     
  44. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    631
    I've tested this again in 2022.2.19 (URP).

    Forward (correct):
    Forward_SpecularOff.jpg

    Deferred (incorrect):
    Deferred_SpecularOff.jpg

    The metallic in (Deferred) GBuffers is also set to 0 when disabling specular highlights but this seems to be expected.
    URP_GBufferPass.jpg

    I suggest switching to Forward rendering path or report this as a bug.
     
    StuwuStudio likes this.
  45. StuwuStudio

    StuwuStudio

    Joined:
    Feb 4, 2015
    Posts:
    165
    Alright, I'll be reporting this as a bug, eventually.
    Forward is not really an option, deferred is improving my performance by a lot on PC.
     
    wwWwwwW1 likes this.