Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Puddleworker · Sep 24, 2012 at 05:21 PM · lightexposure

Is there a way to measure light exposure for a specific point in the game world that can be used in scripts?

I am trying to build a game that features monsters who scurry away from light and toward darkness. Is there any way I can use scripts to measure what the current light exposure at a given point is?

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 shaderop · Sep 24, 2012 at 05:45 PM

As far as I know you can't count on lights/objects invisible to the camera to contribute to lighting/receive lighting because the 3D engine should optimize these out to save on rendering time. Even if you can somehow force the lighting calculations to happen it still would be a very inefficiency way to do what you want.

Best way would probably be to simply measure the distance to the nearest light and move the creature away from it.

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 Puddleworker · Sep 24, 2012 at 06:04 PM 0
Share

What if I have an object that is visible to the camera, like the creature model? Is there still no way to sample light exposure?

avatar image shaderop · Sep 24, 2012 at 06:25 PM 0
Share

Off the top of my head, you can render the camera view to a texture that has the same pixel dimensions as the screen, use the method Camera.WorldToScreenPoint to convert the creature's position to screen position, and use that to read the RGB value on the texture to which you have rendered the screen to get the light intensity. But I'm not sure how well that would work (if at all).

avatar image
0

Answer by Muuskii · Sep 24, 2012 at 06:37 PM

You might actually be able to generate a mesh that takes the same shape as the light's area of effect (more efficient if the light doesn't move) and then if a given point is inside of that mesh calculate the distance and intensity to see if there's too much light exposure.

I'd have to do some research on how to calculate the mesh shape. But from my understanding: Collision contact points give vertex positions and positions where edges clip through colliders. So that can give you a bit of a starting point on how to form the starting mesh.

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

11 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

Related Questions

Light Switching Unexpected Token Error 1 Answer

Light Script that increses brightness when button pressed then shuts off 1 Answer

How to stop rendering light? 1 Answer

How do I change a spot light to a point light by pressing a key? 1 Answer

Light script flashes on and off 1 Answer


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