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
- 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)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
- UnityHub: Add support for custom project title (instead of folder name) or use ProductName
- Testing Unity MUSE AI
[…] 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 […]