Skip to content

Instantly share code, notes, and snippets.

@FreyaHolmer
Created August 26, 2021 08:19
Show Gist options
  • Save FreyaHolmer/40f2a22c5aef78f0f4337717e0f7c69c to your computer and use it in GitHub Desktop.
Save FreyaHolmer/40f2a22c5aef78f0f4337717e0f7c69c to your computer and use it in GitHub Desktop.
Premultiplied alpha shader drawing a texture
Shader "Unlit/TexturePremul" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Pass {
Blend One OneMinusSrcAlpha // premultiplied alpha
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
struct MeshData {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct Interpolators {
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
Interpolators vert (MeshData v) {
Interpolators o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float4 frag( Interpolators i ) : SV_Target {
return tex2D( _MainTex, i.uv );
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment