How to bend object with shaders in Unity? - unity3d

I have a shader script with which I bend the world. But the problem is that this script only bends up and down. How to add so that you can both left and right?
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
Shader "Custom/Bendy Diffuse - Radial"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_ReflectionColor ("Reflection Tint Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert addshadow
#pragma multi_compile __ HORIZON_WAVES
#pragma multi_compile __ BEND_ON
// Global properties to be set by BendControllerRadial script
uniform half3 _CurveOrigin;
uniform fixed3 _ReferenceDirection;
uniform half _Curvature;
uniform fixed3 _Scale;
uniform half _FlatMargin;
uniform half _HorizonWaveFrequency;
// Per material properties
sampler2D _MainTex;
fixed4 _Color;
fixed4 _ReflectionColor;
struct Input
{
float2 uv_MainTex;
};
half4 Bend(half4 v)
{
half4 wpos = mul (unity_ObjectToWorld, v);
half2 xzDist = (wpos.xz - _CurveOrigin.xz) / _Scale.xz;
half dist = length(xzDist);
fixed waveMultiplier = 1;
dist = max(0, dist - _FlatMargin);
wpos.y -= dist * dist * _Curvature * waveMultiplier;
wpos = mul (unity_WorldToObject, wpos);
return wpos;
}
void vert (inout appdata_full v)
{
#if defined(BEND_ON)
v.vertex = Bend(v.vertex);
#endif
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
fixed4 detail = tex2D(_MainTex, IN.uv_MainTex);
fixed4 refl = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = detail.rgb * _Color.rgb;
o.Alpha = 1;
o.Emission = refl.rgb * _ReflectionColor.rgb;
}
ENDCG
}
Fallback "Mobile/Specular/Diffuse"
}

If I understood your question correctly, you are trying to create an illusion of curved Earth. You have xzDist, add this vector multiplied by unmodified Y. So basically if it's left from origin point, bend it left. Points that are hight will bend away from the center more, and the ones below the equator could bend to the center. Can't promise that this will look right though.

Related

Shader works in Editor but not on iPhone

I am using the next script for a painting asset found on this website.
As you render the faces of your mesh in the uv space of the mesh, you are reconstruction the islands one triangle at the time. On the edges of the island, it can be that due to underestimation the rasterizer doesn’t consider a pixel which is actually in the island. For these pixels, no pixel shader will be executed and you will be left over with a crease. (text and image taken form the website)
The basic idea is that every frame, after the paint texture has been updated, I run a shader over the entire texture, and using a filter and a pre baked mask of the uv islands, extend the islands outwards.
The problem is that it does not work on iPhone. There is no error, no weird coloring, it is like that script does not get applied. I am not sure where the problem is coming from..maybe the for loops or the command buffers used in c#.
Shader "Unlit/FixIlsandEdges"
{
SubShader
{
// =====================================================================================================================
// TAGS AND SETUP ------------------------------------------
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
// =====================================================================================================================
// DEFINE AND INCLUDE ----------------------------------
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
// =====================================================================================================================
// DECLERANTIONS ----------------------------------
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
uniform float4 _MainTex_TexelSize;
sampler2D _IlsandMap;
// =====================================================================================================================
// VERTEX FRAGMENT ----------------------------------
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float map = tex2D(_IlsandMap,i.uv);
float3 average = col;
if (map.x < 0.2) { // only take an average if it is not in a uv ilsand
int n = 0;
average = float3(0., 0., 0.);
for (float x = -1.5; x <= 1.5; x++) {
for (float y = -1.5; y <= 1.5; y++) {
float3 c = tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy*float2(x, y));
float m = tex2D(_IlsandMap, i.uv + _MainTex_TexelSize.xy*float2(x, y));
n += step(0.1, m);
average += c * step(0.1, m);
}
}
average /= n;
}
col.xyz = average;
return col;
}
ENDCG
}
}
}
I've read somewhere that using tex2D in for loops is a big no no, so I changed that to a tex2Dlod but the same thing happens.
You can check out the Git project here
I am completely lost on this one and google isn't very helpful. Thank you for any comments.

Image size independent shader

I'm trying to create a shader for an image material that draws a circle regardless of the aspect ratio of the image itself.
In Shadertoy (hlsl) I can do the following to create a round circle, regardless of aspect ratio:
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord/iResolution.xy;
uv -= 0.5;
uv.x *= iResolution.x/iResolution.y; // < this compensates for the aspect ratio
float l = length(uv);
float s = smoothstep(0.5, 0.55, l);
vec4 col = vec4(s);
fragColor = vec4(col);
}
Which gives the following output
If I remove the line uv.x *= iResolution.x/iResolution.y; the circle will warp based on the current aspect ratio.
Now I want to create the same effect in Unity, so I tried the (to me seemingly) same approach.
_MainTex_TexelSize contains the width/height of the texture (from the docs):
{TextureName}_TexelSize - a float4 property contains texture size information:
- x contains 1.0/width
- y contains 1.0/height
- z contains width
- w contains height
Shader "Unlit/Shader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
Cull off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _MainTex_TexelSize;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.uv -= 0.5;
o.uv.x *= _MainTex_TexelSize.z / _MainTex_TexelSize.w;
return o;
}
float DrawCircle(float2 uv, float radius, float fallOff)
{
float d = length(uv);
return smoothstep(radius, fallOff, d);
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float c = DrawCircle(i.uv, 0.5, 0.55);
col = lerp(col, fixed4(1,0,0,1), c);
return col;
}
ENDCG
}
}
}
The shader compiles as is, but the circle will still stretch based on the aspect ratio of the image.
I thought this may be due to the way the uv's are set up using o.uv = TRANSFORM_TEX(v.uv, _MainTex); so I tried dividing that by the image's size:
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.uv / _MainTex_TexelSize.zw;
o.uv -= 0.5;
However this did nothing
and setting up the uv's differently like so
o.uv = v.uv / _MainTex_TexelSize.zw;
o.uv / _MainTex_TexelSize.zw;
o.uv -= 0.5;
results in the circle's center moving to the upper right, but still warp when the aspect ratio change.
What step am I missing/doing wrong to get the aspect ratio independent result like I get in shadertoy?
The aspect ratio of the input texture _MainTex has nothing to do with the aspect ratio of the output*. In the shadertoy example that output is the screen, and iResolution gives you the screen dimensions (the equivalent in unity is _ScreenParams). If you want to draw a quad that is not full screen, you have to match the quad aspect ratio with the _MainTex aspect ratio to use _MainTex_TexelSize, or else just provide the aspect ratio or dimensions in a shader property (that is basically what _ScreenParams does):
float _Aspect;
fixed4 frag(v2f i) : SV_Target
{
i.uv -= .5;
i.uv.x *= _Aspect;
fixed4 col = tex2D(_MainTex, i.uv);
float c = DrawCircle(i.uv, .5, .55);
col = lerp(col, fixed4(1,0,0,1), c);
return col;
}
You could calculate the aspect ratio with derivatives. Here dx and dy are the amount of uv change per pixel. This would also be useful if you want to have, for example, fallOff always be 10 pixels.
fixed4 frag(v2f i) : SV_Target
{
i.uv -= .5;
float dx = ddx(i.uv.x);
float dy = ddy(i.uv.y);
float aspect = dy/dx;
i.uv.x *= aspect;
fixed4 col = tex2D(_MainTex, i.uv);
float c = DrawCircle(i.uv, .5, .55);
col = lerp(col, fixed4(1,0,0,1), c);
return col;
}

Merging 2 shaders

I am currently using 2017.3.0f.3. I have two CG shaders that I would like to merge into a single shader. One is for handling the distortion of a sprite (like waves/wind), the other keeps it facing the camera (billboard). They work independently but I need them to work together.
Shader 1:
Shader "Cg shader for billboards" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
_ScaleX ("Scale X", Float) = 1.0
_ScaleY ("Scale Y", Float) = 1.0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
uniform sampler2D _MainTex;
uniform float _ScaleX;
uniform float _ScaleY;
struct vertexInput {
float4 vertex : POSITION;
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
+ float4(input.vertex.x, input.vertex.y, 0.0, 0.0)
* float4(_ScaleX, _ScaleY, 1.0, 1.0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
Shader 2:
Shader "Transparent/Cutout/Diffuse Shake" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_ShakeDisplacement ("Displacement", Range (0, 1.0)) = 1.0
_ShakeTime ("Shake Time", Range (0, 1.0)) = 1.0
_ShakeWindspeed ("Shake Windspeed", Range (0, 1.0)) = 1.0
_ShakeBending ("Shake Bending", Range (0, 1.0)) = 1.0
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert alphatest:_Cutoff vertex:vert addshadow
sampler2D _MainTex;
fixed4 _Color;
float _ShakeDisplacement;
float _ShakeTime;
float _ShakeWindspeed;
float _ShakeBending;
struct Input {
float2 uv_MainTex;
};
void FastSinCos (float4 val, out float4 s, out float4 c) {
val = val * 6.408849 - 3.1415927;
float4 r5 = val * val;
float4 r6 = r5 * r5;
float4 r7 = r6 * r5;
float4 r8 = r6 * r5;
float4 r1 = r5 * val;
float4 r2 = r1 * r5;
float4 r3 = r2 * r5;
float4 sin7 = {1, -0.16161616, 0.0083333, -0.00019841} ;
float4 cos8 = {-0.5, 0.041666666, -0.0013888889, 0.000024801587} ;
s = val + r1 * sin7.y + r2 * sin7.z + r3 * sin7.w;
c = 1 + r5 * cos8.x + r6 * cos8.y + r7 * cos8.z + r8 * cos8.w;
}
void vert (inout appdata_full v) {
float factor = (1 - _ShakeDisplacement - v.color.r) * 0.5;
const float _WindSpeed = (_ShakeWindspeed + v.color.g );
const float _WaveScale = _ShakeDisplacement;
const float4 _waveXSize = float4(0.048, 0.06, 0.24, 0.096);
const float4 _waveZSize = float4 (0.024, .08, 0.08, 0.2);
const float4 waveSpeed = float4 (1.2, 2, 1.6, 4.8);
float4 _waveXmove = float4(0.024, 0.04, -0.12, 0.096);
float4 _waveZmove = float4 (0.006, .02, -0.02, 0.1);
float4 waves;
waves = v.vertex.x * _waveXSize;
waves += v.vertex.z * _waveZSize;
waves += _Time.x * (1 - _ShakeTime * 2 - v.color.b ) * waveSpeed *_WindSpeed;
float4 s, c;
waves = frac (waves);
FastSinCos (waves, s,c);
float waveAmount = v.texcoord.y * (v.color.a + _ShakeBending);
s *= waveAmount;
s *= normalize (waveSpeed);
s = s * s;
float fade = dot (s, 1.3);
s = s * s;
float3 waveMove = float3 (0,0,0);
waveMove.x = dot (s, _waveXmove);
waveMove.z = dot (s, _waveZmove);
v.vertex.xz -= mul ((float3x3)_World2Object, waveMove).xz;
}
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}
I have tried a failed multiple times already. Is it possible?
It is possible, and there's more than one way to go:
The simplest would be to not use the billboard shader at all and just orient the transform to look at the camera using a c# script. If you are not looking into efficiency, this is the best solution.
The other solution is to merge the wave function into the vertex shader of the billboard one. You just need to apply the wave distortion before the billboard transformation:
input.vertex.xz -= mul ((float3x3)_World2Object, waveMove).xz;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
+ float4(input.vertex.x, input.vertex.y, 0.0, 0.0)
* float4(_ScaleX, _ScaleY, 1.0, 1.0));
(you ofc need to move everything related to waveMove along with it :) )
If you need the lighting to work (the benefit of using surface shader), then it gets trickier. Surface shaders transform into clip/screen space behind the scene, after the execution of your main vertex shader method. Since billboard transformation needs to break down that transformation things get messy: you need to transform the vertices into their final clip space position, and then convert it back into object space so it can be re-transformed again behind the scene into the desired position.

Not getting uniform thickness in wireframe shader

