How to create a cycling color shader (or just color a sprite with an RGB value)

Hello! I’m completely new to monogame and XNA. I would like to learn about shaders, if that is what is required to make something that colors an entirely white image through the colors of the rainbow. Are there any good learning resources on this besides the docs? if using a shader is not required, my second question would be how to draw a sprite with an RGB color value.
Thanks!

If all you want to do is to tint a sprite with some color, you don’t need to use a shader. You can just use one of MonoGame’s builtin SpriteBatch.Draw() methods that takes a color argument, which is used as a color mask when the sprite is drawn.

Something like this:
spriteBatch.Draw(someTexture, new Rectangle(0, 0, 16, 16), Color.White);

You’ll have to change Color.White to something that cycles through the colors of the rainbow each frame. For that you’ll probably want to keep track of a hue value that increases over time, and convert that hue (& some saturation & luminance or value) to RGB. More info on color spaces can be found here:

(or a bunch of other places online.)

Welcome to the community @Luca_Fossen. You can easily tint a sprite using the Color parameter. mcmillen gave an excellent example. You can also create a timer to track when to change colors. So, in the Update method add the elapsed time sincce the last frame to a variable like this.

double timer = 0;

public override void Update(GameTime gameTime)
{
    timer += gameTime.ElapsedGameTime.TotalSeconds;
}

You can use this to time how long between color changes. Like

if (timer > someTime)
{
    // change color
    timer = 0;
}

edit
You can use Color.Lerp to smoothly transition between colors.

Thank you! I will try it out.

Thanks! Sorry for my late reply. I will try it out.

Just take this class and change h value. https://github.com/Martenfur/Monofoxe/blob/develop/Monofoxe/Monofoxe.Engine/HsvColor.cs