Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Unity URP SSAO in "Depth normal" mode (#225) #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Shader "Graphics Tools/Standard"
#pragma multi_compile_instancing
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_local _ _CLIPPING_PLANE _CLIPPING_SPHERE _CLIPPING_BOX
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION

#pragma shader_feature_local_fragment _CLIPPING_BORDER

Expand Down Expand Up @@ -229,6 +230,124 @@ Shader "Graphics Tools/Standard"

ENDHLSL
}

// From Packages/com.unity.render-pipelines.universal/Shader/Lit.hlsl
Pass
{
Name "DepthOnly"
Tags
{
"LightMode" = "DepthOnly"
}

// -------------------------------------
// Render State Commands
ZWrite On
ColorMask R
Cull[_Cull]

HLSLPROGRAM
#if UNITY_VERSION >= 202230
#pragma exclude_renderers gles gles3 glcore
#pragma target 4.5
#else
#pragma target 2.0
#endif

// -------------------------------------
// Shader Stages
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment

// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

#if UNITY_VERSION >= 202200
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
#endif

//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#if UNITY_VERSION >= 202230
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
#else
#pragma multi_compile _ DOTS_INSTANCING_ON
#endif

// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
ENDHLSL
}

// From Packages/com.unity.render-pipelines.universal/Shader/Lit.hlsl
// This pass is used when drawing to a _CameraNormalsTexture texture
Pass
{
Name "DepthNormals"
Tags
{
"LightMode" = "DepthNormals"
}

// -------------------------------------
// Render State Commands
ZWrite On
Cull[_Cull]

HLSLPROGRAM
#if UNITY_VERSION >= 202230
#pragma target 2.0
#else
#pragma exclude_renderers gles gles3 glcore
#pragma target 4.5
#endif

// -------------------------------------
// Shader Stages
#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment

// -------------------------------------
// Material Keywords
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _PARALLAXMAP
#pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

#if UNITY_VERSION >= 202200
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ LOD_FADE_CROSSFADE
#endif
#if UNITY_VERSION >= 202230
// -------------------------------------
// Universal Pipeline keywords
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
#endif

//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#if UNITY_VERSION >= 202230
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
#else
#pragma multi_compile _ DOTS_INSTANCING_ON
#endif

// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitDepthNormalsPass.hlsl"
ENDHLSL
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#ifdef _SCREEN_SPACE_OCCLUSION
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/AmbientOcclusion.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
#endif
#else
#include "UnityCG.cginc"
#include "UnityStandardConfig.cginc"
Expand Down Expand Up @@ -801,6 +805,12 @@ half4 PixelStage(Varyings input, bool facing : SV_IsFrontFace) : SV_Target
half3 reflection = GTGlossyEnvironmentReflection(reflectVector, GTPerceptualSmoothnessToPerceptualRoughness(_Smoothness), occlusion);
output.rgb = (albedo.rgb * 0.5h) + (reflection * (_Smoothness + _Metallic) * 0.5h);
#endif

#if defined(_SCREEN_SPACE_OCCLUSION)
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.position);
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(normalizedScreenSpaceUV);
output.rgb *= aoFactor.directAmbientOcclusion;
#endif

// Fresnel lighting.
#if defined(_RIM_LIGHT)
Expand Down Expand Up @@ -836,7 +846,6 @@ half4 PixelStage(Varyings input, bool facing : SV_IsFrontFace) : SV_Target
incident.y * incident.y * _EnvironmentColorY +
incident.z * incident.z * _EnvironmentColorZ;
output.rgb += environmentColor * max(0.0, dot(incident, worldNormal) + _EnvironmentColorThreshold) * _EnvironmentColorIntensity;

#endif

#if defined(_NEAR_PLANE_FADE)
Expand Down