25
2015
Opaque Sprite Shader
(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:
// 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:
// 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:
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 "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 | |
| } | |
| } | |
| } |
Related Posts
1 Comment + Add Comment
Leave a comment
Recent posts
- Adding Real World Location to Ice Fishing Prototype
- [web tool] Image Channel Inspector : AlphaScope
- Editor Tool: Smart Recompile (don’t recompile if edit comments)
- Editor Tool: Scene Size Analyzer
- LudumDare 60: Old Tech
- uBasic Scripting Language for Unity
- GreaseMonkey+Editor Plugin: 1-Click Copy script from ChatGPT (Web) to Unity Editor (as script)
- Editor Tool: Property Watcher
- .unityignore : Hide files from Project window
- PostBuild Script to Create Single exe Standalone File
- Game Loop Designer
- Favorites in PackageManager
Recent Comments
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by












[…] 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 […]