• Stars
    star
    524
  • Rank 84,033 (Top 2 %)
  • Language HLSL
  • License
    MIT License
  • Created almost 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Some custom lighting functions/sub-graphs for Shader Graph, Universal Render Pipeline

Shader Graph Custom Lighting

Some custom lighting functions/sub-graphs for Shader Graph, Universal Render Pipeline. If anything breaks, let me know by opening an issue!

+ This version is for URP v12+ (Unity 2021.2+) For use with older versions use the v8 branch!

Setup:

  • Install via Package Manager → Add package via git URL :
    • https://github.com/Cyanilux/URP_ShaderGraphCustomLighting.git
  • Alternatively, download and put the folder in your Assets

Includes Sub Graphs for :

Main Light

  • Main Light
    • Outputs : Direction, Colour, CullingMask
  • Main Light Shadows
    • Inputs : WorldPosition, Shadowmask (can leave at 1,1,1,1 if you don't need it)
    • Outputs : ShadowAtten
    • (Now works with all Shadow Cascades settings!)
  • Main Light Cookie- For supporting cookies. Will also enable cookies for additional lights (as they use the same keyword)
    • Inputs : WorldPosition
    • Outputs : Cookie
  • Main Light Layer Test - For supporting Light Layers. Pass your shading calculation from main light through here.
    • Inputs : Shading
    • Output : Out (with layer mask applied)
  • Main Light Diffuse (handles Lambert / NdotL calculation)
    • Inputs : Normal
    • Outputs : Diffuse
  • Main Light Specular Highlights - handles specular highlights based on Phong or BlinnPhong models
    • Inputs : Smoothness, Normal
    • Outputs : Specular

Other

  • Additional Lights - Loops through each additional light, point, spotlights, etc. Handles diffuse, specular and shadows. Supports Forward+ path (in 2022.2+)
    • Also supports cookies if Main Light Cookie node is used (or _LIGHT_COOKIES Boolean Keyword is defined in Blackboard)
    • Also supports light layers if Main Light Layer Test node is used (or _LIGHT_LAYERS Boolean Keyword is defined in Blackboard)
    • For creating custom lighting models, you'll need to copy this function and edit it due to the loop, e.g. swap the LightingLambert and LightingSpecular functions out for custom ones. Also see the AdditionalLightsToon function as an example
    • Inputs : SpecularColour, Smoothness, Normal, Shadowmask
    • Outputs : Diffuse, Specular
  • Sample Shadowmask - attach this to the Shadowmask port on the Main Light Shadows and Additional Lights sub graphs, in order to support Shadowmask baked lighting mode
    • Outputs : Shadowmask
  • Ambient SampleSH - uses per-pixel SampleSH, use add node to apply this. Can alternatively use the built-in Baked GI node)
    • Inputs : Normal
    • Outputs : Ambient
  • Subtractive GI - for supporting Subtractive baked lighting mode. Should connect Main Light Shadows node to first port. Uses MixRealtimeAndBakedGI function from URP ShaderLibrary
    • Inputs : ShadowAtten, Normal, BakedGI
    • Outputs : Out (Vector3)
  • Mix Fog - applies fog to the colour, should be used just before outputting to BaseColor on Master Stack
    • Inputs : Colour
    • Outputs : Out (Vector3, colour with fog applied)

Deprecated

  • Phong Specular and Blinn-Phong Specular subgraphs are now considered deprecated - use Main Light Specular Highlights instead.

Included Examples

  • Toon - Toon/Cel Shading. Main Light (ramp texture) & Additional Lights (number of bands). Also supports Main Light Cookies, BakedGI (including Subtractive & Shadowmask), Fog
  • Shadow Receiver - Transparent material that receives shadows and can set their colour. Can turn off casting via Mesh Renderer

More Repositories

1

URP_BlitRenderFeature

Blit Render Feature for Universal RP's Forward Renderer. Set specific source/destination via camera source, ID string or RenderTexture asset. Also options for _InverseView matrix and _CameraNormalsTexture generation.
C#
565
star
2

URP_ShaderCodeTemplates

A few shader code templates/examples for Unity, Universal Render Pipeline (URP v10 / Unity 2020.3). ShaderLab & HLSL.
ShaderLab
267
star
3

ShaderGraphVariables

Adds 'Register Variable' and 'Get Variable' nodes to Shader Graph, allowing you to link sections of a graph without connection wires. <3
C#
251
star
4

URP_WatercolourShaders

A few experiments with watercolour-like shader effects made using Shader Graph. Unity 2020.1.2f1, URP 8.2.0
C#
180
star
5

BakeShader

Unity editor tool for baking shaders to textures. Texture2D, Texture3D, Flipbook, or MeshRenderer (uses model UV)
C#
163
star
6

URP_RetroCRTShader

A shader graph which replicates some retro tv/monitor effects. CRT (cathode-ray tube) warping, scanlines, static, distortion, etc.
C#
141
star
7

Cards

A few scripts which controls interactions for a hand of cards. Card model, shadergraph and example setup included.
C#
128
star
8

ShaderGraphToPNG

Screenshots a Shader Graph in multiple sections, stitches them together and saves the result as a PNG
C#
117
star
9

ToDo

Unity in-editor to-do list, attached as a component and uses a custom inspector based on ReorderableList. Also see branches for ScriptableObject / cross-scene reference version.
C#
81
star
10

URP_GrassGeometryShader

Example of a Grass Geometry Shader for Unity, Universal Render Pipeline. Based on https://github.com/IronWarrior/UnityGrassGeometryShader
HLSL
63
star
11

cyanilux.github.io

Tutorial/blog site, generated using Hugo
HTML
2
star