-
Notifications
You must be signed in to change notification settings - Fork 5
/
Vignette 1.shader
92 lines (83 loc) · 2.17 KB
/
Vignette 1.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
Shader "Hidden/Custom/Vignette 1"
{
Properties
{
_MainTex ("MainTex", 2D) = "white" {}
_fade ("Opacity", float) = 1
_intensity ("Intensity", float) = 1
_width ("Width", float) = 0.5
_height ("Height", float) = 0.5
_ellipse ("Ellipse", float) = 2
_fuzzy ("Fuzzy", float) = 0
}
SubShader
{
Tags
{
"QUEUE"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
Pass
{
Cull Off Lighting Off ZWrite Off
Fog { Mode Off }
Offset -1, -1
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#pragma exclude_renderers xbox360 ps3 flash
#include "UnityCG.cginc"
struct v2f
{
float4 vertex : POSITION;
float2 uv: TEXCOORD0;
float2 worldPos : TEXCOORD1;
};
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord: TEXCOORD0; // 输入的模型纹理坐标集
};
float _fade;
float _intensity;
float _width;
float _height;
float _ellipse;
float _fuzzy;
float4 _MainTex_ST; // 区域图采样
sampler2D _MainTex; // 区域图样本对象
float4 _ClipRange0 = float4(0.0, 0.0, 1.0, 1.0);
float2 _ClipArgs0 = float2(1000.0, 1000.0);
v2f vert(in appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.worldPos = v.vertex.xy * _ClipRange0.zw + _ClipRange0.xy;
return o;
}
half4 frag(v2f IN) : COLOR
{
// Softness factor
float2 factor = (float2(1.0, 1.0) - abs(IN.worldPos)) * _ClipArgs0;
half4 mainCol = tex2D(_MainTex , IN.uv);
half4 fragColor = (0.0,0.0,0.0,0.0);
float2 p = (_MainTex_ST.xy - 2.0 * IN.uv.xy) / _MainTex_ST.y;
half4 col = (1.0,1.0,1.0);
col.w = clamp(pow(abs(p.x / 0.5)* _width, _ellipse) +
pow(abs(p.y / 0.5)* _height, _ellipse), 0.0, 1.0);
half res = step(1.0, col.w);
half colw = 1.0 - res;
col.w *= _fade * _intensity * _fuzzy * colw;
fragColor = lerp(mainCol, col, col.w) * colw;
fragColor.a *= clamp( min(factor.x, factor.y), 0.0, 1.0);
return fragColor;
}
ENDCG
}
}
FallBack "Diffuse"
}