Skip to content

Instantly share code, notes, and snippets.

@antonsem
Forked from StigOlavsen/arproxy.shader
Last active April 3, 2024 20:54
Show Gist options
  • Save antonsem/b294fa7b7443e017599ee7a87a22b8b4 to your computer and use it in GitHub Desktop.
Save antonsem/b294fa7b7443e017599ee7a87a22b8b4 to your computer and use it in GitHub Desktop.
Unity shader for LWRP and AR Foundation, renders as transparent with occlusion and shadows. Put this on AR planes to get shadows and occlusion for 3D objects.
Shader "AR Proxy"
{
Properties
{
}
SubShader
{
Tags
{
"RenderType" = "Transparent"
"RenderPipeline" = "UniversalPipeline"
"IgnoreProjector" = "True"
}
LOD 300
Pass
{
Name "AR Proxy"
Tags
{
"LightMode" = "LightweightForward"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On
Cull Off
HLSLPROGRAM
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
// -------------------------------------
// Material Keywords
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _ALPHAPREMULTIPLY_ON
// -------------------------------------
// Lightweight Pipeline keywords
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex HiddenVertex
#pragma fragment HiddenFragment
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct Attributes
{
UNITY_VERTEX_INPUT_INSTANCE_ID
float4 positionOS : POSITION;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float4 shadowCoord : TEXCOORD0;
};
Varyings HiddenVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
output.shadowCoord = GetShadowCoord(vertexInput);
output.positionCS = vertexInput.positionCS;
return output;
}
half4 HiddenFragment(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
half s = MainLightRealtimeShadow(input.shadowCoord);
return half4(0, 0, 0, 1 - s);
}
ENDHLSL
}
UsePass "Universal Render Pipeline/Lit/DepthOnly"
}
FallBack "Hidden/InternalErrorShader"
}
@Hoppenbrouwers
Copy link

Thank you for this! Works like a charm here. 2020.3.1f1 (LTS) with URP 10.3.2. using it together with AR Foundation PlaneOcclusionShader to render shadows on the ground. Really awesome work dude!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment