-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path95-Shader__GrabTexture Shader-NewUnlitShader.shader.txt
75 lines (66 loc) · 1.77 KB
/
95-Shader__GrabTexture Shader-NewUnlitShader.shader.txt
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
Shader "Unlit/#NAME#"
{
// The grab pass lets you access a texture of what has been rendered before.
// https://docs.unity3d.com/Manual/SL-GrabPass.html
// If you're just changing colour, you probably just want to use blend modes,
// but using the grab pass lets you change what pixel you're sampling for distortion effects.
// This shader should appear invisible because I'm not changing anything yet.
Properties
{
}
SubShader
{
Tags {
"RenderType"="Opaque"
"Queue" = "Transparent"
}
LOD 100
// _BackgroundTexture is an arbitrary name
// If multiple meshes or shaders use the same name, it will use the same texture for all of them
// If another shader uses a different name, it's supposed to grab another grab pass at that time
GrabPass{
"_BackgroundTexture"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _BackgroundTexture;
float4 _BackgroundTexture_TexelSize;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
//this is a dumb thing where some computers have inverted y co-ordinates from others
//but at least Unity provides a constant that lets you know if that's the case
#if UNITY_UV_STARTS_AT_TOP
float scale = -1;
#else
float scale = 1;
#endif
o.uv.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
//----------------------
o.uv.zw = o.vertex.zw;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the grab texture
fixed4 col = tex2Dproj( _BackgroundTexture, UNITY_PROJ_COORD(i.uv));
return col;
}
ENDCG
}
}
}