Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by brettjcooper · Sep 23, 2016 at 01:39 PM · lightingspritesnormal maps

Why does this sprite's normal map only light correctly from one direction?

Base Sprites

I'm trying to use a Normal/Depth map to light a 2D sprite. These are the Diffuse and Normal/Depth sprites (two separate sprites in Unity): alt text

The Weird Issue

The problem is, the character is lit correctly when "facing" the light, but is not lit correctly from behind when "facing" away:

alt text

I am new to Unity, so I'm wondering if there's some gotcha here I don't know about? Maybe something with normals or something, I dunno..any help would be greatly appreciated!

Details:

  • I'm using the Sprite Lamp "Standard" shader.

  • The light is a standard Unity spotlight at Z position = -1 (no rotation or scaling).

  • The arc of light you can see behind the character is the spotlight falling on a wall sprite at Z position = 4.

  • The character sprite is at Z position = 0 (no rotation or scaling).

  • I flip the X Scale of the character sprite to make him face left or right.

Edit:

I guess I should mention that both the Diffuse and Normal/Depth maps are imported as Sprites, which I believe automatically get rendered on both sides along the Z-axis so you can flip their X Scales without disappearing them. Sprite Lamp was made with 2D in mind, so it allows you to use Sprites for your maps instead of other kinds of Textures that may be drawn on only one side (causing normals to point away from the camera).

diffuse-normaldepth.png (3.3 kB)
examples.png (38.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Sep 23, 2016 at 01:46 PM

I believe this is one of those odd cases where working in 2d is actually much harder than working in 3d.... I don't know the details of the shader you're using but my gut feeling is that it's a double-sided shader, which won't work with normal maps - you can "flip" a texture from left-to-right by using xscale *= -1, as you have done, but doing this to a normal map will mess up the tangents so the light will apparently be coming from "behind" the object instead, as your screenshots show.

So you need to render the back face and front face side in a separate pass and manually hardcode the tangent vector. There's an example in this thread that shows how.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image brettjcooper · Sep 23, 2016 at 03:22 PM 0
Share

Thanks for your reply, @tanoshimi! Would that explain the middle two images where the X Scale is -1 on both, but the lighting "works" on one and not the other? I'm having a hard time understanding how the X Scale can be to blame, since the last image is not flipped and still exhibits the issue.

avatar image
0

Answer by Zirok_ · Dec 02, 2021 at 05:28 PM

I figured this out, It happens when you have two or more source lights affecting an sprite, so you have two options:

1) Delete one of the source lights 2) [Recomended] set the culling mask of one of the light sources to affect everything except the layer where your sprite is.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Sprite Diffuse shader not affected by point lights 1 Answer

Lighting with scaled sprites 0 Answers

Make a sprite have the same color as the main light of the scene 1 Answer

How do I make a working, tiling Sprite shader that works with 2D LWRP? 0 Answers

2D Sprite Shader Acting like Light 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges