Transitioning shaders between areas
Hello! I've been working on a open world RPG named Seven Stardust. I've recently been trying to improve the visual quality of my game, and part of that is shaders.
I've had an issue where my music and shaders suddenly change when switching areas and it's a bit jarring. Thankfully, I was able to make a system to blend shaders between different areas. My game does not have complex shaders, it's just a hue change.
However, because of these simple shaders, I'm able to blend Vector3 variables and pass them into my GLSL in order to change hues dynamically. Some of the code I used to get this working is below.
I hope this helps some people out with their games, and have a wonderful day!
Open Alpha Here. No download required!
i there private final Vector3 startColor = new Vector3(1f, 1f, 1f);
private final Vector3 targetColor = new Vector3(1f, 1f, 1f);
private final Vector3 activeColor = new Vector3(1f, 1f, 1f);
private float fadeTimer = 0.0f;
private final float FADE_DURATION = 1.5f;
public void update(GameScreen game) {
String mapArea = game.mapSystem.area != null ? game.mapSystem.area : "";
if (!mapArea.equals(currentArea)) {
Gdx.app.log("ShaderSystem", "Area shifted to: " + mapArea);
currentArea = mapArea;
startColor.set(activeColor);
targetColor.set(getColorByAreaName(currentArea));
fadeTimer = 0.0f;
}
if (fadeTimer < FADE_DURATION) {
fadeTimer += Gdx.graphics.getDeltaTime();
if (fadeTimer > FADE_DURATION) {
fadeTimer = FADE_DURATION;
}
float alpha = fadeTimer / FADE_DURATION;
activeColor.x = MathUtils.lerp(startColor.x, targetColor.x, alpha);
activeColor.y = MathUtils.lerp(startColor.y, targetColor.y, alpha);
activeColor.z = MathUtils.lerp(startColor.z, targetColor.z, alpha);
}
}
/* After this you can pass ActiveColor into your frag shader, Which would change
the pixels to this color. The code might not work, I kinda just pulled it out of
my shader system, but that's the general gist of blending. */