- Home /
[Shader, sprite] frag shade entire sprite image?
I'm kinda new to shaders. I have a basic shader that just causes the sprite to warp around over time.
Shader "Unlit/FlamingBackgroundShader"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 ic = tex2D(_MainTex, i.uv);
float2 uv = i.uv;
float speed = 1.0;
float freq = 0.01;
float scale = 2.0;
float coef = 0.1;
float off = 0.01;
float t = _Time.y;
float a = sin((speed*t)+(uv.y*t*freq));
float b = sin(uv.y*scale)*coef;
float c = off;
float finalX = a*b +c;
float finalY = sin(t*0.642)*0.1;
float2 nuv = uv+float2(finalX,finalY);
fixed4 col = tex2D(_MainTex, nuv);
fixed4 final = fixed4(col.r,col.g,col.b,0.0);
//vec3 colr = vec3(s.r,s.g*(1.25-uv.y),s.b*(1.0-uv.y));
// sample the texture
//float2 nuv = float2(i.uv.x+10.0,i.uv.y);
//float2 nuv = float2(i.uv.x,i.uv.y+());
//fixed4 col = fixed4(c.r,1.0,c.b,c.a);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
i want the entire sprite to have the affects of the fragment shader. however, any parts of the sprite that are completely transparent apparently define the vertex boundaries, and the fragment shader only works within those boundaries. i want it to work on every pixel within the sprite, not jsut the pixels that are opaque.
does anybody know how i can omit or change the vertex method so that the fragment shader can work on the entire image, from its width to its height, not just the parts of the image that have color?
Answer by aurelioprovedo · May 28, 2018 at 12:51 PM
Make sure that, in the Import Settings of your Sprite, the Mesh Type is set to Full Rect.
From what you're saying, it sounds to me as if the sprite is using a tightly adjusted mesh. That would explain why only the opaque parts are being drawn.
Your answer
Follow this Question
Related Questions
Combine Vertex / Fragment and Surface Shader 0 Answers
Vertex shader breaks render to texture - camera preview and render texture not the same 1 Answer
Add new vertex attributes for a shader,Create vertex attributes 0 Answers
Vertex/Fragment shaders - transparency ignoring Render Queue 3 Answers
Refraction Shader. Strange Artifacts 0 Answers