Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by chump_fighter · May 27, 2021 at 09:24 AM · lightingspritesshadows

How do games like Octopath Traveler handle the angle of shadows, and is this even possible in Unity? [URP]

I'm working on one of those 3D environment 2D sprite projects, and I've been able to get the sprites to cast and receive shadows without any real issue. Since I'm using 2D sprites, and I want the camera to be angled to make the ground more visible, I'm "billboarding" the sprites, so that they're always directly facing the camera. This is where the issue comes in. Rotating the sprites on the X axis changes the angle of the shadow. This really shows when a 2D object that has been billboarded is near a 3D object, since the 3D object does not have this shadow angle issue. Here's an example of Octopath having no issue with this:


alt text


And here's an example of the issue in my test environment: alt text


It's already damaging enough to the illusion that the sprite is at a different angle than the 3D objects, but I've found that perspective in the spritework can help with that. But the shadow issue absolutely kills it, in my opinion. So, does anyone know of some sort of way around this? I've already explored having a second, not billboarded sprite that is only rendering shadows, which works pretty well, except for the fact that the invisible shadow sprite will cast it's shadow on the main sprite. The only way around this is to use an unlit shader for the sprite, which is largely against the point of what I'm trying to do here. The most ideal solution I could think of is to have the lighting and shadows calculated on the sprites, and then billboard them. I'm currently researching the URP API to look into this, but I don't know if it's even possible. Any ideas would be greatly appreciated.

octopath.jpg (272.2 kB)
capture.png (66.0 kB)
Comment
Add comment · Show 4
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 andrew-lukasik · May 27, 2021 at 09:24 AM 0
Share

You probably need to create a shader with ShadowCaster pass that rotates your geometry toward light direction vector in y axis, or something like that.

avatar image chump_fighter andrew-lukasik · Jun 03, 2021 at 04:25 PM 1
Share

Sorry for the late response, this sent me into spending some time researching and learning about writing shaders. I finally got to a point where I was able to rotate the geometry in the shadowcaster pass, but unfortunately this makes the shadow cast onto the object itself. So I've found myself once again stuck at another wall. Thank you for your suggestion, though.

avatar image andrew-lukasik chump_fighter · Jun 03, 2021 at 06:42 PM 0
Share

Oh goddammyt, you're right! Sorry for misguiding you, I didn't thought it through at all.

This is interesting problem you're dealing with here. Probably another vacuous idea... but maybe adding a simple geometry shader that will extrude faces along normals (give them thickness) in that ShadowCaster pass you created, would help here.

avatar image KqGMRPFkAeESzF8 · Sep 26, 2021 at 11:53 AM 0
Share

how did you get 3D shadows to work with 2D sprites?

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by chump_fighter · Jan 24 at 10:24 PM

So it's been quite a while since I made this, but I managed to come to a workable solution to this issue that I thought would be worth posting in case anyone stumbled upon this topic. Basically, rather than simply rotating 2D objects to face the camera, I wrote a script to apply a custom projection matrix to the camera, that makes everything on the Y axis face the camera perfectly, as can be seen here:

alt text


I came to this solution after eventually finding this article. The projection matrix script is linked at the bottom of the article, but I had to change some stuff to get it to work. Here's the relevant bit I had to change:

     private void OnPreCull()
     {
         // First calculate the regular worldToCameraMatrix.
         // Start with transform.worldToLocalMatrix.
 
         var m = GetComponent<Camera>().transform.worldToLocalMatrix;
         // Then, since Unity uses OpenGL's view matrix conventions
         // we have to flip the z-value.
         m.SetRow(2, -m.GetRow(2));
 
         // Now for the custom projection.
         // Set the world's up vector to always align with the camera's up vector.
         // Add a small amount of the original up vector to
         // ensure the matrix will be invertible.
         // Try changing the vector to see what other projections you can get.
         m.SetColumn(1, 1e-3f * m.GetColumn(1) + up);
 
         GetComponent<Camera>().worldToCameraMatrix = m;
     }

I admittedly don't know why it works this way, but I had to change the script to set column 1 instead of column 2. This solution of course has now come with another set of issues (URP shadows aren't working correctly, moving up on the Y axis causes objects to appear to move backwards,) but I think that it might be beyond the original scope of this topic.


custom-matrix.png (59.2 kB)
Comment
Add comment · Show 2 · 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 itstimetomakelol · Jan 25 at 01:24 PM 0
Share

You're an absolute goat for posting the solution after 8 months thanks a lot man!

avatar image andrew-lukasik itstimetomakelol · Jan 26 at 10:07 PM 0
Share

What does "goat" mean in the land you come from?

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

206 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Large models like mountains not casting shadow on plane 1 Answer

Hide 2D light beneath another light's cast shadow 0 Answers

Getting strange square lighting artifacts, despite the room being well lit? 1 Answer

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

GameObject doesn't cast a shadow 3 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