#How can I swap colors in a shader?

6 messages · Page 1 of 1 (latest)

worthy frigate
#

This tutorial is great all the way through but at minute it describes masking techniques that might come in handy
https://youtu.be/nyFzPaWAzeQ?feature=shared

Hello Godotneers! Have you ever wanted to use shaders in your game but found that they are some sort of black magic? In this video we're going to to explore how shaders work in Godot and how to write shaders both in Godot's visual shader editor and Godot's built-in shader language. We cover both vertex shaders and fragment shaders, so that after...

▶ Play video
pliant valve
# worthy frigate This tutorial is great all the way through but at minute it describes masking te...

This had a lot of useful info, but I'm still having trouble. I have existing shaders that work for 2D sprites, but when I go to translate them to 3D is where my problem lies, I think. Most tutorials are using shader_type canvas_item; where this shader is showing a type of spatial. And TEXTURE seems to be unavailable.

I use this is my 2D Sprite Shader:
vec4 curr_color = texture(TEXTURE,UV);

But it shows up invalid in spatial.

#

And when I try something like:

    if (curr_color == old_shadow)
    {
        COLOR = new_shadow;
    }```
It says I can't change constants. Yet this works for the `canvas_item` type.
winter coral
#

The spatial shader uses ALBEDO to set the color in the Fragment() function. It's a Vector3, so you will need to remove the alpha from the color.

{
        ALBEDO = new_shadow.rgb;
}```
winter coral
pliant valve