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 Wikzo-DK · Oct 04, 2016 at 03:01 AM · raycastcolliderlightshadowshadowmap

Accessing a shadowmap and using it in C# script to turn off colliders?

Hi. I previously asked this question: https://forum.unity3d.com/threads/dynamic-cutout-mesh-colliders-using-shadow-maps.433729/

Basically, I want to achieve the effect of "cutting"/disabling a part of an object when it is in shadow (so it doesn't collide with anything, even though it is still visually rendered).

Now I am getting closer to a solution.

The setup: I want to disable certain colliders based on whether they are in shadow or not (using a spot light in Unity).

I have a box that consists of many smaller box colliders (4x4): alt text

Basically, I am trying to access the shadowmap/depth texture, which stores the closest point seen from the light's point of view. So far, I have managed to create a depth texture using this guide: http://williamchyr.com/2013/11/unity-shaders-depth-and-normal-textures/

However, this shadowmap/depth texture is created from the camera and not the light source (right now, they are placed in the exact same spot). Also, the camera's culling mask doesn't include the box colliders, so they won't affect the shadowmap/depth texture: http://imgur.com/9WG0L8G

Using this depth value, I want to compare it against the distance of each of the (box) colliders. If the distance from the light source to the collider is larger, then it means that the collider is in shadow (and should be turned off). Here are two examples (purple area should be turned off): http://imgur.com/AtBuZia http://imgur.com/ZL4BLVJ

Here is an image that illustrates the distance check I want to make (e.g., one of the center colliders): alt text

Usage example: if I push a box halfway into a shadow, it should start "tumbling" as if it is tipping due to gravity. E.g., in the image below, the box is halfway in shadow, so you would expect it to start falling down into the shadow and get "absorbed" by it (because each colliders turn off when in shadow; when all are turned off, the object won't collide with the floor and therefore fall down through the shadow): http://imgur.com/nV0UzT5

So, what I need now is to be able to access this shadowmap/depth texture and look up each of the colliders and the corresponding depth value. This value should then be compared to the actual distance between the collider and the light source. However, I am having problems with doing this, since I am unsure how to use the position of a gameobject (the collider) with the shadowmap (which is being generated in a post-processing shader).

Also, I would really like to directly access the built-in shadowmap generated by each of the light sources in Unity, instead of manually having to create them by placing a camera in the same spot as the light.

Do you have any suggestions of how to do this? I assume I need to do some communication between shaders and C# scripts, since the shadowmap would have to be generated via a shader, and then a C# should be able to take that and compare the depths with Vector3.Distance() for each of the colliders (and decide to turn them on/off).

Thanks a lot 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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using shadows as Triggers? 1 Answer

How to access shadow map depth values? 0 Answers

How to detect if an object is under a shadow casted by a directional light 1 Answer

Can't get a laser working properly. 2 Answers

why are child colliders sometimes ignored? 2 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