Last active
July 24, 2022 10:26
-
-
Save EricHu33/4fec7242da31424304c9a1cf68d8728c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "URP/CustomLighting" | |
{ | |
Properties | |
{ | |
_BaseColor ("Base Color", Color) = (1, 1, 1, 1) | |
} | |
SubShader | |
{ | |
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "SimpleLit" "IgnoreProjector" = "True" "ShaderModel" = "4.5" } | |
LOD 300 | |
Pass | |
{ | |
Tags { "LightMode" = "UniversalForward" } | |
HLSLPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma prefer_hlslcc gles | |
#pragma exclude_renderers d3d11_9x | |
#pragma target 2.0 | |
// ------------------------------------- | |
// Universal Pipeline keywords | |
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS | |
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE | |
// ------------------------------------- | |
// Unity defined keywords | |
#pragma multi_compile _ DIRLIGHTMAP_COMBINED | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" | |
CBUFFER_START(UnityPerMaterial) | |
float4 _BaseMap_ST; | |
half4 _BaseColor; | |
CBUFFER_END | |
struct Attributes | |
{ | |
float4 positionOS : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct Varyings | |
{ | |
float2 uv : TEXCOORD0; | |
float3 positionWS : TEXCOORD1; | |
float4 positionHCS : SV_POSITION; | |
}; | |
TEXTURE2D(_BaseMap); | |
SAMPLER(sampler_BaseMap); | |
Varyings vert(Attributes IN) | |
{ | |
Varyings OUT; | |
VertexPositionInputs positionInputs = GetVertexPositionInputs(IN.positionOS.xyz); | |
OUT.positionHCS = positionInputs.positionCS; | |
OUT.positionWS = positionInputs.positionWS; | |
OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap); | |
return OUT; | |
} | |
half4 frag(Varyings IN) : SV_Target | |
{ | |
half4 color = _BaseColor; | |
return _BaseColor; | |
} | |
ENDHLSL | |
} | |
//Reduce duplicate code by using `UsePass`, this breaks srp batcher due to other shader's cbuffer are different then ours | |
UsePass "Universal Render Pipeline/Simple Lit/ShadowCaster" | |
UsePass "Universal Render Pipeline/Simple Lit/DepthOnly" | |
UsePass "Universal Render Pipeline/Simple Lit/Meta" | |
UsePass "Universal Render Pipeline/Simple Lit/Universal2D" | |
} | |
Fallback "Hidden/Universal Render Pipeline/FallbackError" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment