Last active
September 11, 2023 14:18
-
-
Save josephbk117/8f848de2f0dd7767af65c473897a5a49 to your computer and use it in GitHub Desktop.
Better UI shaderfor Unity UI
This file contains hidden or 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
/*Please do support www.bitshiftprogrammer.com by joining the facebook page : fb.com/BitshiftProgrammer | |
Legal Stuff: | |
This code is free to use no restrictions but attribution would be appreciated. | |
Any damage caused either partly or completly due to usage this stuff is not my responsibility*/ | |
Shader "BitshiftProductions/OptimizedUI" | |
{ | |
Properties | |
{ | |
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {} | |
_Color("Tint", Color) = (1,1,1,1) | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue" = "Transparent" | |
"IgnoreProjector" = "True" | |
"RenderType" = "Transparent" | |
"PreviewType" = "Plane" | |
"CanUseSpriteAtlas" = "True" | |
} | |
Cull Off | |
Lighting Off | |
ZWrite Off | |
ZTest[unity_GUIZTestMode] | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
#include "UnityUI.cginc" | |
struct appdata_t | |
{ | |
float4 vertex : POSITION; | |
float4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
fixed4 color : COLOR; | |
half2 texcoord : TEXCOORD0; | |
float4 worldPosition : TEXCOORD1; | |
}; | |
fixed4 _Color; | |
fixed4 _TextureSampleAdd; | |
#define PI 3.14159 | |
#define TWO_PI 6.28318 | |
v2f vert(appdata_t IN) | |
{ | |
v2f OUT; | |
OUT.worldPosition = IN.vertex; | |
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition); | |
OUT.texcoord = IN.texcoord; | |
#ifdef UNITY_HALF_TEXEL_OFFSET | |
OUT.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1,1); | |
#endif | |
OUT.color = IN.color * _Color; | |
return OUT; | |
} | |
sampler2D _MainTex; | |
fixed4 frag(v2f IN) : SV_Target | |
{ | |
return (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment