Skip to content

andypoly/Unity-Shader-Graph-Custom-Functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

Unity Shader Graph Custom Functions (URP focused)

Notes on using Custom Function Nodes in Unity Shader graph

(Unity 2022 LTS)

To see see a fullscreen Shader Graph effect to do URP outlines & using a custom function node - download the unity package here.

Custom Function Node Documentation: https://docs.unity3d.com/Packages/[email protected]/manual/Custom-Function-Node.html

Documentation for writing the code is sparse! To find out what functions & variables you can use and how to read from the screen buffers, grab files like Functions.hlsl and ShaderVariables.hlsl from in Packages\Shader Graph\ShaderGraphLibrary. To see the actual code for say URP - view the ShaderLibrary folder under the Universal RP package.

Fullscreen shader graphs

https://docs.unity3d.com/Packages/[email protected]/manual/post-processing/post-processing-custom-effect-low-code.html

You can sample Depth, Color and Normal if you have them enabled (Set the requirements in your FullScreenPassRendererFeature). Pass Screen Position into your custom function node from the graph.

Reading from screen buffers:

SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv);

But the depth is different under different graphics APIs so you should check out common.hlsl to handle it! An orthographic Camera just needs z values flipping #if defined(UNITY_REVERSED_Z) A normal camera should convert depth to 'LinearEyeDepth'.

SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);

Currently this will only work if you have a Scene Color Node used in your graph! But as pointed out by https://github.com/smitdylan2001 you can add a keyword bool to your blackboard with the reference value as "REQUIRE_OPAQUE_TEXTURE" and default it to true. This will make it work as an alternative!!

SHADERGRAPH_SAMPLE_SCENE_NORMAL(uv);

If you need the texel size of the above textures you could use the available _ScreenParams (e.g. float2 texelSize = float2(1.0 / _ScreenParams.x, 1.0 / _ScreenParams.y);)

About

Notes on using Custom Functions Nodes in Unity Shader graph

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published