• Unity
  • Post Processing with URP not working with Spine Assets

@wvkmind Unfortunately we could not reproduce the problem of incorrect sorting order when zwrite is enabled that you are showing in the top image.

Is there a reason you enabled Use Custom Render Type?

wvkmind написал

I know the "Transparent" not have CameraDepthTexture

What do you mean by that?

Are you using the URP 2D render pipeline?

Related Discussions
...

@[удалено]

It is my mistake,I did not see the error because it reports an error on the panel ,my "SkeletonAnimation" panel is closed.
Warning me to config the "Advanced - Z Spaing",It work.

Thanks for letting us know @wvkmind, glad to hear that you've figured it out.

Alright, I tried again last night, and I still haven't been able to achieve the desired effect of Depth of Field with 3D lighting for my 2D Spine assets. Maybe I missed a step somewhere?

  • Started with an existing project without URP, then added it in

  • I then installed Esoteric Software's URP support packages

  • Changed my asset's shader to one that had a "depth to write" option and then edited the z-spacing

Unfortunately, I still haven't figured it out quite yet. Maybe there's a particular URP Spine Shader you recommend for achieving this effect? I was able to accomplish Depth of Field or 3D lighting, but there doesn't seem to be a shader that allows for both effects to occur simultaneously.

I'm sorry to hear that it didn't solve your problem. Could you please send us a minimal reproduction Unity project as a zip package that shows your exact setup, as a zip package to contact@esotericsoftware.com? Then we can have a look at how we can solve this.

  • Изменено

Done! Huge thanks. I will edit this post once the solution has been provided.


Just kidding. See below.

Thanks for the package, we will get back to you as soon as we've figured out what's going wrong.


In your scene you are combining a normal 3D point light with Spine's URP 2D shaders - this will not work, also not with Unity's own URP 2D shaders.

Also, at the Camera Inspector settings you are using the normal Forward Renderer and have no Render Pipeline Asset assigned under Project Settings - Quality - Rendering.

Please familiarize yourself with the Universal Render Pipeline in Unity in general first and read the corresponding documentation or videos before combining it with Spine. The scriptable render pipeline requires a bit more setup.


Perhaps the Render Pipeline Asset was originally assigned but the reference lost after import. In general it is not recommended to move the UPM package content into the Assets directory, instead it should rather be added as described in the spine-unity instructions here:
spine-unity Runtime Documentation: Installation

This guarantees that the package.json file is evaluated and that any dependencies are resolved.

Thanks for the tips. Definitely sorry Harald for causing the headache, I will absolutely spend more time with URP. A lot of this has been really confusing for me since my project intends to be a hybrid of both 3D and 2D, somewhat of a Paper Mario or Don't Starve look, if you are familiar with either of those games.

If I am using Spine and 2D sprites along the side of 3D assets, is there not a combination of shaders and rendering settings that allows me to have every asset affected in a similar manner enabling a depth of field effect and general lighting?


Honestly, I think I got it working through rereading the URP installation page and re-downloading the Spine-URP package. A new, yet similar question popped up: using the shader "URP/Spine/Skeleton Lit" how can I make it so a 3D light effects the Spine on both sides of the Z-axis?

buddhamon написал

If I am using Spine and 2D sprites along the side of 3D assets, is there not a combination of shaders and rendering settings that allows me to have every asset affected in a similar manner enabling a depth of field effect and general lighting?

The main problem that you ran into is that you can either use the ("special") URP 2D renderer, or the ("normal") URP 3D renderer. When using the 2D renderer, you have a different pipeline which does not work with 3D lights and 3D lit shaders:
https://www.youtube.com/watch?v=F5l8vP90EvU
So the way to go is to not use the 2D renderer when you have a mixed 2D & 3D scene and want to light them in with true 3D lights.

buddhamon написал

using the shader "URP/Spine/Skeleton Lit" how can I make it so a 3D light effects the Spine on both sides of the Z-axis?

Let's first ask the question what you want to achieve, because this might not be what you want:
Do you want to rotate the skeleton by 180 degrees? Please note that you can produce a similar result by using skeletonAnimation.Skeleton.ScaleX (you can use scaleX = sin(rotationAngle)) to gradually "flip" the skeleton and still have the normal facing the camera.
If you really need a true 3D rotation, then you should be aware that any lighting will dim during the turning process, as the normal rotates with the skeleton. So then we would recommend to use the Universal Render Pipeline/Spine/Sprite shader and enable Fixed Normal with default setting Camera Space to make the normal always face the camera and not produce strange lighting effects.

