gaussian blur unity sprite 2D
C#
Shader "Custom/GaussianBlur"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
radius ("Radius", Range(0,30)) = 15
resolution ("Resolution", float) = 800
hstep("HorizontalStep", Range(0,1)) = 0.5
vstep("VerticalStep", Range(0,1)) = 0.5
}
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent"}
ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
half2 texcoord : TEXCOORD0;
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
};
sampler2D _MainTex;
float radius;
float resolution;
//the direction of our blur
//hstep (1.0, 0.0) -> x-axis blur
//vstep(0.0, 1.0) -> y-axis blur
//for example horizontaly blur equal:
//float hstep = 1;
//float vstep = 0;
float hstep;
float vstep;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color;
return OUT;
}
float4 frag(v2f i) : COLOR
{
float2 uv = i.texcoord.xy;
float4 sum = float4(0.0, 0.0, 0.0, 0.0);
float2 tc = uv;
//blur radius in pixels
float blur = radius/resolution/4;
sum += tex2D(_MainTex, float2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
sum += tex2D(_MainTex, float2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
sum += tex2D(_MainTex, float2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
sum += tex2D(_MainTex, float2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
sum += tex2D(_MainTex, float2(tc.x, tc.y)) * 0.2270270270;
sum += tex2D(_MainTex, float2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
sum += tex2D(_MainTex, float2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
sum += tex2D(_MainTex, float2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
sum += tex2D(_MainTex, float2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
return sum;
}
ENDCG
}
}
Fallback "Sprites/Default"
}
Also in C#:
- Title
- download and run exe c# 1 button
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- how to move towards an object unity
- Category
- C#
- Title
- .net core session
- Category
- C#
- Title
- c# delegate return value invoke
- Category
- C#
- Title
- convert generic to type c#
- Category
- C#
- Title
- ignore fakeiteasy
- Category
- C#
- Title
- .sh script: check if file exist
- Category
- C#
- Title
- nullreferenceexception c#
- Category
- C#
- Title
- blazor display validation message
- Category
- C#
- Title
- how to reference function in unity
- Category
- C#
- Title
- C# foreach loop async but wait at end
- Category
- C#
- Title
- razor: show editable list
- Category
- C#
- Title
- value is null to insert in c#
- Category
- C#
- Title
- how to use more than one condition in ef join
- Category
- C#
- Title
- wpf use enum description
- Category
- C#
- Title
- decimals not stored in azure tables
- Category
- C#
- Title
- prefab gets character transform
- Category
- C#
- Title
- viewBag as a list
- Category
- C#
- Title
- unity c# get bool from another script
- Category
- C#
- Title
- c# reverse a string
- Category
- C#
- Title
- unity get data from firebase
- Category
- C#
- Title
- dynamic in c#
- Category
- C#
- Title
- create char array c#
- Category
- C#
- Title
- add row count devepxress report
- Category
- C#
- Title
- How to get the world position of the edge of an object?
- Category
- C#
- Title
- c# double question mark
- Category
- C#
- Title
- c# md5 int
- Category
- C#
- Title
- what type of variable is true or false in c#
- Category
- C#
- Title
- c# long to int
- Category
- C#
- Title
- c# clear list items
- Category
- C#
- Title
- c# cheat sheet
- Category
- C#
- Title
- c# max two values
- Category
- C#
- Title
- xamarin forms alarm
- Category
- C#
- Title
- C# get object property name
- Category
- C#
- Title
- degree between two points latitude longitude c#
- Category
- C#
- Title
- unity c# run a command then wait
- Category
- C#
- Title
- unity how to change max fps
- Category
- C#
- Title
- csharp datetime string format
- Category
- C#
- Title
- C# Console multi language
- Category
- C#
- Title
- Add component object to gameobject unity
- Category
- C#
- Title
- c# read char
- Category
- C#
- Title
- c# get object property value by name
- Category
- C#
- Title
- split string
- Category
- C#
- Title
- c# main method
- Category
- C#
- Title
- convert number of days into months c#
- Category
- C#
- Title
- c sharp substring
- Category
- C#
- Title
- install .net sdk ubuntu 20
- Category
- C#
- Title
- how to reference a child object unity
- Category
- C#
- Title
- chase object unity
- Category
- C#
- Title
- object escape player unity
- Category
- C#
- Title
- winforms c# add data to datagridview with a button
- Category
- C#
- Title
- how to make a float in C++
- Category
- C#
- Title
- how to pause physics in unity c#
- Category
- C#
- Title
- how to spawn coins randomly around the screen unity 2d
- Category
- C#
- Title
- c sharp string replace
- Category
- C#
- Title
- entity framework core
- Category
- C#
- Title
- how to make infinite loop in c#
- Category
- C#
- Title
- 2d character controller unity
- Category
- C#
- Title
- c# how to initialize an array
- Category
- C#
- Title
- c# find index element array
- Category
- C#
- Title
- c# type of generic is string
- Category
- C#
- Title
- unity c# foreach
- Category
- C#
- Title
- letter at index of string c#
- Category
- C#
- Title
- unity add component
- Category
- C#
- Title
- Assets/Scripts/Snake.cs(177,25): error CS1061: Type `Snake.SnakeBodyPart' does not contain a definition for `SetGridPostion' and no extension method `SetGridPostion' of type `Snake.SnakeBodyPart' could be found. Are you missing an assembly reference?
- Category
- C#
- Title
- how to convert from hexadecimal to binary in c#
- Category
- C#
- Title
- degree to radians c#
- Category
- C#
- Title
- get setter c# model
- Category
- C#
- Title
- reverse a string in c#
- Category
- C#
- Title
- c# random string
- Category
- C#
- Title
- how to store some variables on the device in unity
- Category
- C#
- Title
- convert string to double c#
- Category
- C#
- Title
- unix time c#
- Category
- C#
- Title
- vb.net tostring numeric format string
- Category
- C#
- Title
- how to load the active scene unity
- Category
- C#
- Title
- date time heutiges datum
- Category
- C#
- Title
- c# reflection create generic type
- Category
- C#
- Title
- How to solve error in ExecuteNonQuery() in asp.net
- Category
- C#
- Title
- 2d object look at object
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- how to close a form c#
- Category
- C#
- Title
- C# graph api upload file one drive
- Category
- C#
- Title
- c# get country code
- Category
- C#
- Title
- c# new dictionary linq
- Category
- C#
- Title
- c# round to closest multiple
- Category
- C#
- Title
- eager loading vs lazy loading c#
- Category
- C#
- Title
- Request.ServerVariables["HTTP_X_FORWARDED_FOR"] get only one ipaddress
- Category
- C#
- Title
- how to populate listbox using list<t> c#
- Category
- C#
- Title
- get string character by index c#
- Category
- C#
- Title
- c# exit program
- Category
- C#
- Title
- c# join array
- Category
- C#
- Title
- c# create array of int
- Category
- C#
- Title
- csharp first element of array
- Category
- C#
- Title
- verifyusertokenasync password reset token
- Category
- C#
- Title
- Execute code every x seconds with Update()
- Category
- C#
- Title
- c# move with arrow keys
- Category
- C#
- Title
- unity assign button onclick
- Category
- C#
- Title
- wpf c# select folder path
- Category
- C#
- Title
- unity how to end a game with esc
- Category
- C#