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
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
- Convert LAS/LAZ/PLY pointclouds to GLTF (GLB) Point Meshes (standalone converter)
Recent Comments
- on Sprite Sheet Flip Book Shader
- on Sprite Sheet Flip Book Shader
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
- on UI Scroll View automatic Content height
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 […]