-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathURP Unlit.shader
137 lines (109 loc) · 5.69 KB
/
URP Unlit.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Shader "URP Template/Unlit"
{
Properties
{
[MainColor] [HDR] _BaseColor("Color", Color) = (1,1,1,1)
[MainTexture] _BaseMap("Albedo", 2D) = "white" {}
// _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend", Float) = 1.0
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend", Float) = 0.0
[Toggle] _ZWrite("Z Write", Float) = 1.0
[Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull", Float) = 2.0
}
SubShader
{
Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" "IgnoreProjector" = "True"}
LOD 300
Pass
{
Name "Standard Unlit"
Tags{"LightMode" = "UniversalForward"}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
Cull[_Cull]
HLSLPROGRAM
// Required to compile gles 2.0 with standard SRP library
// All shaders must be compiled with HLSLcc and currently only gles is not using HLSLcc by default
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
// -------------------------------------
// Material Keywords
// unused shader_feature variants are stripped from build automatically
// #pragma shader_feature _ALPHATEST_ON
// #pragma shader_feature _ALPHAPREMULTIPLY_ON
// #pragma shader_feature _EMISSION
#pragma multi_compile_fog
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex UnlitPassVertex
#pragma fragment UnlitPassFragment
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// Material shader variables are not defined in SRP or LWRP shader library.
// This means _BaseColor, _BaseMap, _BaseMap_ST, and all variables in the Properties section of a shader
// must be defined by the shader itself. If you define all those properties in CBUFFER named
// UnityPerMaterial, SRP can cache the material properties between frames and reduce significantly the cost
// of each drawcall.
// In this case, for sinmplicity LitInput.hlsl is included. This contains the CBUFFER for the material
// properties defined above. As one can see this is not part of the ShaderLibrary, it specific to the
// LWRP Lit shader.
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
// float4 tangentOS : TANGENT;
float2 uv : TEXCOORD0;
// float2 uvLM : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float2 uv : TEXCOORD0;
// float2 uvLM : TEXCOORD1;
float4 positionWSAndFogFactor : TEXCOORD2; // xyz: positionWS, w: vertex fog factor
half3 normalWS : TEXCOORD3;
float4 positionCS : SV_POSITION;
};
// TEXTURE2D(_BaseMap);
// SAMPLER(sampler_BaseMap);
// CBUFFER_START(UnityPerMaterial)
// half4 _BaseColor;
// CBUFFER_END
Varyings UnlitPassVertex(Attributes input)
{
Varyings output;
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
// VertexNormalInputs vertexNormalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
// output.uvLM = input.uvLM.xy * unity_LightmapST.xy + unity_LightmapST.zw;
float fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
output.positionWSAndFogFactor = float4(vertexInput.positionWS, fogFactor);
// output.normalWS = vertexNormalInput.normalWS;
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
output.positionCS = vertexInput.positionCS;
return output;
}
half4 UnlitPassFragment(Varyings input) : SV_Target
{
// normalWS = normalize(normalWS);
// float3 positionWS = input.positionWSAndFogFactor.xyz;
// half3 viewDirectionWS = SafeNormalize(GetCameraPositionWS() - positionWS);
half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
color.rgb = MixFog(color.rgb, input.positionWSAndFogFactor.w);
return color;
}
ENDHLSL
}
// Used for rendering shadowmaps
// UsePass "Universal Render Pipeline/Lit/ShadowCaster"
// Used for depth prepass
// If shadows cascade are enabled we need to perform a depth prepass.
// We also need to use a depth prepass in some cases camera require depth texture
// (e.g, MSAA is enabled and we can't resolve with Texture2DMS
// UsePass "Universal Render Pipeline/Lit/DepthOnly"
// Used for Baking GI. This pass is stripped from build.
// UsePass "Universal Render Pipeline/Lit/Meta"
}
}