forked from Cyanilux/URP_ShaderCodeTemplates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
URP_UnlitTemplate.shader
77 lines (65 loc) · 1.88 KB
/
URP_UnlitTemplate.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
// Example Shader for Universal RP
// Written by @Cyanilux
// https://www.cyanilux.com/tutorials/urp-shader-code
Shader "Cyanilux/URPTemplates/UnlitShaderExample" {
Properties {
_BaseMap ("Example Texture", 2D) = "white" {}
_BaseColor ("Example Colour", Color) = (0, 0.66, 0.73, 1)
//_ExampleVector ("Example Vector", Vector) = (0, 1, 0, 0)
//_ExampleFloat ("Example Float (Vector1)", Float) = 0.5
}
SubShader {
Tags {
"RenderPipeline"="UniversalPipeline"
"RenderType"="Opaque"
"Queue"="Geometry"
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _BaseMap_ST;
float4 _BaseColor;
//float4 _ExampleVector;
//float _ExampleFloat;
CBUFFER_END
ENDHLSL
Pass {
Name "Unlit"
//Tags { "LightMode"="SRPDefaultUnlit" } // (is default anyway)
HLSLPROGRAM
#pragma vertex UnlitPassVertex
#pragma fragment UnlitPassFragment
// Structs
struct Attributes {
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
struct Varyings {
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
// Textures, Samplers & Global Properties
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
// Vertex Shader
Varyings UnlitPassVertex(Attributes IN) {
Varyings OUT;
VertexPositionInputs positionInputs = GetVertexPositionInputs(IN.positionOS.xyz);
OUT.positionCS = positionInputs.positionCS;
// Or :
//OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
OUT.color = IN.color;
return OUT;
}
// Fragment Shader
half4 UnlitPassFragment(Varyings IN) : SV_Target {
half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
return baseMap * _BaseColor * IN.color;
}
ENDHLSL
}
}
}