• Unity Lighting and Shaders

Hey Alic,

I was wondering if you had made any good progress with a shader for unity that did things better and were willing to share it?
I've tried sprite lamp shader but cant seem to get shadow casting working with it...

Thanks!

Related Discussions
...

Hey wrongtarget,

So I've got a shader I'm pretty happy with, but it's definitely still a work in progress and it has a multi-part setup. Work needs to be done to make mesh attachments work.

Basically I've combined the cool features of the sprite lamp shader (cell shading, light wrapping) with the stuff I wanted: casting and receiving shadows, working with unity projectors, and most importantly to me, rendering in a transparent style rather than an alpha-cutout style so that details aren't lost around the edges of every texture.

The full implementation requires editing two of the runtime classes so that all animations are always drawn on front-facing geometry, and also so bone transform data is passed through the tangents data of the vertices just as Gallo did on the forums. It also requires adding a manager type class to your game which can sort all spine animations manually, because in order to receive shadows in unity, things have to be drawn before the transparent part of the render queue


and drawing things transparently outside of the transparent part of the render queue means that the draw order of everything becomes completely random, so you have to manage the sorting yourself ahead of time.

None of it's that bad, but it is a multi-step process that might take a while to explain in detail, depending on how much you've messed around with this stuff yourself. If you want, I can send you my files. The main reason I haven't shared anything up till now is that I'm actually on an older version of Spine, and therefore an older version of the runtimes, for an unrelated and dumb reason, so until I get around to updating my Spine version, all my edited runtime classes might be annoying to look through for changes. Anyway, hope you're well and let me know if you're interested in what I'm using, or if you just want to share info / clarify something about my approach. Hope you're well!

Alex

Hey Alic,

Thank you for replying 🙂
If you take a look around the forum you'll see I've been digging about this for a while (I even was in touch with Gallo for a few weeks). We made a bit of progress, and also stumbled on some of the same problems with the render queue, but never got as far as you did
I'd definitely would appreciate if you could share your files with me
I'm working with the latest version of Spine, maybe I can help get your work working with it? 🙂
In any case, at least I'd like to give it a go if you let me.

Cheers!

Hey wrongtarget, I absolutely remember that you did one of the unity bump mapped implementations a while ago


believe me, I read all that stuff 🙂

https://www.dropbox.com/sh/pxr0wo3pooxtbqq/AAAdiqctBgBRnfQ30RTuyq6na?dl=0

So here's my current setup. The shader is pretty messy since I tend to just throw stuff in and comment other stuff out while I'm trying stuff. A lot of things aren't commented, there's a line which specifically emphasizes the horizontal normals, for example. I'll work on cleaning it up.

The way the shader works is that the forward base pass, which includes a directional light, all vertex lights, and spherical harmonics, draws the character as a transparent sprite with alpha blending, and then other lights are drawn with an alpha cutout approach additively on top of the transparent sprite. Because of this, a character illuminated by directional lighting will look just like a character drawn with the basic lit spine shader, but a character with no directional light and only spotlights will be drawn completely with alpha cutouts. The trick is that mixing them seems to work pretty well


tell me what you think.

This is the highest quality approach I've been able to figure out, since unity (as far as I know) doesn't make the data for point lights available in the forward base pass. It's sort of like fancy grass shaders that draw transparent style first for smooth edges, and then draw alpha cutouts after to deal with draw order.

Except, for characters you don't want those smooth edges being drawn in the wrong order either, so you use the RendererSortingOverrideGroup component to sort all of the mesh renderers for the spine animations. Just add the RendererSortingOverrideGroup to a game object and then drag all the spine renderers to the list it has. Currently sorting only happens during play mode, not in edit mode.

One last note: The changes to SkeletonRenderer will look for a bool in one of the csharp atlas classes I think. That's only there because it was needed when converting backfacing meshes to frontfacing meshes in SkeletonRenderer, because spine can rotate some of the textures when it packs them, and there was no easy way to figure out which ones had been rotated. You can probably just remove this part, since with bump mapping it's way easier to just disable rotation in the atlas anyway.

Ok, let me know if you've got any questions!

Oh, and one important thing to point out about the shader I sent you: All the bump mapping stuff is currently only happening in the forward add pass. This is just because I'm working with an indoor level mostly lit by point lights right now, and I haven't gotten around to making the main directional light act the same way the additive pass lights do. But it should just be a matter of moving the code from the additive pass back to the base pass, with a few adjustments, which I'll do once I've finalized the additive pass code a bit more.

4 dana kasnije

Hey, how did it go wrongtarget? Any luck?

6 dana kasnije

Hey Alic,

Sorry! I haven't been able to even test it. We're launching our Kickstarter in a couple of weeks and it's been pretty hectic.
On the plus side I was talking to Mitch and he told me that you guys have made great progress together! I'm glad he was able to help.
You guys are deadly. Keep it up.