Harald написал

So the way to go is to not use the 2D renderer when you have a mixed 2D & 3D scene and want to light them in with true 3D lights.

Got it. I will not use a 2D renderer.

Harald написал

Do you want to rotate the skeleton by 180 degrees?

Sorry, I think we misunderstood each other. I want a 3D light to affect the front of a Spine on either side of the Z-axis.

Here the light illuminates the front of the Spine

Here the light vanishes behind the spine, the front unlit

The desired effect would include the lighting in the first image while the light is on either side of the Spine. Otherwise, I will also try your recommendation.


It appears Universal Render Pipeline/Spine/Sprite does not work for me because I plan to have my Spine assets navigate in a 3D world. The lighting and visual effects seem to work best in tandem with the shader Universal Render Pipeline/Spine/Skeleton Lit

I want a 3D light to affect the front of a Spine on either side of the Z-axis.

Ok. Unfortunately there is no built-in support for double-sided lighting in the Spine shaders yet. I will add functionality to the shaders via a bool parameter.

A new issue ticket is available here, I will let you know once it's done:
[unity] Backside lighting option for lit shaders · #1725

buddhamon написал

It appears Universal Render Pipeline/Spine/Sprite does not work for me because I plan to have my Spine assets navigate in a 3D world. The lighting and visual effects seem to work best in tandem with the shader Universal Render Pipeline/Spine/Skeleton Lit

Why do you think it's not suitable for navigating the 3D world? Actually the Sprite shaders are a kind of Spine's uber-shader which provide the functionality of Spine/Skeleton Lit plus many more features and a lot of configurable parameters. Anyway, backside lighting is not supported there either.

Harald написал

I will add functionality to the shaders via a bool parameter. A new issue ticket is available here, I will let you know once it's done

Oh wow! Thanks! I was going to look into how to do that today but, okay, huge thanks! I'm excited to hear about any updates!

Harald написал

Why do you think it's not suitable for navigating the 3D world?

So far I haven't found a way to make the Universal Rendering Pipeline/Spine/Sprite shader have any other Lighting Mode than Lit Universal; the other Lighting Modes cause the shader to fail and turn resultantly pink. I've only found the Universal Rendering Pipeline/Spine/Skeleton Lit to work with a local 3D point light. I'll do some more research on it today to see if I am missing a step.

buddhamon написал

So far I haven't found a way to make the Universal Rendering Pipeline/Spine/Sprite shader have any other Lighting Mode than Lit Universal; the other Lighting Modes cause the shader to fail and turn resultantly pink.

For URP the Sprite shader has to be set to Lit Universal, if you switch Lighting Mode to something else you are switching to other shaders, which are non-URP, therefore are not compatible (pink).

buddhamon написал

I've only found the Universal Rendering Pipeline/Spine/Skeleton Lit to work with a local 3D point light.

You can check out the URP 3D Shaders example scene which shows how the Universal Render Pipeline/Spine/Sprite shader interacts with all kinds of lights. Did you perhaps not setup the Fixed Normal settings as mentioned above?

Gotcha.

Harald написал

Did you perhaps not setup the Fixed Normal settings as mentioned above?

Maybe not, I had the Fixed Normal setting checked, but I didn't generate a normal map. Is that generated in Photoshop? (Also does the same apply to the emission map as well?) I also couldn't figure out how to make the Fixed Normal Space be Camera Space, but I'm guessing View-Space the equivalent?

As soon as I used a different Spine asset that had the Normal Map configured, the lighting started to work in 3D space properly for the Universal Render Pipeline/Spine/Sprite shader.

Sorry for the late reply! For some reason I have overlooked your posting earlier.

buddhamon написал

Maybe not, I had the Fixed Normal setting checked, but I didn't generate a normal map. Is that generated in Photoshop?

You don't need to use a normal map, it's optional at the shaders. It's sufficient to have the normals per vertex / per object, but they need to be either generated via Advanced - Add Normals or via Fixed Normals, otherwise your object will look unlit.

buddhamon написал

