Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Missing/Changed LIGHT_ATTENUATION macro?

Discussion in 'Graphics Experimental Previews' started by a-shoulson, Jan 9, 2018.

  1. a-shoulson

    a-shoulson

    Joined:
    Jun 24, 2015
    Posts:
    8
    This may be a little premature, but it seems in the 2018.1.0b1 preview (from the InputManager release), compiling a shader with the LIGHT_ATTENUATION() macro gives a syntax error (unexpected token ';'). Has this macro been removed/altered in 2018.1 and/or has it been replaced with anything?

    Code (csharp):
    1.  
    2. float4 frag(VertexOutput i) : COLOR {
    3.    // ...
    4.    float attenuation = LIGHT_ATTENUATION(i);
    5.    // ...
    6. }
    7.  
    Replacing the macro with just a float literal (like 1.f) removes the error.
     
    Last edited: Jan 9, 2018
    CSaw9000RKG and Macieqs like this.
  2. CSaw9000RKG

    CSaw9000RKG

    Joined:
    Dec 2, 2016
    Posts:
    1
    We are seeing this issue too on 2018.1.0b2 and are interested to know if there is a replacement planned?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    LIGHT_ATTENUATION has been deprecated since Unity 5 shipped in 2015. It was replaced with UNITY_LIGHT_ATTENUATION.

    Note the various TRANSFER_SHADOW macros were also deprecated. See this tutorial for how to update your shaders to work.
    http://catlikecoding.com/unity/tutorials/rendering/part-17/
     
  4. theolagendijk

    theolagendijk

    Joined:
    Nov 12, 2014
    Posts:
    117
    Thanks!

    I noticed that the *UNITY_LIGHT_ATTENUATION* code example shows ;
    Code (CSharp):
    1. UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos.xyz);
    That has to be ;
    Code (CSharp):
    1. UNITY_LIGHT_ATTENUATION(attenuation, i, i.posWorld.xyz);
     
    KFJ2112, Stephen_O and CloudyVR like this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That would depend on your shader. If you've named the world position variable i.posWorld, then yes, otherwise no. It might be a.MonkeysUncle if someone so chose.
     
    theolagendijk likes this.
  6. theolagendijk

    theolagendijk

    Joined:
    Nov 12, 2014
    Posts:
    117
    Apologies, you're right of course. :D
    I'm embarrassed. Thanks!
     
  7. RPGgrenad

    RPGgrenad

    Joined:
    Jun 4, 2017
    Posts:
    2
    I checked out the tutorial, but I'm having a difficult time understanding how to apply the UNITY_LIGHT_ATTENUATION stuff.

    My shaders use something basically the same as the example at the start of this thread, could you give an updated version of the example shown above? Thank you very much for the tutorial, by the way. Will be referring to it in the future.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos.xyz);

    That defines and sets a variable named attenuation that has both the shadow and light attenuation value.
     
  9. JamesJQuinn12

    JamesJQuinn12

    Joined:
    Jan 6, 2016
    Posts:
    2
    You guys saved me, thanks!
     
  10. fau7

    fau7

    Joined:
    Jan 24, 2018
    Posts:
    48
    Hi guys,
    I would like to use the LIGHT_ATTENUATION in my shader. But I can't seem to find an up-to-date explanation how to use it even in the documents. :/ My bad... Does anyone have any experience in 2018?
     
    IgorAherne and mkusan like this.
  11. ShaftTheGamer

    ShaftTheGamer

    Joined:
    Jun 13, 2016
    Posts:
    1
    Any chance to find documentation on what the UNITY_LIGHT_ATTENUATION macro actually does? Or, at east, where is it defined, so i can see the code for myself, if there are no docs?
    The LIGHT_ATTENUATION only took vertex output construction as an input, but it looks like it's not the case anymore. What variables does the updated macro take?
     
    mkusan likes this.
  12. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Download the builtin shader source (see the first post on the shader forum).
     
    mkusan and fau7 like this.
  13. fau7

    fau7

    Joined:
    Jan 24, 2018
    Posts:
    48
    Thank you very much bgolus. Doing as you said right now.
     
  14. kyewong

    kyewong

    Joined:
    Sep 11, 2014
    Posts:
    22
    Hi, I noticed that 'UNITY_LIGHT_ATTENUATION' enables both the shadows and reflected lightings at the same time. Is there an option which enables only the shadows pls?
     
  15. Tortuap

    Tortuap

    Joined:
    Dec 4, 2013
    Posts:
    137
    Yes, LIGHT_ATTENUATION.
     
  16. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393