• RuntimesUnity
  • Looking for an easier way to set up emissive and light mask

Hi, I recently started using Spine. It's been pretty straightforward in most scenarios, but I would like to know if there's a smarter way to animate emissive maps and light masks for Unity.

I used to separate all maps before importing them into the engine, having to make sure all maps are exact in sizes and angles has been painful, and I can't animate them.

Now I realise that I can just use the default output file from Spine, and by changing the material type to Universal Render Pipeline/2D/Spine/Sprite, it works almost as intended. The only problem is I don't know how to set up the rim light mask that I made in Spine.

As you can see it's pure white in runtime instead of partially lit by the environment:

I didn't find any option to set the light mask to only use a red light channel like what I used to do.

Here's an example of what the light mask is supposed to look like:

Thanks beforehand if you can give me some hints or suggestions

  • Harald ответили на это сообщение.
    Related Discussions
    ...

    To set up emissive maps and light masks more efficiently in Unity using Spine, you can leverage the Spine URP shaders. Here are some steps and tips to help you achieve the desired effect:

    1. Use Spine URP Shaders: Ensure you have the Spine URP Shaders UPM extension package installed. This package includes shaders specifically designed for Spine animations in Unity's Universal Render Pipeline (URP).

    2. Shader Selection: Use the Universal Render Pipeline/2D/Spine/Sprite shader for your materials. This shader supports emissive maps and can interact with URP 2D lights.

    3. Emission Map Setup: In the material settings, you can assign an emission map. This map will define which parts of your texture emit light. Ensure your emission map is correctly set up in Spine and exported along with your main texture.

    4. Rim Light Mask: For the rim light effect, you can use the emission map channel provided by the Universal Render Pipeline/Spine/Sprite shader. Adjust the emission color and intensity to achieve the desired rim light effect. If you need the rim light to react to the environment, you might need to script the emission intensity based on the light source's position relative to the character.

    5. Normal and Light Maps: If you want to use normal maps for more detailed lighting effects, ensure your normal maps are correctly set up and assigned in the material settings. The Universal Render Pipeline/Spine/Sprite shader supports normal maps, which can enhance the lighting interaction on your character.

    6. Example Scene: Check out the 2D/URP 2D Shaders.unity example scene provided with the Spine URP Shaders package. This scene demonstrates how to set up materials and lights for Spine animations in URP.

    Here is a brief example of how to set up the material in Unity:

    Material material = new Material(Shader.Find("Universal Render Pipeline/2D/Spine/Sprite"));
    material.SetTexture("_MainTex", mainTexture);
    material.SetTexture("_EmissionMap", emissionMap);
    material.SetColor("_EmissionColor", Color.white * emissionIntensity);

    For more detailed control over the rim light effect, you might need to write a custom shader or script to adjust the emission based on the light source's position.

    By following these steps, you should be able to set up your emissive maps and light masks more efficiently and achieve the desired lighting effects in Unity.

    Unfortunately, this bot doesn't know what it's talking about.

    1. It doesn't answer the question
    2. It provided the same solution to different problems. How is writing a new set of 2d light detection functions an 'easier solution' let alone we are using many fake lights to save performance
    3. It hallucinates non-existing example scenes
    4. The code it provides is pointless as it's already a made option in Unity
    • Misaki ответили на это сообщение.

      Cheshirecrow Sorry the bot's answer is not helpful. However, the example scene the bot mentioned is existent. The example scene is not added to the project unless you press the Import button in the Samples section of the package manager, so I guess that's why you missed it:

      After importing the examples, set the Example 2D URP Asset to Scriptable Render Pipeline Settings in Project Settings - Graphics.

      Then you can check the example scene 2D/URP 2D Shaders.

      I'm not very familiar with lighting, so I'm not sure if this will solve your problem, but it's worth a look if you haven't already checked it out.

      • Cheshirecrow ответили на это сообщение.

        Misaki Thank you so much for the step-by-step tutorial, I suppose that's why I never found it. Just this example scene alone is probably all I need. I'll spend some time studying it.

        Misaki Oh, unfortunately, the setup in the scene did what I used to do for static emission maps. Do you happen to know any examples of Spine-animated emission maps that also have the correct light mask setup inside runtime?

        • Misaki и Harald ответили на это сообщение.

          Cheshirecrow Unfortunately I do not have detailed insight on that, so please wait for a response from our Unity expert Harald.

          Cheshirecrow Oh, unfortunately, the setup in the scene did what I used to do for static emission maps. Do you happen to know any examples of Spine-animated emission maps that also have the correct light mask setup inside runtime?

          What do you mean by static emission maps? You might want to check out this forum posting which describes the URP 2D example scene rim light setup:
          https://esotericsoftware.com/forum/d/15745-2d-light-urp-light-mask-duffuse-ramp-and-specular/5

          Basically it's a combination of declaring the light type for each mask channel in the Renderer2DData asset, adding a light to the scene which emits light with the respective Blend Style and then at the skeleton Material have the respective mask channel (e.g. the red channel) have a non-black value where it should receive this specific light type.

          • Cheshirecrow ответили на это сообщение.

            Harald Thank you fro the reply. Yes, I've checked this post before and it's been exactly how I set up other sprites.

            By static emission maps, I mean using one map for the emission channel as this screenshot shows, I'm not sure if it's possible to animate it or modify it with a shader on top of the Spine's material:

            The goal is to figure out an effective way to get animated emissive lights in runtime with the correct rim light which uses the red channel. It's possible to animate the emission map in the Spine as an 'additive' layer and export it to runtime with almost perfect results, the only problem is the light mask will be carried from the Spine as well (no option to change the blend mode for it). Please check the video I sent from the previous post and you can see how it looks

            I would be very grateful if you have a better solution as this would speed up the work process greatly

            • Harald ответили на это сообщение.

              Thanks for the additional info.

              Cheshirecrow The goal is to figure out an effective way to get animated emissive lights in runtime with the correct rim light which uses the red channel.

              I'm afraid I don't quite understand the desired combination of rim light and emissive light here. Normally the rim light is created by outside sources, a 2D Light placed in the scene where the back of the character should be lit when moving past it. For the rim light, the skeleton's material just controls reflection intensity of such lights, via the Light Mask, limiting reflections to the rim. Emissive light on the contrary is used for light sources emitting light from the skeleton, like e.g. green fluorescent areas or glowing eyes. If you want to control the emissive map's intensity at runtime, you normally set the emissive map to cover only the glowing areas, and then change the color parameter next to it accordingly, which is multiplied with the mask. You can then use e.g. a MaterialPropertyBlock to avoid creating material duplicates.

              Cheshirecrow I didn't find any option to set the light mask to only use a red light channel like what I used to do.

              Here's an example of what the light mask is supposed to look like:

              If like in the short video section you posted earlier, this looks more like you want to place a 2D Light in the scene at the respective location (or let the position move with a bone via a BoneFollower) and then let it light your skeleton. How did you originally create this lighting effect? Why can't you reproduce it with the Light Mask now, what prevents it from working?

              • Cheshirecrow ответили на это сообщение.

                Harald Thanks, I understand the concept of achieving this effect in runtime and I can recreate this light effect as needed. The reason why I'm trying to find a better way to do it is because of the lack of control over the emission map (animation).

                Now I'm trying to make an automated landmine as you can see in the first video. The emission map should be animated on or off depending on its active states and I achieved that by animating an 'additive' layer inside Spine and then exporting it into Unity. Here's what the material looks like in runtime for this animated emission effect:

                Instead of setting a light mask or emission, Spine did a good job combining all meshes into one:
                But now I can't set up the light mask like I used to do as that wouldn't fit in with this atlas

                Do you have any suggestions?

                • Harald ответили на это сообщение.

                  Cheshirecrow The emission map should be animated on or off depending on its active states and I achieved that by animating an 'additive' layer inside Spine and then exporting it into Unity.

                  Thanks for sharing the details. Unfortunately I don't quite understand, why don't you use the additive slot blend mode any more if it worked before? Or did you run into problems making the additive blend mode work with URP?

                  Cheshirecrow But now I can't set up the light mask like I used to do as that wouldn't fit in with this atlas

                  You don't pack mask or normal textures into the atlas, you need to have an identical atlas texture for the mask where only these regions are not black.

                  • Cheshirecrow ответили на это сообщение.

                    Harald So what do you suggest I do if I need to achieve the flickering effect in the first video? Could you give a general idea of how to achieve the same effect with the separated textures method?

                    • Harald ответили на это сообщение.

                      Cheshirecrow I would create a 2D Light at the respective position and vary it's intensity over time. If you need to mask the effect to some parts of the skeleton, then have the 2D light's Blend Style set to be e.g. rim. Then let the mask atlas texture at the skeleton only be non-black (in e.g. the red channel) where you want the light to affect the skeleton.

                      Note that the mask texture is a copy of the normal atlas texture with identical layout, not adding mask attachments to your normal atlas texture. You can ensure the identical layout by creating the mask atlas texture from the output normal atlas texture, or pack attachments by folder structure and ensure that all attachments to be packed are of the same size and have Strip whitespace X/Y disabled to ensure all are packed with identical layout.

                      If I misunderstood your question, please let me know.

                      • Cheshirecrow ответили на это сообщение.

                        Harald Do you mean adding another 'Light blending style' and using additional lights to control the emission map aside from rim lights?

                        Does this mean 'additive layers' from Spine are useless if I want to use a light mask in runtime and I should remove them completely?

                        • Harald ответили на это сообщение.

                          Cheshirecrow Do you mean adding another 'Light blending style' and using additional lights to control the emission map aside from rim lights?

                          Sorry if the description didn't help. I was mostly describing how to create the lighting effect for the second video you posted, the one with the walking robot below the text "Here's an example of what the light mask is supposed to look like". Your example of the rolling ball is actually a bit different.

                          Regarding your first video with the multiple red lights at the ball, plus the white rim mask:
                          The red lights and the rim are completely separate things. For the white rim, if the ball would not be rolling: the rim atlas texture should be assigned at the Light Mask with only these atlas parts non-black where the rim light should be displayed. Then place 2D Lights in your environment with Blend Style set to Rim. And don't set the rim light attachment slot to Blend Mode Additive, you want to use the 2D Light to light the masked parts. That all applies if the ball would not be rolling.

                          Since the ball is rolling, you have the problem that the rim moves with it. To fix that would require the attachment to be separate and aligned horizontally via e.g. a TransformConstraint or overriding bone location programmatically, or using a similar solutions to keep the bone horizontal. Since you can't separately rotate the rim mask texture from the normal color texture at a single attachment, you need to have two separate bones with separate attachments. This fixes the orientation part of the problem. The light-attachment at the top could have Blend Mode Additive. Then you would enable the material parameter Light Affects Additive, so that the 2D Lights are multiplied with the additive color. With this combination, you should not need a mask for this rim light any more, as the light is multiplied already with the additive texture, resulting in the mask effect.

                          Regarding the multiple red lights: I'm not quite sure what the exact problem with those was, but you can simply enable the Emission property and assign the emission atlas texture there (again, identical in layout to the normal atlas texture, only white where the red lights are), then modify the color property next to it (programmatically e.g. via MaterialPropertyBlock to avoid material copies).

                          • Cheshirecrow ответили на это сообщение.
                            • Изменено

                            @Cheshirecrow An easier solution would be to have the rim mask cover the whole area of your ball, and to have Spotlight rim lights illuminate the top part brighter than the bottom.

                            You can actually see a similar setup in the example scene URP 2D Shaders, at the Spine GameObject (stretchyman) objects, there you can have a look at the material setup.

                            Harald Regarding the multiple red lights: I'm not quite sure what the exact problem with those was, but you can simply enable the Emission property and assign the emission atlas texture there (again, identical in layout to the normal atlas texture, only white where the red lights are), then modify the color property next to it (programmatically e.g. via MaterialPropertyBlock to avoid material copies).

                            Thank you for the wall of text, this is what I'm looking for. Sadly there isn't any solution to animate it directly inside Spine but I guess it is what it is. I'll talk to the programmer and figure out a way.

                            I really appreciate your help, wish you have a wonderful week

                            • Harald ответили на это сообщение.