t1 / TFDContents / Assets / Resources / BlurShader2.shader @ 10
이력 | 보기 | 이력해설 | 다운로드 (2.77 KB)
| 1 |
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' |
|---|---|
| 2 |
|
| 3 |
Shader "Custom/BlurShader2" {
|
| 4 |
Properties {
|
| 5 |
_MainTex ("Base (RGB)", 2D) = "white" {}
|
| 6 |
_BlurSizeXY("BlurSizeXY", Range(0,10)) = 0
|
| 7 |
} |
| 8 |
|
| 9 |
CGINCLUDE |
| 10 |
#include "UnityCG.cginc" |
| 11 |
|
| 12 |
sampler2D _MainTex; |
| 13 |
float _BlurSizeXY; |
| 14 |
|
| 15 |
struct data {
|
| 16 |
float4 vertex : POSITION; |
| 17 |
float3 normal : NORMAL; |
| 18 |
}; |
| 19 |
|
| 20 |
struct v2f {
|
| 21 |
float4 position : POSITION; |
| 22 |
float4 screenPos : TEXCOORD0; |
| 23 |
}; |
| 24 |
|
| 25 |
v2f vert(data i) |
| 26 |
{
|
| 27 |
v2f o; |
| 28 |
o.position = UnityObjectToClipPos(i.vertex); |
| 29 |
o.screenPos = o.position; |
| 30 |
|
| 31 |
return o; |
| 32 |
} |
| 33 |
|
| 34 |
half4 frag( v2f i ) : COLOR |
| 35 |
{
|
| 36 |
float2 screenPos = i.screenPos.xy / i.screenPos.w; |
| 37 |
float depth = _BlurSizeXY * 0.0005; |
| 38 |
|
| 39 |
screenPos.x = (screenPos.x + 1) * 0.5; |
| 40 |
screenPos.y = 1 - (screenPos.y + 1) * 0.5; |
| 41 |
|
| 42 |
half4 sum = half4(0.0h,0.0h,0.0h,0.0h); |
| 43 |
|
| 44 |
sum += tex2D( _MainTex, float2(screenPos.x-5.0 * depth, screenPos.y+5.0 * depth)) * 0.025; |
| 45 |
sum += tex2D( _MainTex, float2(screenPos.x+5.0 * depth, screenPos.y-5.0 * depth)) * 0.025; |
| 46 |
|
| 47 |
sum += tex2D( _MainTex, float2(screenPos.x-4.0 * depth, screenPos.y+4.0 * depth)) * 0.05; |
| 48 |
sum += tex2D( _MainTex, float2(screenPos.x+4.0 * depth, screenPos.y-4.0 * depth)) * 0.05; |
| 49 |
|
| 50 |
|
| 51 |
sum += tex2D( _MainTex, float2(screenPos.x-3.0 * depth, screenPos.y+3.0 * depth)) * 0.09; |
| 52 |
sum += tex2D( _MainTex, float2(screenPos.x+3.0 * depth, screenPos.y-3.0 * depth)) * 0.09; |
| 53 |
|
| 54 |
sum += tex2D( _MainTex, float2(screenPos.x-2.0 * depth, screenPos.y+2.0 * depth)) * 0.12; |
| 55 |
sum += tex2D( _MainTex, float2(screenPos.x+2.0 * depth, screenPos.y-2.0 * depth)) * 0.12; |
| 56 |
|
| 57 |
sum += tex2D( _MainTex, float2(screenPos.x-1.0 * depth, screenPos.y+1.0 * depth)) * 0.15; |
| 58 |
sum += tex2D( _MainTex, float2(screenPos.x+1.0 * depth, screenPos.y-1.0 * depth)) * 0.15; |
| 59 |
|
| 60 |
sum += tex2D( _MainTex, screenPos-5.0 * depth) * 0.025; |
| 61 |
sum += tex2D( _MainTex, screenPos-4.0 * depth) * 0.05; |
| 62 |
sum += tex2D( _MainTex, screenPos-3.0 * depth) * 0.09; |
| 63 |
sum += tex2D( _MainTex, screenPos-2.0 * depth) * 0.12; |
| 64 |
sum += tex2D( _MainTex, screenPos-1.0 * depth) * 0.15; |
| 65 |
sum += tex2D( _MainTex, screenPos) * 0.16; |
| 66 |
|
| 67 |
sum += tex2D( _MainTex, screenPos+5.0 * depth) * 0.15; |
| 68 |
sum += tex2D( _MainTex, screenPos+4.0 * depth) * 0.12; |
| 69 |
sum += tex2D( _MainTex, screenPos+3.0 * depth) * 0.09; |
| 70 |
sum += tex2D( _MainTex, screenPos+2.0 * depth) * 0.05; |
| 71 |
sum += tex2D( _MainTex, screenPos+1.0 * depth) * 0.025; |
| 72 |
|
| 73 |
return sum / 2; |
| 74 |
} |
| 75 |
|
| 76 |
ENDCG |
| 77 |
|
| 78 |
SubShader {
|
| 79 |
ZTest Always Cull Off ZWrite Off |
| 80 |
pass {
|
| 81 |
CGPROGRAM |
| 82 |
#pragma vertex vert |
| 83 |
#pragma fragment frag |
| 84 |
#pragma target 3.0 |
| 85 |
ENDCG |
| 86 |
} |
| 87 |
} |
| 88 |
} |