在 Spine 编辑器中,Backface culling 功能应用在物体上没问题,但是导入Unity中运行,Backface culling 失效了,表现如图(能看到立方体的内部):
4.1 导出的资源无法使用backface culling
把 Skeleton.shader 的 Cull off 删掉就好了,为什么?为什么官方默认 Culling 是关掉的,有什么原因吗?
@sayi 为什么官方默认剔除是关掉的,有什么原因吗?
当然,背面剔除是故意关闭的。 这是因为任何负比例的附件(从左到右翻转它们等)都会导致缠绕顺序从 CCW 变为 CW,反之亦然,将正面变成背面。 然而,您可能希望渲染所有附件,而不仅仅是朝右的附件,因此剔除模式应设置为“无”。
您希望 Spine 骨骼启用背面剔除是否有原因?
在Spine编辑器中,Backface culling功能应用在物体上没问题,但是导入Unity中运行,Backface culling失效了,表现如图(可以看到立方体的内部)
我不确定我是否正确理解你的问题。 如果您的意思是背面剔除是剔除正面而不是背面,则需要剔除相反的缠绕顺序,而不是“Cull Back”,而使用“Cull Front”。 请注意,Unity 的命名有点不幸,因为它应该是“Cull CW”或“Cull CCW”,但 Unity 假定顺时针顺序为正面。
请注意,启用剔除时,您不能在骨骼或附件上使用负比例,否则您将剔除这些附件。 如果您必须启用剔除并且还需要负向缩放骨骼,您可以更改“MeshGenerator”中的代码来检查每个三角形的缠绕并对它们重新排序,但这可能不是您想要的。
为什么官方默认 Culling 是关掉的,有什么原因吗?
Of course, backface culling is turned off on purpose. This is because any negative scale of attachments (for flipping them from left to right, etc) would lead to the winding order changing from CCW to CW and vice versa, turning a front- into a backface. You would want to render all attachments however, not only right-facing ones, so culling mode should then be set to None
as a consequence.
Is there a reason why you want your Spine skeletons to have backface culling enabled?
在 Spine 编辑器中,Backface culling 功能应用在物体上没问题,但是导入Unity中运行,Backface culling 失效了,表现如图(能看到立方体的内部)
I'm not sure I understand your question correctly. If you mean that backface culling is culling front faces instead of back faces, you need to cull the opposite winding order, instead of Cull Back
use Cull Front
. Note that this is somewhat unfortunate naming by Unity, as it should be Cull CW
or Cull CCW
, but Unity assumes clockwise order as front-facing.
Note that when enabling culling, you can't use negative scale on bones or attachments, or you will cull these attachments. If you must have culling enabled and also need to scale bones negatively, you could change the code in MeshGenerator
to check winding of each triangle and reorder them, but this is likely not what you want.
Thank you for your response, and my apologies if my previous questions were unclear. My problem is as follows: I have a rotating cube with Backface Culling enabled. When previewing in the Spine 4.1 editor, I can see that the Backface Culling function is effective. However, in Unity Spine Runtime 4.1, the Backface Culling function of the rotating cube is not effective. Why is this?
Second question is, why does the Backface Culling function work when I delete 'Culling Off' in the Spine's Shader?
Third question is, why is the default setting in the Shader 'Culling off'? What is the reason for this?
The appendix includes two videos: 'fail.mp4' demonstrates the Backface Culling not working, and 'success.mp4' shows the successful operation after modifying the shader.
Thank you once again for your responses.
I made the demo based on this video:
- Edited
Sorry if my reply was unclear. I tried to explain why backface culling is disabled on purpose, but my reply seems to not have helped since the questions remain open to you.
sayi However, in Unity Spine Runtime 4.1, the Backface Culling function of the rotating cube is not effective. Why is this?
Third question is, why is the default setting in the Shader 'Culling off'? What is the reason for this?
These two questions seem identical to me, so I answer them as one:
Backface culling is disabled on purpose in spine-unity shaders, since it's common for users to scale bones or attachments by -1 to flip them, which turns a front-face into a back-face. The reason is that front-faces and back-faces are determined by vertex winding order clockwise (CW) and counter-clockwise (CCW). Negative scale inverts the winding order, so it turns a front-face into a back-face.
In Unity, it would not be intuitive for users to have all flipped attachments (which have been scaled by -1) disappear by default. Thus backface culling is disabled in all spine-unity shaders.
sayi Second question is, why does the Backface Culling function work when I delete 'Culling Off' in the Spine's Shader?
The shaders use the default settings then, which is Cull back
, culling back-faces and displaying only front-faces. Unfortunately the Cull
option can't be set via parameters (such as e.g. colors or alpha thresholds) in a Shader, but instead requires a separate shader. Since this would double the amount of shaders, we didn't include a Cull back
version of each shader in spine-unity, since this would bloat the runtime unnecessarily. You can however easily create copies of the shaders you need yourself and just modify the Cull none
statement to Cull back
(or remove this line resulting in the same via the default). Alternatively you can of course modify the original shaders as well, just be aware that when updating the spine-unity runtime you might override your changes, you then need to re-apply them accordingly.
If anything remains unclear, please let us know.