Created
December 5, 2021 17:57
-
-
Save wtrebella/7f197d3f357b53e808dfbfa8b2e7a11a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Sprites/Default with UV Noise" | |
{ | |
Properties | |
{ | |
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} | |
_Color ("Tint", Color) = (1,1,1,1) | |
_NoiseAmt ("Noise Amt", Range(0, 1)) = 0.5 | |
_NoiseScaleX ("Noise Scale X", Float) = 1 | |
_NoiseScaleY ("Noise Scale Y", Float) = 1 | |
_NoiseTex ("Noise Texture", 2D) = "white" {} | |
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 | |
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1) | |
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1) | |
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {} | |
[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0 | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue"="Transparent" | |
"IgnoreProjector"="True" | |
"RenderType"="Transparent" | |
"PreviewType"="Plane" | |
"CanUseSpriteAtlas"="True" | |
} | |
Cull Off | |
Lighting Off | |
ZWrite Off | |
Blend One OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex SpriteVert | |
#pragma fragment SpriteFrag | |
#pragma target 2.0 | |
#pragma multi_compile_instancing | |
#pragma multi_compile_local _ PIXELSNAP_ON | |
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA | |
#ifndef UNITY_SPRITES_INCLUDED | |
#define UNITY_SPRITES_INCLUDED | |
#include "UnityCG.cginc" | |
#ifdef UNITY_INSTANCING_ENABLED | |
UNITY_INSTANCING_BUFFER_START(PerDrawSprite) | |
// SpriteRenderer.Color while Non-Batched/Instanced. | |
UNITY_DEFINE_INSTANCED_PROP(fixed4, unity_SpriteRendererColorArray) | |
// this could be smaller but that's how bit each entry is regardless of type | |
UNITY_DEFINE_INSTANCED_PROP(fixed2, unity_SpriteFlipArray) | |
UNITY_INSTANCING_BUFFER_END(PerDrawSprite) | |
#define _RendererColor UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteRendererColorArray) | |
#define _Flip UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteFlipArray) | |
#endif // instancing | |
CBUFFER_START(UnityPerDrawSprite) | |
#ifndef UNITY_INSTANCING_ENABLED | |
fixed4 _RendererColor; | |
fixed2 _Flip; | |
#endif | |
float _EnableExternalAlpha; | |
CBUFFER_END | |
// Material Color. | |
fixed4 _Color; | |
fixed _NoiseAmt; | |
fixed _NoiseScaleX; | |
fixed _NoiseScaleY; | |
struct appdata_t | |
{ | |
float4 vertex : POSITION; | |
float4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
fixed4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
UNITY_VERTEX_OUTPUT_STEREO | |
}; | |
inline float4 UnityFlipSprite(in float3 pos, in fixed2 flip) | |
{ | |
return float4(pos.xy * flip, pos.z, 1.0); | |
} | |
v2f SpriteVert(appdata_t IN) | |
{ | |
v2f OUT; | |
UNITY_SETUP_INSTANCE_ID (IN); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); | |
OUT.vertex = UnityFlipSprite(IN.vertex, _Flip); | |
OUT.vertex = UnityObjectToClipPos(OUT.vertex); | |
OUT.texcoord = IN.texcoord; | |
OUT.color = IN.color * _Color * _RendererColor; | |
#ifdef PIXELSNAP_ON | |
OUT.vertex = UnityPixelSnap (OUT.vertex); | |
#endif | |
return OUT; | |
} | |
sampler2D _MainTex; | |
sampler2D _AlphaTex; | |
sampler2D _NoiseTex; | |
fixed4 SampleSpriteTexture (float2 uv) | |
{ | |
fixed4 color = tex2D (_MainTex, uv); | |
#if ETC1_EXTERNAL_ALPHA | |
fixed4 alpha = tex2D (_AlphaTex, uv); | |
color.a = lerp (color.a, alpha.r, _EnableExternalAlpha); | |
#endif | |
return color; | |
} | |
fixed4 SpriteFrag(v2f IN) : SV_Target | |
{ | |
float2 noiseUV = IN.texcoord * float2(_NoiseScaleX, _NoiseScaleY); | |
float2 noise = tex2D (_NoiseTex, noiseUV); | |
float2 uv = IN.texcoord + noise.xy * _NoiseAmt; | |
fixed4 c = SampleSpriteTexture (uv) * IN.color; | |
c.rgb *= c.a; | |
return c; | |
} | |
#endif // UNITY_SPRITES_INCLUDED | |
ENDCG | |
} | |
} | |
} |
Author
wtrebella
commented
Oct 4, 2023
via email
Glad to hear it!
…On Wed, Oct 4, 2023 at 2:57 PM sancarr ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
@wtrebella <https://github.com/wtrebella> Yup, it worked! Thank you so
much 🙏🏽
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/wtrebella/7f197d3f357b53e808dfbfa8b2e7a11a#gistcomment-4714156>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATDLU63D6WKAQ46QOVAA7LX5XLWNBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCMZUGIZTAOJYU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment