First Commit
This commit is contained in:
95
Assets/Shaders/Blur.shader
Normal file
95
Assets/Shaders/Blur.shader
Normal file
@@ -0,0 +1,95 @@
|
||||
Shader "Outline/Blur"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
//https://github.com/mattdesl/lwjgl-basics/blob/master/test/mdesl/test/shadertut/ShaderLesson5.java
|
||||
SubShader
|
||||
{
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
// Combined
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
half4 _MainTex_ST;
|
||||
|
||||
uniform float _BlurResolution;
|
||||
uniform float _BlurRadius;
|
||||
uniform float _BlurDirectionX;
|
||||
uniform float _BlurDirectionY;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
//_BlurRadius = 2.5f;
|
||||
//our original texcoord for this fragment
|
||||
fixed2 tc = UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST);
|
||||
|
||||
//float r = lerp(_BlurResolution.y, _BlurResolution.x, step(_BlurDirection.x, 1.0f));
|
||||
|
||||
//the amount to blur, i.e. how far off center to sample from
|
||||
//1.0 -> blur by one pixel
|
||||
//2.0 -> blur by two pixels, etc.
|
||||
float blur = _BlurRadius/_BlurResolution;
|
||||
|
||||
//the _BlurDirectionection of our blur
|
||||
//(1.0, 0.0) -> x-axis blur
|
||||
//(0.0, 1.0) -> y-axis blur
|
||||
float hstep = _BlurDirectionX;
|
||||
float vstep = _BlurDirectionY;
|
||||
|
||||
//apply blurring, using a 9-tap filter with predefined gaussian weights
|
||||
|
||||
fixed4 sum = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
|
||||
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x, tc.y)) * 0.2270270270;
|
||||
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user