changing a light's colour at runtime

can anyone help me out with this? changing bgColor gives slightly the wrong colour but at least does something, changing color does nothing.
what am i missing?

okay i’ve figured out how to use RedGreenBlueLight and set the r g b brightnesses separately but now the colour is really washed out. any tips?

addBaseColor(); sets the light colour bgColor is background colour RGBAlpha this is the LED enclosure rather than the light colour.

it seems like addBaseColor is effectively creating a new light every time? can’t i just change the colour somehow

Inside addBaseColor(R, G, B); as long as the 3 values are in the range of [0, 255]

What exactly are you trying to accomplish?

ideally i’d like to be able to create a single light that i can set to any arbitrary colour at any time. if i try to use addBaseColor that way it crashes rack

1 Like

The way to do it, is to create a light with three components as Coirt shows in the example above. Then set the brightness of those three components at runtime.

There’s an example in this module. The light widget is configured with the lights, coloured red, green and blue. And these three lights are superimposed. By setting the brightness if each, you can mix the color you want on the fly.

Thanks both. This sounds like what i was doing with redgreenbluelight from the component library, but that was giving me a really washed out desaturated colour - I’ve also had trouble getting bgColor to display precisely the right colour to match other components. Not sure if you can shed any light?
Is this the “LED enclosure” adding a tint? I can’t seem to get that property (color) to have any noticeable effect, though.

Really ?::rofl:

1 Like

had to do it to em

2 Likes

bgColor is / can be a RGBA in your template for the light this->bgColor = nvgRGBA(255, 255, 255, 0); will give you a transparent colour when the lights are off, the same can be applied to this->borderColor = ... in your template.

Without seeing your source code it is hard to know what is going on exactly though.

LightWidget uses “analog modeling” of LEDs. This makes sense because if you photograph a Eurorack module, the pixel values of a light will of course not be linearly proportional to the RGB voltages given to the LED. This is due to nonlinear brightness-vs-voltage, nonexact LED colors, noncalibrated cameras/eyes, etc.

If you want an exact RGB color for whatever reason, write your own custom widget.

and this extends to the background of an unlit light?

LightWidget draws the exact bgColor. The appearance of the illuminated light is what’s physically modeled.

i see. thanks. and its “color” property is the result of that modeling, determined by the brightnesses of the individual basecolors, etc?

There’s more to it than that. The glow effect, translucency and mixing with the background color, the LIGHTER composite operation, etc.

Why do you need exact colors anyway?

I’d like the colour scheme of the lights to match the rest of the module’s colour scheme. with rbglight the colour is so desaturated you can barely distinguish yellow from green for example.
I also have knobs which light up, made by placing a transparent-centered knob over a light, and i’d like for them to appear the same as a regular knob when the light is off, but setting the light bgColor to match results in a slightly darker shade:

Maybe you could build your own ModuleLightWidget with your own colors rather than use the RedGreenBlueLight color scheme from the VCV Component Library.

Seems like i’ll have to. You said bgColor should be accurate at least though, so i’m not sure what the problem is there.