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 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
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
[…] 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 […]