Changing light colour makes it too bright

Hey there.
So I’m trying to have different colour spells according to what button you press on the Razer Hydra. I have code that I think should work but obviously isn’t and I’m not sure why.
When the demo starts the light is way to bright.
If I remove the line of code in the Start() method that sets the colour, it is fine and has the right range and intensity that I want. However if I add this code in or change the light colour by a button press, it gets messed up and too bright.

Here is a picture example with the code to see also.

alt text

Thanks for any help with this

3 Answers

3

Try to set alpha value

private color PhysicsSpell = new Color(23,118,186,alpha);

or change the intensity

@eran0201 That didn't work. Intensity already changed as you can see in the code. Any other ideas?

–

This code works for me, if I mimick it in a small use case that is:

using UnityEngine;


public class tmp : MonoBehaviour
{
    [SerializeField]
    Color c = Color.white;
    [SerializeField]
    float i = 0.25f;

    void Start()
    {
        //Light light = GetComponent<Light>();
        light.color = c;
        light.intensity = i;
        light.range = 3;
    }
}

I changed the color in the inspector to various things and it all turned out correctly.

Two things I would like to tell you

Light is multiplicative, if you have a light source that is 100% blue (so new Color(0,0,255):wink: and put it in a scene that has the default material, everything is blue. But if you create a new material and make the color red (255,0,0) everything will be black. This is because blue * red = black, red contains no blue so blue light only shows the blue part, which is zero. (0255, 00, 255*0) = (0,0,0)

So in short: I think your light color mismatches with your material color making some objects appear correct and other over-bright.

Tips: Make your light look right when the light is white, desaturate your textures so colored lights can influence the world with whaterver color they have and possibly desaturate the lights either way. Colors look bright in comparison to their surrounding, if something is only a little red in a grey world it will still look very red so don’t worry about your world becoming too flat - as long as the contrast is right.

Additionally (if you have pro) you can solve the boring-ness of colors by upgrading the saturation with a post effect.

Another, totally unrelated thing, I’d also like to recommend you to use a public or serialized field to put the light in like so (this is not related to your question at all but I just noticed it in your code):

    public class MyClass : MonoBehaviour
    {
    [SerializeField]
    Light spellLight;
/*
    void Start() etcetera
*/
    }

So you can use drag and drop in the editor instead of using gameobject.find → which will give problems when you have more than 1 object with this name, possibly one having no light source at all etcetera. Also it is faster on startup and gives better error messages (null reference on the specific property so you know the object that was in there was deleted or has not been filled in etcetera).

that's an interesting problem, I don't know why this is however you could assign lightSpell in Awake or use a public property so you can edit the value in the inspector. Are you sure you didn't get an error when assigning LightSpell and then the range and intensity were never set (so probably the range was at 12, the intensity at 1, the color at default, so the light is much brighter because it is much bigger etcetera)?

–

found it! stupid for me not to see this... colors range from 0.0f to 1.0f, anything beyond is stored and used so things become ridiculously bright! if you want to use sensible values create a const float COLOR_CONVERSION = 1f / 256f;

–

@TropicalTrevor Ah thanks for that. However I'm not understanding this one thing. If I have this: SpellLight.color = Color.white; And it works, why does having SpellLight.color = LightSpell; Where LightSpell is defined at the top as this: Color LightSpell = Color.white; Not work? I understand what your saying about having to convert them but would setting them as a color not be the proper way? Also for what you said about COLOR_CONVERSION, how would I do it for this as an example? private Color FireSpell = new Color(225,113,12); Thanks

–

@TropicalTrevor thanks for that man I will have a look and see if I'm calling it somewhere else , cheers!

–

Hi, so the solution is here:

ambient light values have to be between 0 and 1, 23 for instance is not a valid value