Search Unity

Question Using SAMPLE_SCENE_COLOR in custom function

Discussion in 'Shader Graph' started by zilhk_, Nov 22, 2020.

  1. zilhk_

    zilhk_

    Joined:
    Oct 14, 2015
    Posts:
    2
    Hi there,

    I'm trying to use Scene Color in a custom function but all I get is a grey output. My function just calls
    SHADERGRAPH_SAMPLE_SCENE_COLOR() and returns the color (see screenshot below). My goal is to code a shader graph node that does a screen blur.

    If I replace my custom function by the Scene Color node then it works perfectly so I assume my setup is correct (transparent surface + generate opaque texture).

    Any help is welcome, thanks!

    (Unity 2019.4 - latest packages)

    upload_2020-11-22_17-58-29.png
     
    Last edited: Nov 23, 2020
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,
    I'm not sure if I follow your logic - couldn't you use Custom Function node and input the necessary things like UV, sampler state and a Texture2D, and then create your blur by writing necessary code in a file or that Body box. That's how I've done a blur node.
     
    zilhk_ likes this.
  3. zilhk_

    zilhk_

    Joined:
    Oct 14, 2015
    Posts:
    2
    Hi Olmi,
    I didn't realized you could access the opaque texture directly, which you can with a reference to _CameraOpaqueTexture (see screenshot below). Using that texture I was able to do the blur in HLSL so thanks a bunch!

    Just out of curiosity, shouldn't the call to SHADERGRAPH_SAMPLE_SCENE_COLOR() have worked though? May be I need to add some #define the HLSL script to be able to use it or something like that?

    upload_2020-11-23_9-53-38.png
     
    PoweredByUnity likes this.
  4. Art-Leaping

    Art-Leaping

    Joined:
    Apr 2, 2015
    Posts:
    22
    In looking at the compiled shader - it would appear that it just calls the function (SHADERGRAPH_SAMPLE_SCENE_COLOR), but never actually defines it - which should throw an error, but doesn't. Super weird.

    If you use the "Scene Color" node somewhere in your graph, it'd probably work, but that would be unnecessarily redundant...
     
  5. funnymanwin

    funnymanwin

    Joined:
    Mar 20, 2020
    Posts:
    12
    SHADERGRAPH_SAMPLE_SCENE_COLOR(UV.xy) - works only if node "Scene Color" included in you graph. I dont know wtf, but it here you can see my tests:
    upload_2022-11-14_13-36-33.png upload_2022-11-14_13-37-14.png upload_2022-11-14_13-40-15.png upload_2022-11-14_13-40-41.png
     
  6. wechat_os_Qy05S7nbbQGL8b3ltmj_rS0oA

    wechat_os_Qy05S7nbbQGL8b3ltmj_rS0oA

    Joined:
    Apr 18, 2022
    Posts:
    1