Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Created December 28, 2020 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save partybusiness/9edf56e3a5d749ed8cf7255ad65516af to your computer and use it in GitHub Desktop.
Save partybusiness/9edf56e3a5d749ed8cf7255ad65516af to your computer and use it in GitHub Desktop.
Shader "Unlit/SparkleMaterial"
{
//this will display a texture centred at the 0.5,0.5 point in the uvs of the mesh but scaled and rotated to match the screen
//_ImageSize sets the size of the texture in pixels
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_ImageSize("Image Size", float) = 30
}
SubShader
{
Tags {
"RenderType"="Transparent"
"Queue" = "Transparent"
}
LOD 100
Blend One One
Cull Off
ZWrite 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;
float _ImageSize;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed2 deltaY = ddy(i.uv);
fixed2 deltaX = ddx(i.uv);
fixed2 iuv = i.uv - 0.5;
fixed a = (iuv.y * deltaY.x - iuv.x * deltaY.y) / (deltaX.y*deltaY.x - deltaX.x * deltaY.y);
fixed b = (iuv.x * deltaX.y - iuv.y * deltaX.x) / (deltaX.y*deltaY.x - deltaX.x * deltaY.y);
fixed4 col = tex2D(_MainTex, fixed2(a,b)/ _ImageSize +0.5);
return col;
}
ENDCG
}
}
FallBack "Particles/Additive"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment