Core Issue
I'm experiencing inconsistent depth occlusion behavior with Spine skeletons in my Unity 2D game. Despite multiple shader modifications, I'm still encountering unexpected rendering behavior.
Technical Details
Depth Testing Inconsistency:
I'm building a 2D game where the -Z axis should represent foreground and +Z axis should represent background
However, the transparency occlusion is working opposite to expectations - objects that should be occluded are visible, and vice versa
Spine SkeletonMecanim Configuration Issue:
When setting objects closer to the camera as "background" and objects further from camera as "foreground", the occlusion works correctly
This is counter-intuitive and conflicts with the standard Unity rendering pipeline
Setting objects according to logical foreground/background positions results in incorrect occlusion
Shader Attempts:
I've made multiple modifications to the Spine-Skeleton_custom.shader
Attempted various ZTest configurations (LEqual, GEqual, Less, Greater)
Implemented Z-axis inversion in vertex shaders
Added alpha feathering and threshold effects
Created depth-only passes and simplified the shader
Current State:
The shader now correctly renders with alpha feathering
Depth interactions are still working incorrectly without manually reversing the foreground/background assignments
Created a SpineZOrderCorrector component as a potential solution
Questions
What's causing this reverse relationship between Spine's foreground/background settings and actual Z-depth?
Is there a way to fix this at the shader level without needing a custom component?
Does the SkeletonMecanim component have built-in functionality that's reversing the expected Z ordering?
Are there any performance concerns with my current shader implementation?
Is there a more elegant solution to achieve proper occlusion while maintaining alpha feathering effects?
I need a solution that allows me to set objects according to logical foreground/background positions and have them render with correct occlusion, while maintaining good performance in the built-in render pipeline.
<iframe src="https://1drv.ms/v/c/a6f0114fb2c74c10/IQQZcaCQdXXgTZGRrCzqaWzNAbNYteeYtJg0pkQTXJke8JY" width="2560" height="1380" frameborder="0" scrolling="no" allowfullscreen></iframe>
<iframe src="https://1drv.ms/v/c/a6f0114fb2c74c10/IQTYaSW7NaE3Spf7-QxRjRM6AdH75w1nYVpTKiEjRGfge_Q" width="2560" height="1380" frameborder="0" scrolling="no" allowfullscreen></iframe>