Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
2
Question by Jazzypants360 · Aug 14, 2013 at 03:33 AM · shadowsprojection

Detecting the location of a shadow that is being projected onto a plane

Long time developer, first time 3D Dev and Unity user...

Let's say you have a bunch of primitives in a scene that are being lit by a directional light source. Now, imagine that you have a plane in the scene as well, such that shadows of the primitives are being projected onto the plane. How might one go about trying to detect where those shadows are relative to the plane?

The eventual goal is to take the 2D geometry of the shadows as a basic shape, and then extrude them into 3D objects. The important part here is that the 2D geometry needs to be in the shape of whatever shadows are being projected onto the plane.

Thanks in advance!

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

1 Reply

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

Answer by Sajidfarooq · Aug 14, 2013 at 05:03 AM

O = Shape that casts shadow

L = light

1) If you had a "point" light: Find the vectors from each vertex of the O to L. These are now "rays". Find the intersection between these "rays" and the plane on which the shadows are projected using the built-in ray-casting functions in Unity.

2) Directional light:

A directional light does not have a specific location, but it does have direction. Hence, you already have a ray, but the "location" is not specified. Add this ray to each vertex on O to get a ray that is cast from L to that specific vertex of O. Again, "ray-cast" each ray to find its intersection point on the plane on which the shadow is cast.

Comment
Add comment · Show 10 · 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 Jazzypants360 · Aug 14, 2013 at 01:11 PM 0
Share

This seems to be the exact concept I was looking for. I'm assu$$anonymous$$g I'll be able to deter$$anonymous$$e the coordinates of the intersection on the plane from the RaycastHit info. I'll poke around with that later today and see what I come up with. Thanks so much for the quick response!

avatar image Jazzypants360 · Aug 15, 2013 at 04:19 AM 0
Share

So, I'm now able to deter$$anonymous$$e the coordinates of all of the intersections between the rays (from light L through the vertices of O) and plane P. Next, I'm trying to make a polygon in the shape of the shadow on plane P and extrude that polygon. The trouble is that I'm not sure how to define the polygon, since I don't know which pairs of vertices should be used to create the edges. Depending on how I construct the polygon, I might end up with a closed shape, or I might end up with a bunch of criss-crossed lines from one vertex to the next. Thinking further down the road, this becomes much more complicated when there are shadows from multiple primitives.

Since this is basically the same problem that a rendering engine must solve when producing shadows, I'm assu$$anonymous$$g there must be a well-defined solution for how to do this out there, and perhaps my explanation just led us astray.

Any suggestions on how to proceed? If I could find a way to define the polygons that make up the shadow, I'd be golden.

avatar image Sajidfarooq · Aug 15, 2013 at 05:22 AM 1
Share

What you need is a "Convex Hull" of the points you just found. There are other approaches, but the Convex Hull is the simplest. It may not work for all cases, but its best to implement it first, and then worry about what is not working. http://en.wikipedia.org/wiki/Convex_hull

avatar image Sajidfarooq · Aug 15, 2013 at 04:31 PM 1
Share

The convex hull is not implemented in Unity, but there are several c# implementations. Try this or this.

Do note that the Convex Hull will fail for some shapes/shadows. However, its best to first try it and see if it works for you before trying a more exhaustive approach.

avatar image Sajidfarooq · Aug 16, 2013 at 04:05 AM 1
Share

The Convex Hull does have connectivity information. It finds connectivity for the outermost points, i.e, the convex hull. Problems arise when the shadows are not necessarily convex...

Show more comments

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

17 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

Related Questions

Detecting the location of a shadow that is being projected onto a plane 1 Answer

Custom projection matrices make shadows impossible 2 Answers

Distance in the shadows of the sprites and quads. 0 Answers

Shadows and the camera projection matrix 0 Answers

custom projection matrix cascaded shadows. 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