thrawn75

Hi!

I'm trying to make a spine character work with a fog image effect but it seems that the sprites are not writing to the z-buffer as the fog cut them as if they were not there.

It's strange because I see it's using a standard MeshRenderer, but there must be something else that makes these sprites work differently.

Do you have a sample or suggestion on how to make a sprite write to z-buffer so the fog can work with them?

Thanks.
thrawn75
  • Сообщения: 5

Pharan

Fog is a shader thing, as is writing to the z-buffer.

If it's a z-buffer-based post-effect fog you're using, I think you'll have some trouble, since non-pixel-art sprites are alpha blended and using a z-buffer involves making compromises with the quality of sprite edges. This would be true for any sprite stuff, not just Spine.

Not sure if a per-pixel fog can be done on sprites independently (not a post-effect) though. Worth a look.
Аватара пользователя
Pharan
  • Сообщения: 5366

thrawn75

Yes, fog is a shader thing :)

For the records, I'm the author of this fog asset, called Volumetric Fog & Mist. I've achieved to make the standard Unity SpriteRenderer and normal sprites work well with the fog, thanks to a custom shader. So yes, it's possible to mix global image effects that takes into account z-buffer with sprites.

here's a video showing the issue:


My goal is to make Spine sprites compatible with fog as well.

Let me explain what's going on in the video:

- You can see an Elephant sprite, that uses standard SpriterRenderer and a custom shader called Sprite Fog (there're two variations, Unlit and Diffuse). This custom shader allows sprites to throw shadows and to blend correctly with fog.
- You can see how the Elephant is moved to the back and to the front, crossing the fog properly and getting hidden when it's beyond the minimum distance of the fog. And the Elephant is just a 2D Sprite!

However, I can't achieve the same result with the spine sprites even when I have assigned them the same custom sprite shader than the Elephant. The character either shows on top of the fog or if I uncheck the render before transparent objects property of the fog image effect, the character will not blend correctly with the fog, as it's cut by it as if it was not there (notice that the character is getting hidden in front of the fog and it should not).

I can send you a private copy of this test project in case you think you can help me and other customers solve this issue (in fact I'm contacting you in the name of one of my customers who is also using Spine for their Unity characters).

Hope we can both get to the end of this issue.

Thank you in advance.
thrawn75
  • Сообщения: 5

Pharan

I can't imagine how that worked without messing up the edges if you're using a z-buffer-based fog.
Anyway, if you made it work, you made it work.

As for Spine stuff, there's nothing about their MeshRenderer that's special except that its material array is directly pulled every frame from its AtlasAsset.
So if you set the material and shader properly in the AtlasAsset, only the shader should be causing anything to work or not work.
This is considering the shader determines render queue as well as, writing to and reading z-buffer.

You can send the private project to unity@esotericsoftware.com or PM me a download link here in the forums.
Аватара пользователя
Pharan
  • Сообщения: 5366

thrawn75

Yeah, the material is set so it uses the same shader than the Elephant, but no dice.
I've sent the test project to your email address.

Thanks.
thrawn75
  • Сообщения: 5

Pharan

The download link you sent seems to keep failing.

It also seems unusually large.
In case you didn't know. You can exclude the Library folder when sending your project. That's stuff Unity can regenerate itself. Or just export a .unitypackage.
Аватара пользователя
Pharan
  • Сообщения: 5366

thrawn75

Right. I've re-submitted a smaller package. Try again please.
thrawn75
  • Сообщения: 5

Pharan

(1) I loaded the project in Unity 5.3. The elephant was missing but that wasn't a problem. I had my own placeholder image to use as a sprite.

(2) I switched the shader on the character wearing green to the Spine/Skeleton shader. I saw that was broken, so I switched it back to the VolumetricFogAndMist/Sprites/SpriteFog Unlit. Then it seemed to work fine. No changes in code or scene setup or objects or anything. The Diffuse version also worked fine.
Аватара пользователя
Pharan
  • Сообщения: 5366

thrawn75

I have been able to reproduce that this works on Unity 5.3.4f1. For some reason, it was not working with 5.1.1.
What's strange is that as I opened the project in Unity 5.3.4f1, the sprites were not working, but refreshing the shader (assigning the diffuse or the unlit sprite fog back and forth) made the trick and the fog suddenly started picking the sprites (which means that for some reason the shader was not writing to z-buffer properly with Unity 5.1... really strange).
I'll try to confirm this with our customer.
Thanks for trying out this.
thrawn75
  • Сообщения: 5


Вернуться в Unity