Last active
June 2, 2018 18:37
-
-
Save MatheusFaria/b6674cf88631a02abbfe7403eac4bfbd to your computer and use it in GitHub Desktop.
Unity Naive Blur Shader (This shader is slow!!!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "matheusfaria/NaiveBlur" | |
{ | |
Properties | |
{ | |
_MainTex ("Base (RGB)", 2D) = "white" {} | |
_Radius ("Blur Radius", Int) = 3 | |
} | |
Category | |
{ | |
Tags { | |
"Queue"="Transparent" | |
} | |
SubShader | |
{ | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
float2 _MainTex_TexelSize; | |
int _Radius; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
v2f vert (appdata_base v) | |
{ | |
v2f o; | |
o.pos = UnityObjectToClipPos (v.vertex); | |
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex); | |
return o; | |
} | |
half4 frag (v2f i) : COLOR | |
{ | |
half4 texcol = half4(0.0, 0.0, 0.0, 0.0); | |
for (int x = -_Radius; x <= _Radius; ++x) { | |
for (int y = -_Radius; y <= _Radius; ++y) { | |
texcol += tex2D( | |
_MainTex, | |
float2( | |
i.uv.x + x * _MainTex_TexelSize.x, | |
i.uv.y + y * _MainTex_TexelSize.y | |
) | |
); | |
} | |
} | |
texcol /= (_Radius * 2 + 1) * (_Radius * 2 + 1); | |
return texcol; | |
} | |
ENDCG | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment