Skip to content

Instantly share code, notes, and snippets.

@DanMillerDev
Created April 3, 2019 23:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanMillerDev/68009b24a1f34b77760f67a3e3075277 to your computer and use it in GitHub Desktop.
Save DanMillerDev/68009b24a1f34b77760f67a3e3075277 to your computer and use it in GitHub Desktop.
// Shader targeted for low end devices. Single Pass Forward Rendering.
Shader "Custom/Shadows Only"
{
// Keep properties of StandardSpecular shader for upgrade reasons.
Properties
{
_Alpha("Shadow Alpha", float) = 0.5
// Blending state
[HideInInspector] _Surface("__surface", Float) = 0.0
[HideInInspector] _Blend("__blend", Float) = 0.0
[HideInInspector] _AlphaClip("__clip", Float) = 0.0
[HideInInspector] _SrcBlend("__src", Float) = 1.0
[HideInInspector] _DstBlend("__dst", Float) = 0.0
[HideInInspector] _ZWrite("__zw", Float) = 1.0
[HideInInspector] _Cull("__cull", Float) = 2.0
}
SubShader
{
Tags { "RenderType" = "Transparent" "RenderPipeline" = "LightweightPipeline" "IgnoreProjector" = "True"}
LOD 300
Pass
{
Name "ForwardLit"
Tags { "LightMode" = "LightweightForward" }
// Use same blending / depth states as Standard shader
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
Cull[_Cull]
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#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 LitPassVertexSimple
#pragma fragment ShadowsFragmentPass
#include "Packages/com.unity.render-pipelines.lightweight/Shaders/SimpleLitInput.hlsl"
#include "ShadowsOnlyPass.hlsl"
half4 ShadowsFragmentPass(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.uv;
half3 normalTS = SampleNormal(uv, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap));
InputData inputData;
InitializeInputData(input, normalTS, inputData);
half color = MainLightRealtimeShadow(input.shadowCoord);
return float4(color,color,color,1);
};
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On
ColorMask 0
Cull[_Cull]
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _GLOSSINESS_FROM_BASE_ALPHA
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include "Packages/com.unity.render-pipelines.lightweight/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.lightweight/Shaders/DepthOnlyPass.hlsl"
ENDHLSL
}
// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags{ "LightMode" = "Meta" }
Cull Off
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma vertex LightweightVertexMeta
#pragma fragment LightweightFragmentMetaSimple
#pragma shader_feature _EMISSION
#pragma shader_feature _SPECGLOSSMAP
#include "Packages/com.unity.render-pipelines.lightweight/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.lightweight/Shaders/SimpleLitMetaPass.hlsl"
ENDHLSL
}
}
Fallback "Hidden/InternalErrorShader"
}
@Goncharuk-Nikita
Copy link

Hello.
There is a problem with this shader, need update for 69 #include "ShadowsOnlyPass.hlsl".
Could you also post ShadowsOnlyPass.hlsl? And I would really appreciate any information about the demo project.

Thank you.

@RuhanAhmed
Copy link

Hello. There is a problem with this shader, need update for 69 #include "ShadowsOnlyPass.hlsl". Could you also post ShadowsOnlyPass.hlsl? And I would really appreciate any information about the demo project.

Thank you.

https://gist.github.com/DanMillerDev/92b0139e6d6d01bfd6b476a040b0c247

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