Reputation: 21
As the title says, my models are overlapping themselves when I use the Standard transparent shader.
I need to have a shader compatible with Sorting Layers since my game is a mix of 2D and 3D, that's why I'm using this one
Here's an example, look at the legs :
Opaque : https://i.sstatic.net/eKfem.png
Transparent : https://i.sstatic.net/RpvnQ.png
Any way to fix this issue ?
(EDIT: Another example seen from up :
Opaque : https://i.sstatic.net/3Ap8q.png
Transparent : https://i.sstatic.net/kxYPy.png)
Upvotes: 1
Views: 3724
Reputation: 1
Tacking on to what @Kalle Halvarsson said, I managed to fit the code into Unity's standard shader.
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Pass {
ZWrite On
ColorMask 0
}
Sticking this underneath LOD 300 in the first subshader makes transparent and fade work correctly.
Before:
After:
Upvotes: 0
Reputation: 1268
This is due to the fact that Z-testing is disabled for transparent objects. One way to solve this is to create a custom shader with a so-called "depth primer pass" before the main pass. Here is an example of how it might look in the subshader:
Tags {"RenderType"="Transparent" "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Pass {
ZWrite On
ColorMask 0
}
CGPROGRAM
#pragma surface surf standard alpha:fade
// The rest is just your standard surface shader
Note though that this might cause some weird artifacts when two transparent objects are intersecting or in front of each other.
If you are not experienced in writing surface shaders, you can check out this link: https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
Upvotes: 0