Changing texture main color causes lighting to be ignored?

18580-lighting.png

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.

show me ur code

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.

inst is a parent of some object ?

It's a prefab. Contains 3 submeshes, which are all the same mesh just with different materials applied: [18585-prefab.png|18585]

pls post ur full code

1 Answer

1

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

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).

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?

Hmm - I don't know why dividing doesn't work... It certainly should. Btw - divide by 256f, not 255f.

255 v 256 would make the most miniscule 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).

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 ;)

You are correct, sir! We call that "2am code" (I actually wrote it last night around 1 or 2, heh)