- Modifié
Post Processing with URP not working with Spine Assets
Hello! I was having some trouble getting a depth of field effect on my Spine assets. I wanted the camera to blur out spine assets far in the distance, while the ones up close remained in focus. I was wondering if there was an easy fix to this using URP or if I should look into other shaders that better address Spine assets and this desired effect.
Here is an example image. The two cubes are aligned with the Spine assets, yet only the front cube is in focus while the adjacent Spine is out of focus.
Please have a look at this posting here:
Sprite shader depth write
Most likely the depth of field effect you use is using the depth buffer to determine the blur intensity. Most shaders included in the spine-unity package are not writing to the depth buffer (to allow for better alpha blending at the silhouette) by default. You can either use those Spine shaders that provide a depth write (zwrite
) option or use a zwrite
shader variant (see the shaders section of the spine-unity documentation pages). You could also create a copy of your desired shader and add the required ZWrite On
and alpha clip lines, however this will require a bit of shader editing.
Thanks, Harald, for the amazing response time as always! Sorry to get back to you so slowly!
I haven't gotten around to testing your recommendation yet. I might give it a few more days before I go down this rabbit hole again. I'll keep you posted if it works out or if I run into any more problems.
Hi Harald
I use the "Spine/Sprite/Unlit" shader ,the depth map is correct ,but the layer is wrong
picture 1 layer is wrong
picture 2 does not have depth map
I know the "Transparent" not have CameraDepthTexture ,but how can i using the depth to do some effect in spine.
@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 a écritI know the "Transparent" not have CameraDepthTexture
What do you mean by that?
Are you using the URP 2D render pipeline?
@[supprimé]
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.
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.
- Modifié
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 a écritIf 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 a écritusing 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 a écritSo 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 a écritDo 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 a écritIt 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 a écritI 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 a écritWhy 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 a écritSo 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 a écritI'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 a écritDid 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 a écritMaybe 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 a écrit(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 a écritAs 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).