Skip to content

Instantly share code, notes, and snippets.

@mycodingdad
Last active September 30, 2019 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mycodingdad/77d3e85621f353fb7bd1101ea9ac104b to your computer and use it in GitHub Desktop.
Save mycodingdad/77d3e85621f353fb7bd1101ea9ac104b to your computer and use it in GitHub Desktop.
Unity shader for Universal RP and AR Foundation, renders as transparent with occlusion and shadows. Put this on AR planes to get shadows and occlusion for 3D objects. (From https://gist.github.com/StigOlavsen/c75c78df4e704aeb5f904b6c851748ff)
Shader "AR Proxy"
{
Properties
{
}
SubShader
{
Tags
{
"RenderType" = "Transparent"
"RenderPipeline" = "UniversalPipeline"
"IgnoreProjector" = "True"
}
LOD 300
Pass
{
Name "AR Proxy"
Tags
{
"LightMode" = "UniversalForward"
}
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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment