Created
May 20, 2025 16:04
-
-
Save paulorenanmelo/7a7694590a65b2dcc416078feda14e89 to your computer and use it in GitHub Desktop.
URP compatible shader that's always on top, useful for 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
Shader "Custom/AlwaysOnTopShader" | |
{ | |
Properties | |
{ | |
[NoScaleOffset] _MainTex("Texture", 2D) = "white" {} | |
_Color("Tint", Color) = (1,1,1,1) | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"RenderPipeline" = "UniversalPipeline" | |
"RenderType" = "Transparent" | |
"UniversalMaterialType" = "Unlit" | |
"Queue" = "Overlay" | |
"CanUseSpriteAtlas" = "True" | |
} | |
// Render | |
Cull Off | |
Lighting Off | |
ZTest Always | |
ZWrite Off | |
Blend One OneMinusSrcAlpha | |
HLSLINCLUDE | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | |
CBUFFER_START(UnityPerMaterial) | |
float4 _Color; | |
CBUFFER_END | |
TEXTURE2D(_MainTex); | |
SAMPLER(sampler_MainTex); | |
struct VertexInput | |
{ | |
float4 position : POSITION; | |
float4 color : COLOR; | |
float2 uv : TEXCOORD0; | |
}; | |
struct VertexOutput | |
{ | |
float4 position : SV_POSITION; | |
float4 color : COLOR; | |
float2 uv : TEXCOOR0; | |
}; | |
ENDHLSL | |
Pass | |
{ | |
HLSLPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
// Vertex Shader | |
VertexOutput vert(VertexInput i) | |
{ | |
VertexOutput o; | |
o.position = TransformObjectToHClip(i.position.xyz); | |
o.uv = i.uv; | |
o.color = i.color * _Color; | |
return o; | |
} | |
// Fragment/Pixel Sahder | |
float4 frag(VertexOutput i) : SV_Target | |
{ | |
float4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv) * i.color; | |
c.rgb *= c.a; | |
return c; | |
} | |
ENDHLSL | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment