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
  2. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  3. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

How to get Worldspace Light Direction in ShaderGraph?

Discussion in 'Graphics Experimental Previews' started by Deadcow_, Jun 23, 2018.

  1. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    Hey there :) I found great example of rim light in Shader Graph by Keijiro
    but I want to create directional rim outline shader, like in this example.
    It suggests to apply WorldSpaceViewDir as rim offset.
    Is it possible to achieve something like this with Shader Graph?
     
  2. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    789
    You can learn from his graph how it's being done. All the info is in the picture although low res. Ultimately you can download the project he made available free with that example as well as others and look at how he made those shaders.

    https://github.com/keijiro/ShaderGraphExamples
     
  3. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    No I mean I know how to make rim light but wondering how to make shader graph with rim only on the lit side like on second example link
     
  4. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    789
    In that example, they are using lighting functions but shader graph doesn't have any nodes for that yet.

    upload_2018-6-23_14-35-19.png

    Looks like you can use the camera view direction to mask the rim light from the camera view angle
    Pretty sure there's a node in Shader graph for camera space
     
  5. toothbrush

    toothbrush

    Joined:
    Mar 24, 2017
    Posts:
    2
    You can access unity builtin variables by create a property whose reference is that variable. lightposVector.PNG
     
  6. AdrianMiasik-Outdated

    AdrianMiasik-Outdated

    Joined:
    Jan 14, 2015
    Posts:
    1
    The above worked for me. Thanks @toothbrush.

    Extra caveat for those on LWRP moving towards URP. It seems that built-in shaders variables shouldn't be exposed? This wasn't an issue on LWRP but moving to URP my shaders stopped rendering properly.
    Luckily it's a simple solution: don't expose those built-in variables

    Aforementioned warning:
    upload_2020-5-25_23-25-16.png

    Solution:
    upload_2020-5-25_23-25-23.png

    Uncheck those boxes ^^
     

    Attached Files:

  7. jzq740176597

    jzq740176597

    Joined:
    Jul 31, 2015
    Posts:
    17
    Try to create a var Reference "_WorldSpaceLightPos0" But issue error : "Shader error in 'Master': redefinition of '_WorldSpaceLightPos0' at line 1297 (on d3d11)"

    I also tried use custom-function of string type : manual use "_WorldSpaceLightPos0" complains that it not declared.

    Any hint?

    [Unity 2021.3.24f1 / platform: standalone / BuildIn Shader Graph]
     
    Zenchuck likes this.