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
1
Question by ZhanRnL · May 08, 2010 at 12:35 AM · lightingimagelightbrightnessreading

Reading a color from an image

Hello all,

I'm on the free version of Unity, so I'm faking my shadows with lightmaps (baking them to UV textures in Blender). While this approach is great for buildings and rooms, moving objects aren't shadowed by static objects, and I'd like some way to fake this. For instance: while I'm standing outside in sunlight, my viewmodel should be brightly illuminated, and while indoors, it should switch to a dimmer, more subtle light.

So I was wondering if this would be a plausible solution: have a image which represents which areas of my map should be brightly lit and which should be darker, then while my character walks around the map, read individual pixel values from this image at certain coordinates corresponding to my characters location, and use those values to change the lighting on the viewmodel? Is there a way to do this in Unity?

I'm going for the type of effect seen in CounterStrike 1.6, which doesn't have dynamic lighting on viewmodels, but dims weapons when you're standing in the shade.

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
Best Answer

Answer by Mike 3 · May 08, 2010 at 12:37 AM

yourTexture.GetPixel(x, y); http://unity3d.com/support/documentation/ScriptReference/Texture2D.GetPixel.html

also useful is GetPixelBilinear, which grabs a pixel using 0-1 normalized values for x and y: http://unity3d.com/support/documentation/ScriptReference/Texture2D.GetPixelBilinear.html

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 ZhanRnL · May 08, 2010 at 12:43 AM 0
Share

So I just need to create a Texture2D variable in a script on my character GameObject, load an image to the Texture2D, and call GetPixel?

avatar image
3

Answer by Eric5h5 · May 08, 2010 at 01:22 AM

You can use raycasting down from the character's position to get the color of the lightmap texture at that point. This (somewhat old, hopefully it still works) example makes the ball shadowed or not as you shoot it around the room and it goes in and out of the lightmap shadows.

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

No one has followed this question yet.

Related Questions

floor lighting and item lighting is unbalanced 0 Answers

Adjust Brightness Screen 3 Answers

Unity face lighting face issue: Making lit faces darker and unlit faces brighter 0 Answers

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

What is global illumination and how is it used? 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