Custom Shader Compatibility
This page is only relevant for Forward and Forward+ rendering paths. If you are using deferred rendering, custom shader graphs that use the Lit material will automatically work.
You can add AdaptiveGI support to both custom shader graphs and custom text-based shaders.
Shader Graph
AdaptiveGI natively supports custom shader graphs by using a subgraph. To add AdaptiveGI support to a custom shader graph, simply put the Sample AdaptiveGI subgraph between your custom graph nodes and the fragment shader output. To add the subgraph, simply right click in the shader graph window, select Create Node and double click Sample AdaptiveGI. After that connect each output of the subgraph to the corresponding input on the fragment block.




Now you can connect your shader graph outputs as normal to the Sample AdaptiveGI subgraph.
Amplify Shader Editor
AdaptiveGI natively supports custom shaders created using the Amplify Shader Editor. To add AdaptiveGI support to an Amplify Shader, simply put the Sample Adaptive GI node between your custom graph nodes and the master node output. To add the node, simply right click in the editor window, search "Sample Adaptive GI" and select it to create the node. After that connect each output of the node to the corresponding input on the master node.



Now you can connect your shader's outputs as normal to the Sample Adaptive GI node.
Text Shaders
AdaptiveGI natively supports custom text-based shaders by calling a single HLSL function. Here are the steps to add AdaptiveGI support to your own shaders:
Add required include lines shown below to your shader's UniversalForward pass. Note that this assumes that AdaptiveGI is imported at the root of your project's assets folder. Modify the last line's path if you moved AdaptiveGI to another folder.
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SphericalHarmonics.hlsl" #include "Assets/AdaptiveGI/Shaders/Utilities/SampleAdaptiveGI.hlsl"
AdaptiveGI requires world space position and normals to function. These can be acquired in a number of ways depending on if you use a normal map, vertex normals, etc.
For example, if you're using vertex normals:
Add positionWS and normalWS to your Varyings struct:
float3 positionWS : TEXCOORD0; float3 normalWS : TEXCOORD1;
Calculate world space position and normals from object space in the vertex shader:
OUT.positionWS = TransformObjectToWorld(IN.positionOS.xyz); OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
Call the "GetGridLighting_float()" function in the fragment shader:
half3 giColor; GetGridLighting_float(IN.positionWS, IN.normalWS, sampler_LinearClamp, giColor);
You can now use the giColor however you want in your custom shader! The most common (and physically correct) way to use giColor would be multiplying it by your final base color.
half3 finalColor = _BaseColor.rgb * giColor; return half4(finalColor, _BaseColor.a);
Putting it all together in a simple Unlit shader, here is an example:
Shader "Custom/AdaptiveGISample"
{
Properties
{
_BaseColor ("Base Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderPipeline"="UniversalPipeline" }
// Forward
Pass
{
Name "Unlit"
Tags { "LightMode"="UniversalForward" }
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SphericalHarmonics.hlsl"
#include "Assets/AdaptiveGI/Shaders/Utilities/SampleAdaptiveGI.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float3 positionWS : TEXCOORD0;
float3 normalWS : TEXCOORD1;
};
half4 _BaseColor;
Varyings vert (Attributes IN)
{
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.positionWS = TransformObjectToWorld(IN.positionOS.xyz);
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
return OUT;
}
half4 frag (Varyings IN) : SV_Target
{
half3 giColor;
GetGridLighting_float(IN.positionWS, IN.normalWS, sampler_LinearClamp, giColor);
half3 finalColor = _BaseColor.rgb * giColor;
return half4(finalColor, _BaseColor.a);
}
ENDHLSL
}
// DepthNormals (Used for SSAO)
Pass
{
Name "DepthNormals"
Tags { "LightMode"="DepthNormals" }
ZWrite On
ZTest LEqual
HLSLPROGRAM
#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
ENDHLSL
}
}
FallBack "Hidden/Universal Render Pipeline/FallbackError"
}Last updated