Nov
25
2015

Opaque Sprite Shader

sprite_opaque_no_tint_shader_unity (screenshot of modified shader properties in debug view mode)

Modified built-in sprite shader so that its opaque, no color tint, and pixel snap is always on.
Just to test if there are any performance benefits to use them for opaque sprite tiles, at least the compiled shader stats seems to be lighter.

You can download built-in shader sources at: https://unity3d.com/get-unity/download/archive

Default Sprite shader compiled stats:

1
2
3
4
5
6
7
8
// Stats for Vertex shader:
//       d3d11 : 8 avg math (5..11)
//    d3d11_9x : 8 avg math (5..11)
//        d3d9 : 13 avg math (6..21)
// Stats for Fragment shader:
//       d3d11 : 2 math, 2 texture, 1 branch
//    d3d11_9x : 2 math, 2 texture, 1 branch
//        d3d9 : 5 math, 2 texture

Opaque Sprite shader compiled stats:

1
2
3
4
5
6
7
8
// Stats for Vertex shader:
//       d3d11 : 10 math
//    d3d11_9x : 10 math
//        d3d9 : 20 math
// Stats for Fragment shader:
//       d3d11 : 0 math, 1 texture
//    d3d11_9x : 0 math, 1 texture
//        d3d9 : 2 math, 1 texture

 

Modified Sprite shader source:


Shader "Sprites/OpaqueSnapNoTint"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Geometry"
"IgnoreProjector"="True"
"RenderType"="Opaque"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityPixelSnap(mul(UNITY_MATRIX_MVP, IN.vertex));
OUT.texcoord = IN.texcoord;
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = tex2D(_MainTex, IN.texcoord);
return c;
}
ENDCG
}
}
}


1 Comment + Add Comment

  • […] our semi-transparent cape work. We now have a choice of allowing the cape’s overlap of the opaque sprite to overlap, or painting a white background over the transparent […]

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.