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.
Image removed due to the lack of support for HTTPS. | Show Anyway
Image removed due to the lack of support for HTTPS. | Show Anyway
@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.
@[deleted]
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:
Image removed due to the lack of support for HTTPS. | Show Anyway
ToddRivers wrotePlus 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.
- Edited
@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 Image removed due to the lack of support for HTTPS. | Show Anyway
character in almost no light Image removed due to the lack of support for HTTPS. | Show Anyway
@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:
Image removed due to the lack of support for HTTPS. | Show Anyway
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? Image removed due to the lack of support for HTTPS. | Show Anyway
This is what it looks like for me
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