Godot Version
4.3
I have a psuedo light2d that uses gradient2d as its texture. When I try to tamper with the raw data using gradient.set_color or gradient.set_offset it causes immense lag. I’m constantly changing the values of these to imitate a flicking light and color transition. What am I doing wrong?
Probably then unsuitable to constantly change these parameters.
Are you trying something similar to this video?: https://www.youtube.com/watch?v=lI2NYBQ0kKw
The C++ function in the engine looks like this, then the data would have to be transferred to the GPU.
void Gradient::set_colors(const Vector<Color> &p_colors) {
if (points.size() < p_colors.size()) {
is_sorted = false;
}
points.resize(p_colors.size());
for (uint32_t i = 0; i < points.size(); i++) {
points[i].color = p_colors[i];
}
emit_changed();
}
1 Like
As @alex2782 posted, changing the gradient allocates memory and “bakes” it again for quick future access. Changing it (potentially every frame?) is really inappropriate.
Maybe you could get away with defining multiple gradients ahead of time and switching between them?
Or make multiple lights and turn those on/off maybe?
1 Like
Thanks for the replies! I was able to solve my issue by doing anything but change the raw data. For the flickering light that I wanted, I just adjusted the sprite’s scale value. As for the color changes, I was able to get it done through shaders.
1 Like