Hi everyone!
My project is built in URP 2D, and I want to use Normal Map and 2D Light to achieve better lighting effects and cast shadows for the skeleton. However, when I change the character's shader to Spine/Sprite/Vertex Lit, it appears magenta. How can I use Normal Map and 2D Light in a URP 2D project? Thank you very much!
How to Use Normal Map and 2D Light in Universal 2D Project
To use Normal Map and 2D Light in a Universal Render Pipeline (URP) 2D project, you need to use the appropriate shaders provided by the Spine URP Shaders UPM package. Here are the steps to achieve this:
Install the Spine URP Shaders UPM Package:
- Download and install the Spine URP Shaders UPM package from the Spine Unity download page.
Use the Correct Shaders:
- For URP 2D projects, you should use either the
Universal Render Pipeline/2D/Spine/Skeleton Lit
orUniversal Render Pipeline/2D/Spine/Sprite
shaders. These shaders are designed to work with URP 2D lights and support normal maps. - Do not use
Spine/Sprite/Vertex Lit
as it is not compatible with URP 2D and will result in the magenta (pink) error color.
- For URP 2D projects, you should use either the
Assign Normal Maps:
- You can assign normal maps to your materials in the Unity Inspector. Ensure that your normal maps align correctly with the texture atlas of your skeleton.
- Note that you cannot assign normal map attachments directly in the Spine Editor; this must be done in Unity.
Example Scene:
- Check out the
URP 2D Shaders
example scene included in the Spine URP Shaders package. This scene demonstrates how to set up and use the shaders with normal maps and 2D lights.
- Check out the
Project Settings:
- Ensure that your project settings are correctly configured to use the URP 2D Renderer. This includes setting the appropriate URP Asset in
Project Settings - Graphics - Scriptable Render Pipeline Settings
andProject Settings - Quality - Rendering
.
- Ensure that your project settings are correctly configured to use the URP 2D Renderer. This includes setting the appropriate URP Asset in
By following these steps, you should be able to achieve the desired lighting effects and shadows using normal maps and 2D lights in your URP 2D project.
Thanks bot, I opened the recommended URP 2D Shaders reference project, but the character in this project is still magenta. I have already set the Example 2D URP Asset in Project Settings > Graphics > Scriptable Render Pipeline Settings and Project Settings > Quality > Rendering > Render Pipeline Asset
I received the following error:
Shader error in 'Universal Render Pipeline/2D/Spine/Skeleton': Couldn't open include file 'Packages/com.esotericsoftware.spine.spine-unity/Runtime/spine-unity/Shaders/CGIncludes/Spine-Common.cginc'. at /Unity/Projects/testURP/Library/PackageCache/com.esotericsoftware.spine.urp-shaders@b1fe837e8a/Shaders/Include/SpineCoreShaders/Spine-Common.cginc(2)
Compiling Subshader: 0, Pass: <Unnamed Pass 0>, Vertex program with <no keywords>
Platform defines: SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: FOG_EXP FOG_EXP2 FOG_LINEAR INSTANCING_ON SHADER_API_GLES30 UNITY_ASTC_NORMALMAP_ENCODING UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING _STRAIGHT_ALPHA_INPUT _TINT_BLACK_ON
Thanks for your help
wpw1221 How did you add the URP shader package to your Unity project? Be sure to use the same method you used to add the spine-unity runtime to your Unity project. Otherwise, the shader include paths of the URP Shaders UPM package will point to a spine-unity package directory that does not exist, resulting in shader compilation errors.
Thank you, Misaki. I found out it was indeed my mistake. I added the Runtime using the installer and also added the URP Shader Package via URL, ignoring the reminder in the instructions (requires spine-unity installed via UPM). Now all the examples and my characters are working correctly. Thanks again!