Ooh! Great !! Thanks alot Pharan
Sprite Shaders for Unity
@MichelVictor Hey I was using Rim Lighting in vertex lighting mode and noticed there was a couple of bugs meaning the normals won't being generated correctly, which might of caused your weirdness! I've fixed that and uploaded the shaders to the first post
Plus nice, was gonna ask you what you used to make gifs too! They show off lighting effects so much better than static images.
This looks really cool! I'd love to check it out but I'm getting an error when I try to import it into Unity (5.3.5):
Shader error in 'Game/Sprite Pixel Lit': failed to open source file: 'SpritePixelLighting.cginc' at line 61 (on d3d11)
Compiling Vertex program with DIRECTIONAL SHADOWS_OFF LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF _ALPHAPREMULTIPLY_ON _ALPHA_CLIP
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING
The inspector doesn't show any debug info for the .cginc files so I can't tell what's wrong... any ideas?
Again brilliant work Todd! Thanks for sharing. The results are quite nice.
Is there a way to control the color of the shadow? Seems to be black at the moment. Ambient from the scene doesn't seem to affect it as well (You can see its purple in the bg) Or at least to the extent of my limited knowledge of Unity I don't know how to change the black shadows to another color.
How is everyone dealing with the seams? (Where two image pieces come together.) I've got ugly seams at my jaws and elbows.
Loading Image
Loading Image
@ToddRivers Hey Todd, do you have a quick fix to the issue of "opacity animation"? Whenever I try to use the Normals Shader (both with vertex or pixel lit) I get this weird issue where anytime the sprite fades the color gets darker as it fades away - which is very unattractive as the opacity animation is supposed to blend/transition between sprites. Oh and I'm a bit confused about all the "Tangent Solver" and making modifications to the Spine scripts... do we still have to do that? Or is it only for those who use the "calculate normals" function?
You don't need to modify the Spine-Unity runtime code anymore. The tangent solver is now built-in. You just need to check the checkbox. The latest information is in the first post. All other posts here may not represent how the latest version works.
@[supprimé]
Those seams are caused by whatever is generating your normal maps. It needs to be fixed there. ToddRivers's shaders are only using what normals you give it. If the normals have seams, you'll get seams on the shadows.
@ToddRivers . In case you wanted to polish up your tool some more. I ran into this bug involving ambient occlusion. I tried messing around with the settings, but nothing seemed to do the trick. You can check out the screenshots here. Hope it helps.
@Pharan. Thanks for the explanation. I'll give it a try. :party:
Loading Image
ToddRivers a écritPlus nice, was gonna ask you what you used to make gifs too! They show off lighting effects so much better than static images.
Well I think they way I did is not the best one haha.
I recorded the screen and imported to After Effects, cut the part I wanted to make a perfect loop, imported to photoshop and made a gif from there, lots of work haha.
- Modifié
@ToddRivers Hey, your shader is working pretty well for me. Below is an animation I did with the VertexLit shader which was later edited in Photoshop to add emission from the sword and a few minor tweaks (more on that below).
I have a few requests:
-An Emissive map. From what I can tell, it should be fairly simple to implement.
-Support for Opacity/Fade animation. As @RtFishers mentioned above, I have a similar problem with my animations. As my character's head turns to face the camera there is a sprite for his nose that is supposed to fade away as a new sprite (the "nose shadow") fades in. But I have observed that anytime I try to use opacity in my animations the shader seems to think it needs to DARKEN the sprite instead of just make it fade away (I had to edit the dark nose out in Photoshop). Now I'm guessing this could be a complicated issue, but I hope you can find a solution around it (otherwise I have limited options for the "3D head turn").
-Self-Shadowed Sprites. Now this could just be labelled wishful thinking, but if anyone has used Finn Morgan's SpriteLamp shader they will be familiar with the option for you to include a "Depth Map" into your material which the shader can then read as height and use some sort of increment function to make the sprite cast shadows on itself. But this sounds like a harder feature to add and I don't mind if it's not implemented anytime soon.
-Also, is it possible to enable the VertexLit shader to be able to receive shadows? I can't really use PixelLit as most of my characters have pieces that overlap everywhere.
Hi, I'm currently testing the shaders in the project my team's working on and so far I like them a lot.
I would also like to join LoneWarrior in request to add an emission channel to the shader.
Hey guys! Sorry for going missing, I somehow didn't see the responses.
Firstly I've fixed some pesky typo's in the shaders where I wrote .rbg instead or .rgb grr
Anyways!
@AlaNintendo so first up you should never use mesh normals with rim lighting on spine meshes. Actually you shouldn't really use mesh normals at all on spine animations for lighting in general. The normals will just point outwards from the mesh and make it look like a flat bit of paper (which in essenese is what a sprite is!).
By using a shader normal the shaders will treat it so the normal is constant in camera space meaning the normal is always facing into the camera even when the sprite is not. This might sound weird but it ends up making the lighting look a lot more 3d and realistic for sprites.
For rim lighting however you need a range of normals for it to work (it needs to find the 'rims' of places where the normals change dramatically).
For this on Spine Animations you need to use a normal map. I use this which works pretty nicely: https://www.codeandweb.com/spriteilluminator
For your second image I've found a bug with the way I apply fog, I need to lerp the fog color to clear depending on the pixels alpha, I've now fixed this and it'll be in the latest shaders
What exactly is going on with ambient occlusion in the last pic? Is this a Screen Space Ambient Occlusion effect? Or something else?
@LoneWarrior I love that art style! Emission would be hella cool and something I'd love to have in my game so is prob next on the list
I'm curious as to whats going on with the alpha fade, will look into that too.
Self shadowed sprite would be very cool but very hard to implement I think. Decent normal maps can help give that illusion but actual shadows a prob going to be too hard for now.
Shadows for vertext lighting is something I looked into very briefly and think its possible just harder than pixel lit shadows - you can use pixel lighting with hard alphas though, the animation in you gif should work pretty well with that. It's more accurate than vertex lighting and supports full shadows and as long as your sprites got solid edges work fine (to get it to work turn on write to depth and play around with the Depth Alpha Cutoff).
I use pixel lighting in most place although I've got one character thats furry and pixel lighting doesnt work with this as furr needs full alpha blending to look right so for that character I use vertex lighting. Will look into shadows for that too!
16 Sep 2016, 12:31
Ok emission was nice and easy, it's in the latest shaders on the front page
16 Sep 2016, 16:45
@RtFishers I had a look at the alpha fade bug and think I've fixed it for vertex lighting as best I can , however you'll always get the fade to black problem when using pixel lighting.
Because pixel shading is done over multiple passes it has to use depth testing to stop drawing lit areas over the top of each other.
Because it writes to depth it blocks lighting happening on areas beneath the top most sprite. As this top sprite fades out you start seeing the unlit sprite behind it, unfortunately theres no way around this.
Unity standard shader does not allow for alpha fading in "Cutout" mode for this reason.
Anyhow if you're fading sprite in and out OR using any areas with partial alpha then I recommend using vertex lighting
@LoneWarrior I had a look into recieving shadows in vertext lighting and alas I don't think it's possible without some crazy hacks like I did to get normal maps working in vertex mode but I don't think theres enough texture coord channels to support both at the same time!
Unity's own docs say vertex lighting does not support shadows here (although it also says it doesnt support normal maps and managed to get that one to work )
https://docs.unity3d.com/Manual/RenderTech-VertexLit.html
Anyhow casting shadows still works fine in vertext mode, if you really want a character to recieve shadows I recommend authoring it without any faded edges and then using pixel lighting with write to depth enabled
@ToddRivers thanks a lot for implementing the emission channel! It works quite nice as you can see:
character in full light
Loading Image
character in almost no light
Loading Image
@ToddRivers Thanks so much! Was trying to find other ways to contact you.... please don't disappear like that again . It's great that we also get an emission channel now, too. This shader is getting cooler all the time...
@Gabriev Woah that emission does look cool! It is pretty awesome for doing nice sci-fi lights or glowing runes etc!
I fixed a couple more bugs in the shaders - overlay color now works properly. It's super usefull for flashing sprites to a solid color when hit or for spell effects etc etc (as opposed to tint which is just multiplied with the texture color).
@RtFishers Haha I'll try not to!
@ToddRivers We modified the shader by adding Emission Power to it. (it's the last version, before your fixes). Feel free to include it in your package. It can be used to achieve brighter/more intensive light from the glow map and combined with some postprocessing like simple bloom it can produce neat effects:
Loading Image
Thanks alot for the advice on the rim lighting and mesh normals. I'll give those a try once I fix up my spine animations.
What exactly is going on with ambient occlusion in the last pic? Is this a Screen Space Ambient Occlusion effect? Or something else?
Yea thats the default image effects from Unity's "Screen Space Ambient Occulsion" script. For some reason when I'm using the Blend Modes in your script, the AO from the background seems to render in front? or some kind of additive effect is happening? Sorry I wish I was more technical to explain. I was hoping the screenshots would help explain.
Let me know if I can do some other tests?
Thanks again for the support on this amazing tool! Much appreciated
It's very fun to use
@AlaNintendo Ok I found the problem with Ambient Occulsion, it was caused by how Unity writes a special Depth+Normals texture, for that it needs the RenderType tag to be correct and I was setting it to "AlphaTest" when Unity needed "TransparentCutout" (even though you need to use AlphaTest for the Queue tag grr stupid Unity!).
Anyways it should work now but you might have to change something in the material property for it to update your material with the correct tag (just uncheck and then check the write to depth flag or something).
@Gabriev Nice! I've put your emission power in the latest shaders
Hi, I'm just trying to use the awesome shader package and ran into an issue where nothing would work.
I had an error showing up in the inspector panel for all shaders in Game>Shaders>Sprites saying "undeclared identifier 'unity_ObjectToWorld' d3d11 ShaderShared.cginc:15".
I'm stuck on Unity 5.3.4p6 for target platform reasons. I basically changed the line in ShaderShared.cginc from:
/* line:15 */ return mul(unity_ObjectToWorld, vertex);
to
return mul(_Object2World, vertex);
And everything now works.
Just thought it was worth mentioning for anyone else stuck on this!
@ToddRivers - You're a god! It works perfectly now. Thanks so much
Hi,
I'm just looking at trying out these shaders again. I imported the package from the first post, but Im not sure what I should be expecting.
The character renders as all pink, and I believe I should be seeing a custom GUI for the shader settings?
This is what it looks like for me
Loading Image
Is there anything I need to do after importing the package? Reading through the thread it seems like the required changes have been integrated into the latest runtime, which I just recently updated to.
Also, do these work with baked lighting and light probes? The biggest issue I am trying to solve is that when the character is facing left he is lighted differently than when facing right.
Thanks
Your import seems to be broken, even the inspector/editor code didn't load.
Delete all the files from the previous version and reimport the latest unitypackage.
yeah, not sure why they dont work for me. I'm on Unity 5.3.6
I had this issue. See my post a few posts up. Check your console to see if you see 1 error that matches the error mentioned in my previous post.
MattouBatou a écritI had this issue. See my post a few posts up. Check your console to see if you see 1 error that matches the error mentioned in my previous post.
Ah, thanks that was it. I was not getting anything logged to the console, I must have missed your post. Thanks for the help
Glad it was helpful. I spent a good while scratching my head wondering why the inspector panel looked different to the screenshots in the rest of the thread. If it wasn't for the console logs I was getting, I would have been clueless too. It's a little odd that you didn't get any logs. Ah well, happy shading!
As a sidenote: I recommend Sprite Illuminator for creating your normal maps. I've been hand "carving" them using the angle brush tool and it's been a dream. I attempted setting up a workflow in Photoshop but was a pain previewing the normal map with lighting on a mesh. Sprite Illumintor has a few handy views you can flick between as you paint.
Thanks for all your work @ToddRivers!
I'd definitely be paying for your work, please put it on the Asset Store! Is there a way to get in touch with you directly, maybe to get some active and responsive support, possibly supported by donations?
I thought Spine runtimes for Unity included some basic lit shaders but all the work you're doing is definitely a must have for every Unity Spine user!
Some general questions:
Which Unity Runtimes do your shaders work on? Have you already tested it on Unity 5.4.2f2?
Do the shader support ambient lighting, spot, omni and directional lights?
@[supprimé]
I had an idea.
Speculars.
And Spec map.
Not a request. : p
Pharan a écrit@[supprimé]
I had an idea.
Speculars.
And Spec map.
Not a request. : p
I'd love to have them as well. And maybe refraction shaders as well, for "predator-like" effects
Willing to pay for such features as long as support is given, please consider the Asset Store
Correct me if I'm wrong but I believe the esoteric team have already mentioned elsewhere in the forums about not wanting things on the asset store to rely on Spine's Unity runtime. This is because it is then only usable for those people with Spine. With that in mind, I expect that a "Super Shader Pack" would need a considerable amount of extra work to ensure they can also be used with any Unity prefab without any programming experience required to use them.
I'll be adding some shaders of my own to work with Todd Rivers shader collection within the next few months. When I do, I'll post them here. A Specular shader is something I'll do if someone else doesn't do it first.
MattouBatou a écritCorrect me if I'm wrong but I believe the esoteric team have already mentioned elsewhere in the forums about not wanting things on the asset store to rely on Spine's Unity runtime. This is because it is then only usable for those people with Spine. With that in mind, I expect that a "Super Shader Pack" would need a considerable amount of extra work to ensure they can also be used with any Unity prefab without any programming experience required to use them.
I'll be adding some shaders of my own to work with Todd Rivers shader collection within the next few months. When I do, I'll post them here. A Specular shader is something I'll do if someone else doesn't do it first.
I can't correct you, I still haven't read all the forum threads since I only registered yesterday.
I believe if Esoteric released the runtimes as a package in the asset store that would be feasible. Wrappers for other devices (mostly bound to VR) or softwares or runtimes (eg:LeapMotion), are present in the store, so I believe it's possible. I don't know the details so I won't insist. Even if, if the shaders are going to be useful in my project I'd gladly make a donation
Yes, mantaining a package in the store requires work (I'm mantaining several), but you also get some funding in exchange to keep yourself motivated and the package alive.
I think this is a bit off-topic, I'm not going to reply anymore about this on this thread, mine was simply the wish of an enthusiast
Hey! Just added updated shaders that support Tri-Color ambient lighting (different ambient colors for Ground / Equator / Sky).
They're approximated based on trying to match Unitys Standard Shader so might need some tweaking in the future (Unity added support for it with like no documentation as usual yay!).
It does look pretty awesome though, I defiently recommend lighting your scenes with gradient ambient lighting rather than flat, a bit of green light bouncing up from beneath the character looks ace (although you'll only really notice it with normal maps obv).
I think these shaders are going to get bundled in the unity runtimes in the future, right Pharan?
The shaders don't rely on Spine at all, they work on any mesh/model. They're just designed with sprites in mind. I use them for all sorts of non-spine stuff myself.
However I don't think I'll put them on the asset store now tbh.
Although I'd definitely love some potential extra income to support my own game dev, I learnt to code via looking at other peops open source stuff so feel I should give some free stuff back
@Pharan yeah specular and reflections are the biggest things missing when comapred to unity's standard shader. Specular should be pretty easy I think, might try it at some point. The number of shader varients is getting crazy now though - the pixel shader apparently has 576,388 variants already according to unity haha
You should consider putting them on the asset store, not for profit, but for convenience.
Put it up for $.99 and then it will offset the internet costs for time spent on this.
Yeah maybe, theres also here http://unitylist.com/ which is a great collection of open source unity stuff.
I've fixed more ambient lighting stuff - the pixel shader now uses Unitys spherical harmonics function to sample ambient lighting correctly.
The variables needed to do that aren't defined when using vertex lights so I knocked together a functions that approximates it.
Its impossible to get it look exactly the same but it works pretty well.
You can switch to always using flat ambient (for better performance) by undefining TRI_COLOR_AMBIENT in the shaders.
Hi ToddRivers,
Great progress and updates!
I ran into some performance spikes with your shader. Not really sure how it occurred, but thought maybe you'd want to know? (FYI it's using an older version .. so maybe your latest iteration fixes this)
Anyways keep up the great work and thanks for everything.
Hmm thats weird. The spike is happening when its first setting that shader for use I think. It could be caused by the Unity running out of shader keywords (the defines used to turn shader features on and off, these shaders now have a fair few of them to allow you to switch all the feature on/off).
At the mo I think theres a 64 keyword limit but its going up to 256 in Unity 5.5 so that might fix it!
I've uploaded new shaders that improve the fake spherical harmonics in vertex lighting mode. Should be a lot faster and look a bit better too
@ToddRivers. Nate wants to bundle it with the runtime but I'm trying to figure out how to proceed.
I've been recommending your shader to people who need these features and the common reaction seems to be: "whoa. that's too many features for me." Even though I try to explain that features you don't use don't affect performance. So I want to make some changes to the inspector (spine-friendly defaults and user-friendliness) before then.
I also feel like I need to rename the shader to "Spine/Sprite/Sprite somethingsomething" so people don't get a random "Game" folder in their shaders and so it doesn't get jumbled up with the others. I was thinking something like this:
But it seems a bit too long.
Anyway, I'm wondering about your thoughts on continuing work on it. Like, will there be two versions? Yours and Spine's? Or would you do PRs on the spine-runtimes git repo directly?
I don't want to impose any weird stuff too (in case I make changes to the inspector) if they don't work for the project that you're working on. But I also want to confidently make updates if ever you make changes that require inspector changes too.
Pharan a écrit@[supprimé]. Nate wants to bundle it with the runtime but I'm trying to figure out how to proceed.
I've been recommending your shader to people who need these features and the common reaction seems to be: "whoa. that's too many features for me." Even though I try to explain that features you don't use don't affect performance. So I want to make some changes to the inspector (spine-friendly defaults and user-friendliness) before then.
I also feel like I need to rename the shader to "Spine/Sprite/Sprite somethingsomething" so people don't get a random "Game" folder in their shaders and so it doesn't get jumbled up with the others. I was thinking something like this:
But it seems a bit too long.Anyway, I'm wondering about your thoughts on continuing work on it. Like, will there be two versions? Yours and Spine's? Or would you do PRs on the spine-runtimes git repo directly?
I don't want to impose any weird stuff too (in case I make changes to the inspector) if they don't work for the project that you're working on. But I also want to confidently make updates if ever you make changes that require inspector changes too.
The inclusion sounds nice to me as long as support is provided for it.
2 versions would be nice. One, with the Uber shader created by ToddRivers without putting him any limits to his creativity and experimentation, and another managed by the Spine team itself, stable, clean, cross-platform tested, optimised for performance and compatibility so that is coherent and well integrated with the package.
The nested shader solution is nice as long as the nesting makes sense, I'd be ok for it.
OT: btw, speaking of folder structure, having the runtime folders directly on the root of the project folder isn't very clean - may I move them elsewhere? (Also, the runtimes contain duplicate conflicting class names (eg: Animation), could you consider the possibility of using Namespaces?)
The Spine.Animation class has always been in the Spine namespace. Unity still incorrectly detects it as conflicting. It's not even a UnityEngine.Component. There's no way it would conflict. We've already reported this bug and support said it's a won't-fix.
We leave it up to the users to move the spine runtime folders into their own folder scheme. Moving (or even renaming) them doesn't break your ability to upgrade using unitypackages. Unity editor still knows where/which original folder and files are are based on their guid and updates them accordingly when you import updated unitypackages.
I should probably make that clear somewhere.
@Pharan Hey! I think the best option is two have to different versions. One bundled with the runtimes and another which is my own repository where I can check into whenever and then you guys can update from that when you want to.
That means you can have them appear in the Spine namespace etc which def makes sense (my own project is split into Engine and Game namespaces but it doesnt really make sense for anyone else tbh!). Plus make any changes you think will make things clear for people.
One thing I will do is rollover text explaining some of the features as I always find that usefull and found out how to do that the other day.
I do think its important to keep them as 'uber shaders' though. If you start making seperate versions for all the features it can get messy very quickly.
That's why Unity switched to that model for their own shader.
I guess it somehow needs to be made very clear that the tick boxes are turning off shader features so there is no overhead at all for features you don't use/need (which is exactly what happens if you're using the Unity Standard Shader).
ALSO what I think would be really usefull for peops is to have some example scenes in the runtimes specific to the shaders to show the difference between different lighting modes and to show off some of the features you can do with the shaders and Spine.
(Bump Mapping / Toon Shading / Emission / Tinting etc).
Alright.
I'm totally fine mirroring updates to the Spine-Unity version whenever you update your version but I wish there was some way to find out what changes you actually made so I can match accordingly.
Example scene, definitely. Maybe just a bunch in one scene though. I don't want it to balloon into an exhaustive description of Unity's lighting system. That's not something I confidently understand myself, and would be too much; not even the ShaderForge package does that.