Hi, can anyone help me with sprites transparency sorting by y axis issue using LWRP and ECS (RenderMesh).
Issue is that sprites are not being drawn in the same order as Graphics.DrawMeshInstanced calls order;
for example if i have 2 sprites with 2 different materials and do Graphics.DrawMeshInstanced(sprite1) and Graphics.DrawMeshInstanced(sprite2) - sprite1 is drawn on top of sprite2 (same result if order is reversed) - incorrect, but if sprite1 and sprite2 uses same material and i do Graphics.DrawMeshInstanced(sprite1, sprite2), sprite1 is drawn below sprite2 - correct. Transparency Sort Mode - was set Custom Axis and x:0 y:0 z:0
if i set Transparency Sort Mode - Custom Axis and x:0 y:1 z:0, then it works but with one big caveat, meshes are sorted by center coordinates (i need bottom). Sprite and SpriteRenderer has settings for that, but i use ECS so i can’t/don’t want to use it.
Is it possible to set sorting pivot to bottom instead of center in ECS,LWRP or to turn off transparency sorting?
sprites are being rendered using custom shader:
Shader
Shader "Custom/SpriteShader" {
Properties{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Map Texture", 2DArray) = "white" {}
}
SubShader{
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "RenderPipeline" = "LightweightPipeline" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#pragma target 3.5
struct appdata_t
{
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
float3 uv : TEXCOORD0;
};
struct v2f
{
float3 uv : TEXCOORD0;
float4 pos : SV_POSITION;
DEFAULT_UNITY_VERTEX_INPUT_INSTANCE_ID
};
UNITY_DECLARE_TEX2DARRAY(_MainTex);
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float4, _Vectors0)
UNITY_INSTANCING_BUFFER_END(Props)
v2f vert(appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
float4 params = UNITY_ACCESS_INSTANCED_PROP(Props, _Vectors0);
i.uv.xy = i.uv.xy / params.xy;
i.uv.z = params.z;
float4 color = UNITY_SAMPLE_TEX2DARRAY(_MainTex, i.uv);
return color;
}
ENDCG
}
}
}