-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnlit-Stereo-w-A1.shader
88 lines (77 loc) · 2.67 KB
/
Unlit-Stereo-w-A1.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
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
// Unlit shader. Simplest possible textured shader.
// - no lighting
// - no lightmap support
// - no per-material color
Shader "Unlit/Texture Stereo with alpha v1" {
Properties {
[Enum(Side by Side, 0, Over Under, 1, Separate Images, 2)] _Layout("3D Mode", Float) = 0
[NoScaleOffset] _MainTex ("Main/Left Texture", 2D) = "white" {}
[NoScaleOffset] _MainTexR ("Right Texture (only use when using separate images)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
// Tags { "RenderType"="Opaque" }
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 100
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _MainTexR;
float4 _MainTexR_ST;
int _Layout;
fixed _Cutoff;
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
fixed4 col;
if (_Layout == 0) { // Side-by-Side
col = tex2D(_MainTex, float2((i.texcoord.x * 0.5) + unity_StereoEyeIndex * 0.5, i.texcoord.y));
}
else if (_Layout == 1) { // Over-Under
col = tex2D(_MainTex, float2(i.texcoord.x, (i.texcoord.y * 0.5) + (unity_StereoEyeIndex == 0 ? 0.5 : 0)));
}
else { // Separate
if (unity_StereoEyeIndex == 0) {
col = tex2D(_MainTex, i.texcoord);
}
else {
col = tex2D(_MainTexR, i.texcoord);
}
}
UNITY_APPLY_FOG(i.fogCoord, col);
// UNITY_OPAQUE_ALPHA(col.a);
clip(col.a - _Cutoff);
return col;
}
ENDCG
}
}
}