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 Draco18s · Nov 27, 2013 at 05:00 AM · lightingshaderscolors

Changing texture main color causes lighting to be ignored?

alt text

The dice at the bottom were dragged into the scene manually, the dice at the top were spawned and re-tinted via code (to the same values that the prefab has by default).

Why is lightning being ignored?

For reference, I'm using default diffuse shaders.

Code:

 //for ease of reading, the prefab switch statement has been omitted
 inst = Instantiate(colorizedPrefabd10,pos,Quaternion.identity) as GameObject;

 Renderer[] renders = inst.GetComponentsInChildren<Renderer>();
 int i = 0;
 foreach(Renderer r in renders) {
     if(Size >= 8) {
         switch(i) {
             case 0:
                 r.material.color = numberColor;//numbers (transparent diffuse)
                 break;
             case 1:
                 r.material.color = overlayColor;//overlay (transparent diffuse)
                 break;
             case 2:
                 r.material.color = baseColor;//underlay (diffuse)
                 break;
             default:
                 break;
         }
     }
 }
 //after this it's the d4 and d6 else-blocks, then adding random force and torque.

If I comment out the r.material.color lines, the lighting remains normal, but I don't get the user-defined colors.

lighting.png (231.3 kB)
Comment
Add comment · Show 8
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 Moor · Nov 27, 2013 at 05:07 AM 0
Share

show me ur code

avatar image Draco18s · Nov 27, 2013 at 05:18 AM 0
Share

Oops, sorry. Edited and added it. It's really nothing special. material.color = theNewColor; Commenting it out causes the problem to not occur, but also doesn't allow for the customization feature.

avatar image Moor · Nov 27, 2013 at 05:33 AM 0
Share

inst is a parent of some object ?

avatar image Draco18s · Nov 27, 2013 at 05:50 AM 0
Share

It's a prefab. Contains 3 submeshes, which are all the same mesh just with different materials applied: alt text

prefab.png (60.2 kB)
avatar image Moor · Nov 27, 2013 at 06:02 AM 0
Share

pls post ur full code

Show more comments

1 Reply

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

Answer by ArkaneX · Nov 27, 2013 at 04:17 PM

Just browsed again through your code and got the answer :)

Color is a class having argb values in a 0-1 range (float), and you initialize it using values in 0-255 range. This results in white color (all values are treated as 1).

Comment
Add comment · Show 6 · 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 Draco18s · Nov 27, 2013 at 04:26 PM 0
Share

Nope, no effect! :D Even pure white colors shouldn't cause a FULL BRIGHT effect. :|

Edit:

Dividing the existing values by 255 produced no change, but manually changing (191F/255F) to (0.75F) did. Da fuk?

avatar image ArkaneX · Nov 27, 2013 at 04:46 PM 0
Share

Hmm - I don't know why dividing doesn't work... It certainly should.

Btw - divide by 256f, not 255f.

avatar image Draco18s · Nov 27, 2013 at 04:52 PM 0
Share

255 v 256 would make the most $$anonymous$$iscule of differences. But yeah, it was weird. I just went "whatever" and left it alone with the floating point values.

(Also, if the maximum red on the 0-255 scale is 255, then that is equal to 1 on the 0-1 scale, ergo, divide by 255).

avatar image ArkaneX · Nov 27, 2013 at 04:56 PM 0
Share

Whoops - you're right of course. But then you need to change your code, because when you retrieve color values from PlayerPrefs, you divide by 256 ;)

avatar image Draco18s · Nov 27, 2013 at 05:00 PM 0
Share

You are correct, sir! We call that "2am code"

(I actually wrote it last night around 1 or 2, heh)

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

18 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

Related Questions

Lighting works for iPad but not iPhone? 0 Answers

Help Turning Sprites into 3D Objects and Casting Shadows 1 Answer

How to send an array of positions to a shader. 0 Answers

[Shader] No Fog on Particles/Standard Unlit 0 Answers

How to get 2d lighting data in shadergraph? 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