t1 / TFDContents / Assets / Resources / BlurShader.shader @ 9
이력 | 보기 | 이력해설 | 다운로드 (1.75 KB)
| 1 |
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' |
|---|---|
| 2 |
|
| 3 |
Shader "Custom/BlurShader" {
|
| 4 |
Properties {
|
| 5 |
_MainTex ("Base (RGB)", 2D) = "white" {}
|
| 6 |
_Amount ("Blur Amount", Range(0,4)) = 1
|
| 7 |
} |
| 8 |
|
| 9 |
CGINCLUDE |
| 10 |
#include "UnityCG.cginc" |
| 11 |
|
| 12 |
sampler2D _MainTex; |
| 13 |
float4 _MainTex_TexelSize; |
| 14 |
float _Amount; |
| 15 |
float _Threshold; |
| 16 |
|
| 17 |
struct v2f {
|
| 18 |
float4 pos : POSITION; |
| 19 |
float2 uv : TEXCOORD0; |
| 20 |
}; |
| 21 |
|
| 22 |
struct v2f_off {
|
| 23 |
float4 pos : POSITION; |
| 24 |
float2 uv[8] : TEXCOORD0; |
| 25 |
}; |
| 26 |
|
| 27 |
v2f vert (appdata_img v) |
| 28 |
{
|
| 29 |
v2f o; |
| 30 |
o.pos = UnityObjectToClipPos (v.vertex); |
| 31 |
o.uv = v.texcoord.xy; |
| 32 |
return o; |
| 33 |
} |
| 34 |
|
| 35 |
v2f_off vertOff (appdata_img v) |
| 36 |
{
|
| 37 |
v2f_off o; |
| 38 |
o.pos = UnityObjectToClipPos (v.vertex); |
| 39 |
|
| 40 |
float2 uv = v.texcoord.xy; |
| 41 |
float2 up = float2(0.0, _MainTex_TexelSize.y) * _Amount; |
| 42 |
float2 right = float2(_MainTex_TexelSize.x, 0.0) * _Amount; |
| 43 |
|
| 44 |
o.uv[0].xy = uv + up; |
| 45 |
o.uv[1].xy = uv - up; |
| 46 |
o.uv[2].xy = uv + right; |
| 47 |
o.uv[3].xy = uv - right; |
| 48 |
o.uv[4].xy = uv - right + up; |
| 49 |
o.uv[5].xy = uv - right -up; |
| 50 |
o.uv[6].xy = uv + right + up; |
| 51 |
o.uv[7].xy = uv + right -up; |
| 52 |
|
| 53 |
return o; |
| 54 |
} |
| 55 |
|
| 56 |
half4 fragOff (v2f_off i) : COLOR |
| 57 |
{
|
| 58 |
|
| 59 |
float4 col = tex2D(_MainTex, (i.uv[0] + i.uv[1]) * 0.5); |
| 60 |
float4 newCol = 0; |
| 61 |
newCol.rgb = col.rgb; |
| 62 |
int count = 1; |
| 63 |
for (int pix = 0; pix < 8; pix ++) {
|
| 64 |
if (i.uv[pix].x <= 1.0 && i.uv[pix].y <= 1.0 && i.uv[pix].x >= 0.0 && i.uv[pix].y >= 0.0) {
|
| 65 |
newCol += tex2D(_MainTex, i.uv[pix]); |
| 66 |
count ++; |
| 67 |
} |
| 68 |
} |
| 69 |
newCol = ((newCol + col) / (count + 1)); |
| 70 |
|
| 71 |
return newCol; |
| 72 |
} |
| 73 |
|
| 74 |
ENDCG |
| 75 |
|
| 76 |
SubShader {
|
| 77 |
ZTest Always Cull Off ZWrite Off |
| 78 |
pass {
|
| 79 |
CGPROGRAM |
| 80 |
#pragma vertex vertOff |
| 81 |
#pragma fragment fragOff |
| 82 |
#pragma target 3.0 |
| 83 |
ENDCG |
| 84 |
} |
| 85 |
} |
| 86 |
} |