(Also does the same apply to the emission map as well?) I also couldn't figure out how to make the Fixed Normal Space be Camera Space, but I'm guessing View-Space the equivalent?

Sorry, it's View-Space (camera-space and view-space are actually the same).

buddhamon написал

As soon as I used a different Spine asset that had the Normal Map configured, the lighting started to work in 3D space properly for the Universal Render Pipeline/Spine/Sprite shader.

I assume that on these assets some kind of normal was generated, the normalmap alone is not sufficient (normalmaps are mostly tangent-space normalmaps, without normals and tangents it does not know it's space).

Thanks for getting back to me, Harald! Unfortunately, I still couldn't figure this out. Toggling Advanced - Add Normals or Advanced - Solve Tangents along with Fixed Normals did not manage to solve the issue of the lighting only effecting assets focused around where the X-axis equals 0.

I'm going to try attaching a normal map to my assets and configuring it from there to see if they function as intended then. I'll edit this post once I have updated the scene.


Actually... 😐 are there resources for where I can find how to attach Normals and Emission Maps?

I just created a simple modification to the URP 3D SkeletonLit shader with a toggle to enable Lit From Behind. It's rather simple, as it's just the absolute value of the dot product abs(dot(lightdir, normal)) is used instead of the dot product.

half3 LightingLambertLitFromBehind(half3 lightColor, half3 lightDir, half3 normal)
{
   half NdotL = saturate(abs(dot(normal, lightDir)));
   return lightColor * NdotL;
}

#ifdef _LIT_FROM_BEHIND
#define LightingLambert LightingLambertLitFromBehind
#else
#define LightingLambert LightingLambert
#endif

com.esotericsoftware.spine.urp-shaders-SkeletonLitFromBehind.zip

It's just a simple solution here.
While editing the Sprite shader as well I noticed that the result is rather unintuitive since a normalmap would then be strangely lit here. Anyway, I included it in the zip package below with the required file-overrides. For the Sprite shader you will need to switch Inspector to debug mode and add _LIT_FROM_BEHIND to the shader keywords to enable it, since the GUI code would otherwise need to be modified as well.


Harald написал

Toggling Advanced - Add Normals or Advanced - Solve Tangents along with Fixed Normals did not manage to solve the issue of the lighting only effecting assets focused around where the X-axis equals 0.

Do you still need this given the lit-from-behind functionality?
If yes, please post a screenshot of the problem.

Harald написал

Actually... 😐 are there resources for where I can find how to attach Normals and Emission Maps?

What exactly do you have problems with? You create normal and emission maps in the editor of your choice based on the normal atlas texture (with Photoshop, Substance Alchemist, etc.) and assign the textures to the slot in the Material Inspector.


I forgot to mention this above: I decided against adding the Lit From Behind feature officially since it's a very narrow use case. What will be added is an option for lighting the back-face at the SkeletonLit shader, a parameter Double Sided Lighting.


Harald написал

What will be added is an option for lighting the back-face at the SkeletonLit shader, a parameter Double Sided Lighting.

This feature has just been completed, all SkeletonLit shaders now provide a Double Sided Lighting parameter to properly light the back-face as well.
New 3.8 spine-unity, URP and LWRP packages are available for download here as usual:
Spine Unity Download: Download

Harald написал

What exactly do you have problems with? You create normal and emission maps in the editor of your choice based on the normal atlas texture (with Photoshop, Substance Alchemist, etc.) and assign the textures to the slot in the Material Inspector.

Okay, I'll give this a try soon. The main problem is simply that I don't know how to attach those maps to my Spine assets, but truthfully, I haven't done the research on it yet. I'll try attaching them and reading some tutorials on it and then maybe get back to you when I succeed/fail. That might be a post for another problem later down the line.

Harald написал

This feature has just been completed, all SkeletonLit shaders now provide a Double Sided Lighting parameter to properly light the back-face as well.

I downloaded the new version and reinstalled the URP/LWRP packages and gave it a try. Awesome work! Again, I super appreciate you doing all of this to help me out. However... tragically, I think we miscommunicated. The Lit From Behind functionality I poorly described aimed to light the front of the asset where the light was behind it.

In this first image, the asset is lit as intended with the light in front of the asset.

In this second image, the asset is unlit with the light behind the asset.

Sadly, lighting the asset from the other side isn't the desired effect, instead I wanted the asset to be lit as if the light was cast in the front of the asset as seen in the first picture. The reason behind this is that the world is 3D with the characters being 2D. The characters can traverse the X and Z axis but their Spine's are always orthogonal to the Camera View. As a result, I wanted to implement a lighting system that applied in a unique way for these characters.

You've been such an amazing help, Harald, I completely understand if this exceeds the scope of the original post, and I will do my best to solve this problem on my own after I acquire further shader knowledge. Either way, again huge thanks.

buddhamon написал

Okay, I'll give this a try soon. The main problem is simply that I don't know how to attach those maps to my Spine assets, but truthfully, I haven't done the research on it yet. I'll try attaching them and reading some tutorials on it and then maybe get back to you when I succeed/fail. That might be a post for another problem later down the line.

Ah, sorry, I think I misunderstood your question. You have to use a shader which provides the Normal Map parameter at the Material Inspector. The Spine/Sprite/Vertex Lit and Spine/Sprite/Pixel Lit shaders provides this for the normal pipeline, the shaders Universal Render Pipeline/2D/Spine/Sprite and Universal Render Pipeline/Spine/Sprite for URP.
And in case you mean that: You currently cannot assign a normalmap attachment image in the Spine Editor. This is only done in the spine-unity runtime side.

It's best if you take a look at Stretchyman's Material in the URP 3D Shaders example scene that comes with the Spine URP extension package. This shows a normalmap assigned. For the normal render pipeline, it's shown in the Sprite Shaders example scene.


Harald написал

Sadly, lighting the asset from the other side isn't the desired effect, instead I wanted the asset to be lit as if the light was cast in the front of the asset as seen in the first picture

Hm, this is strange, I implemented it in a way which should light it as your first image shows, even when the light is placed behind (which was the whole point).

Which of the two shaders are you using? If you are using the Sprite shader: did you add _LIT_FROM_BEHIND to the shader keywords as described above to enable it?

Thanks for your kind words!

Harald написал

And in case you mean that: You currently cannot assign a normalmap attachment image in the Spine Editor. This is only done in the spine-unity runtime side.

Oh! Okay, this is very interesting. I will try to figure out how to create correct maps for my Spine assets using the Universal Render Pipeline/Spine/Sprite shader. Thanks for the clarification! I've looked at the Stretchyman Material a few times in the past, but I struggled a little on how to generate the .png file for each map. I'll look into it again though with my fingers crossed.

Harald написал

Hmm, this is strange, I implemented it in a way which should light it as your first image shows, even when the light is placed behind (which was the whole point).

Ah. Sorry, I completely misread what you said in your previous post! My apologies! Yes, after I implemented what you suggested it worked fine for Skeleton Lit. HUGE thanks! There was one hiccup with the dot product getting zeroed out when the normal and lightDir were on the same Z-Axis, which made the object black/unlit. Since I will probably be only using point lights in my project, I changed the function to:

half3 LightingLambertLitFromBehind(half3 lightColor, half3 lightDir, half3 normal)
{
   half mag1 = length(normal);
   half mag2 = length(lightDir);

   return lightColor * saturate(mag1 * mag2);
}

... which produced the desired effect. I'm not entirely sure what each variable does nor have I ever worked in HLSL, but it seemed to work for the time being. Hoping this code doesn't cause the world to catch on fire! :grinteeth:

Using specifically the Stretchyman's Material in the URP 3D Shaders example scene along with the Sprite shader, I see what you mean with the asset looking a little strange while Lit From Behind is enabled. The normalmap and its lighting definitely seems a little off when the light is behind the asset. For the time being I think I will stick with the Skeleton Lit shader in the URP/Spine package without using a normal or an emission map. Once I figure out how to incorporate the Sprite shader with the attached maps/textures, I will revisit the Sprite shader you have provided and see if there is an alternative solution to the lighting that yields a symmetrical result if the asset has Lit From Behind enabled.


I just tested it all out, depth of field, 3D lighting with 2D assets, URP and Spine, bam! It really works wonderfully for the time being. Thank you so, so much again, Harald, I really, really am grateful for all your help. If you are ever in Los Angeles, let me know and I will gladly buy you dinner! :grinteeth: