Search Unity

Disable highlights for fill lights

Discussion in 'Shaders' started by jsr2k1, Apr 1, 2022.

  1. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Hello everyone,

    We are developing a WebGL 2.0 application, so deferred rendering is used. The scene is created from scratch during execution so we can't use baked lightmaps. We add spotlights for direct illumination with shadows and point lights for indirect illumination (fill lights) without shadows.

    The problem is that we need to disable the specular highlight only from point lights. We can't use the render mode: "Not Important" on point lights because of the deferred rendering.

    We can use the _SPECULARHIGHLIGHTS_OFF keyword in our custom shader, but we just want to deactivate highlights for certain lights (point lights without shadows).

    Any idea on how to get this?

    Thanks!
     
  2. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Hello everyone,

    This looks like a very specific issue, but it is important for interior design. Screen Space Global Illumination is not enough precise at this moment, maybe in the future. Or maybe the problem is our target graphics card, RTX 3060. For this reason, we need to add fill lights (point lights without shadows) using old-school techniques to illuminate the scene properly.

    As you can see in the attached picture, the lighting in this scene is quite good, but we really need to get rid of these specular highlights.

    Any ideas please? thanks

    kitchen.PNG
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Unity doesn't have a way to disable specular on specific deferred lights. But it is possible.

    The options are:

    A: Set the light to be Non-Important. This changes the light to be calculated per-vertex, which may not be ideal especially as you'll be limited to 4 of these per mesh and the falloff does not match per-pixel or deferred lights. It's also ... per-vertex ... and comes with the artifacts that per-vertex lighting does. But it will not have shadows or specular highlights. This is the only built in solution.

    B: Use custom deferred lights. There aren't a ton of resources on this out there, and unfortunately most of the store assets that used to exist have all disappeared, but there is an example in the Unity Blog post on command buffers here:
    https://blog.unity.com/technology/extending-unity-5-rendering-pipeline-command-buffers

    These should hopefully still "just work", but you'll need to modify the shader code for them to remove the specular highlights, which you can do by setting the
    specColor = 0.0
    . Or with a little more work you can modify the shader and CustomLight.cs to add a specular intensity you pass as the
    _CustomLightColor
    alpha you multiply the specular color by.

    It also adds the benefit of giving you access to tube and sphere lights, which should be much better for ambient fill lights than punctual lights anyway.

    There's also the old Adam Volumetrics repository that also includes a rectangular area light implementation.
    https://github.com/Unity-Technologies/VolumetricLighting
     
  4. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Thanks for your answer bgolus,

    As I've seen, marking a light as 'Not Important' only has an effect in forward rendering, but I use deferred because of the WebGL platform. I could try the second option.

    On the other hand, we have 2 versions of the project: WebGL and Pc. Recently, I tested the Pc version with HDRP and I've found that lights have the option 'Affect Specular' which in our case is just what we need.

    It is a pity that HDRP is not compatible with WebGL, maybe in the future with WebGPU, but at least we can optimize our Pc version.