Shader "Custom/Geometry/Wireframe"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_WireframeVal ("Wireframe width", Range(0.000, 0.035)) = 0.05
_Color ("color", color) = (1, 1, 1, 1)
_BackColor ("Back color", color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderType"="Opaque" "Glowable" = "True" }
Pass
{
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma geometry geom
#include "UnityCG.cginc"
struct v2g {
float4 pos : SV_POSITION;
};
struct g2f {
float4 pos : SV_POSITION;
float3 center : TEXCOORD0;
};
v2g vert(appdata_base v) {
v2g o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
[maxvertexcount(3)]
void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream) {
float2 p0 = IN[0].pos.xy / IN[0].pos.w;
float2 p1 = IN[1].pos.xy / IN[1].pos.w;
float2 p2 = IN[2].pos.xy / IN[2].pos.w;
float2 edge0 = p1 - p0;
float2 edge1 = p2 - p1;
float2 edge2 = p0 - p2;
float area = abs(edge1.x * edge2.y - edge1.y * edge2.x);
g2f o;
o.pos = IN[0].pos;
o.center = float3(area/length(edge1) , 0, 0);
triStream.Append(o);
o.pos = IN[1].pos;
o.center = float3(0, 0, area/length(edge2) );
triStream.Append(o);
o.pos = IN[2].pos;
o.center = float3(0, area/length(edge0), 0);
triStream.Append(o);
}
float _WireframeVal;
fixed4 _BackColor;
float4 _Color;
fixed4 frag(g2f i) : SV_Target
{
if(min(i.center.x ,(min(i.center.y,i.center.z))) > _WireframeVal)
{
discard;
}
return _BackColor;
}
ENDCG
}
}
}
Here is my wireframe shader code
i am not getting uniform edges throughout
Also when i reduce the width almost to zero (0.0001) the some pixels of wires are not drawn what can i do for that ? I want to make the wireframe shader as unity's built it wireframe mode how can i achieve that ?
Actually, that is uniform thickness. You're just thinking about what "thickness" is in this context, due to how the object is being drawn.
On the edge of the cube facing the camera where it looks like it's thicker than the other edges. Well, you're half right. There is more white pixels drawn there.
But the reason for that is because there are two edges there! And each one is contributing the desired value towards the thickness of the wireframe.
Both the blue outlined face and the red outlined face are contributing to the thickness of that edge, whereas on a corner where the adjacent face is pointing away from the camera (say, the bottom edge of the blue outlined face), only one face contributes to the overall effect.
This isn't noticeable when the thickness is very small or very far away (because 0.2 pixels + 0.2 pixels = 0.4 pixels, round up: 1 pixel), but does become apparent at higher thickness values, or if you non-uniformly scale the object. For example, I have this in a project I was working on a few weeks ago (mind, mine draws the backfaces too and the alpha depth sorting is off):
The reason for this is because where the "edges" are is done through computing the barycentric coordinates of the triangle, which are just an approximation, and will give skewed results if the triangles aren't equilateral.

Unity Gaussian blur Shader just makes my texture white - Why?

I'm trying to make a Gaussian Blur Shader work from this tutorial:
https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson5
But when I convert it to unity's shader language I'm getting nothing but white in my texture, except where transparency is (and no bluring ether.)
Here is my Unity Blur Shader code:
Shader "Unlit/UnlitShaderTest"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
uniform float resolution = 800;
uniform float radius = 400;
uniform float2 dir = float2(0,1);
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float4 sum = float4(0.0, 0.0, 0.0, 0.0);
float2 tc = i.uv;
float blur = 0;// radius/resolution;
//the direction of our blur
//(1.0, 0.0) -> x-axis blur
//(0.0, 1.0) -> y-axis blur
float hstep = dir.x;
float vstep = dir.y;
sum += mul(tex2D(_MainTex, float2(tc.x - mul(mul(4.0,blur),hstep), tc.y - mul(mul(4.0,blur),vstep))),0.0162162162);
sum += mul(tex2D(_MainTex, float2(tc.x - mul(mul(3.0,blur),hstep), tc.y - mul(mul(3.0,blur),vstep))),0.0540540541);
sum += mul(tex2D(_MainTex, float2(tc.x - mul(mul(2.0,blur),hstep), tc.y - mul(mul(2.0,blur),vstep))),0.1216216216);
sum += mul(tex2D(_MainTex, float2(tc.x - mul(mul(1.0,blur),hstep), tc.y - mul(mul(1.0,blur),vstep))),0.1945945946);
sum += mul(tex2D(_MainTex, float2(tc.x, tc.y)),0.2270270270);
sum += mul(tex2D(_MainTex, float2(tc.x + mul(mul(1.0,blur),hstep), tc.y + mul(mul(1.0,blur),vstep))),0.1945945946);
sum += mul(tex2D(_MainTex, float2(tc.x + mul(mul(2.0,blur),hstep), tc.y + mul(mul(2.0,blur),vstep))),0.1216216216);
sum += mul(tex2D(_MainTex, float2(tc.x + mul(mul(3.0,blur),hstep), tc.y + mul(mul(3.0,blur),vstep))),0.0540540541);
sum += mul(tex2D(_MainTex, float2(tc.x + mul(mul(4.0,blur),hstep), tc.y + mul(mul(4.0,blur),vstep))),0.0162162162);
// sample the texture
fixed4 col = mul(tex2D(_MainTex, i.uv),float4(sum.r, sum.g, sum.b, sum.a));
return col;
}
ENDCG
}
}
}
Can someone tell me why my shader is just giving me all white instead of the normal colors? Also if someone could tell me why it's not bluring that'd be great too.
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 float4(sum.rgb, 1);
}
ENDCG
}
}
Fallback "Sprites/Default"
}
The reason you are getting a white texture is because mul(tex2D(_MainTex, i.uv),float4(sum.r, sum.g, sum.b, sum.a)); returns a float1 ( float1 mul(float4 v, float4x1 M); )