• 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 HalfDesign · Oct 04, 2014 at 03:10 PM · c#shadertexturelighting

If not lit, use different texture

Is there a shader or way of making it so that when a sprite is currently being lit by a light then it uses a different texture? For example you have a big 10x10 area with 1x1 black squares, when a light is shone on the squares they become pink.

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 robertbu · Oct 04, 2014 at 05:05 PM

What to recommend here is highly dependent on the larger context of your app. It is possible to do something like you describe with a shader (though you'd have to write it since I cannot think of one posted on the net that already does this), but simulating the light using distance and angle calculations may also be a solution. it all depends on the needs of your app.

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
avatar image
0

Answer by rageingnonsense · Jan 07, 2015 at 10:12 PM

In your shader, use a dot product to determine at a most basic level how much light this square is receiving. You want the dot product between the light direction and the surface normal. Something like this:

 if(dot(normalDirection, lightDirection) != 0) {
     //this area is being lit at LEAST a little, so make it red
     return half4(1, 0, 0, 1);
 } else {
     //not getting any light, make it white
     return half4(1, 1, 1, 1);
 }

The dot product will be 1 for total light exposure, and 0 for none. Values inbetween are varied levels.

This is a super crude example, but what you want to do is entirely possible if you are willing to write a custom shader.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

28 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

Related Questions

Light based texture change on material 0 Answers

How to change RGB base of material via scripting (Normal map + base RGB) ? 1 Answer

Texture showing in editor but not in game 0 Answers

Multiple Cars not working 1 Answer

Unity 1080p Video player 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges