#Blending a colour over a scene

1 messages · Page 1 of 1 (latest)

ashen light
#

Hello!
I am trying to overlay a coloured polygon 2D onto a scene (pic 1), for stylistic purposes.
I want the overlay effect to be similar to having a directional light 2D affecting the whole scene (pic 2)
however, simply setting blend mode to Add does not seem to be enough, and a lot of colours end up very washed out by the polygon (pic 3)
Any tips on how i can have it preserve the colours better?
This will probably involve some shader shenanigans, but I am ready to take those on.
Thanks in advance for your help :)

tropic zenith
#

Hi! So you want to mimic how DirectionalLight works but with a, let's say, color rect?

tough mist
ashen light
#

For now i had luck actually using blend mode multiply

#

And thru shader intensifying color by multiplying it over a constant(basically a stand-in for energy)
That seems to work alright

#

With a bit more shader tweaking, i got something like this to work:

ashen light
tropic zenith
#

sure go ahead!

ashen light
sour forge
#

That's so kewl, if you're willing to share the shader, that'd be kewl too 🙂

ashen light
#
shader_type canvas_item;
render_mode unshaded, blend_mul;

uniform sampler2D gradient_texture;
uniform float energy : hint_range(0,128) = 32.0;
uniform float angle : hint_range(0,360);
uniform float max_dist : hint_range(0,2048) = 100;
uniform int smoothing_steps : hint_range(0,8) = 2;
uniform float smoothing_range : hint_range(0,8) = 2.0;

vec4 get_gradient_color(float position) {
    return texture(gradient_texture, vec2(position, 0.5));
}

void fragment() {
    float ang_rad = angle * 3.1416 / 180.0;
    vec2 dir = vec2(sin(ang_rad),cos(ang_rad));
    vec2 dir_ort = vec2(sin(ang_rad + 1.5708),cos(ang_rad + 1.5708));

    float accum = 0.0;
    float parity = 1.0;
    for(int i = 0; i < smoothing_steps * 2 + 1; i++) {
        parity *= -1.0;
        vec2 at = screen_uv_to_sdf(SCREEN_UV) + dir_ort * float(i) * smoothing_range * parity / float(smoothing_steps + 1);
        float _accum = 0.0;
        while(_accum < max_dist) {
            float d = texture_sdf(at);
            _accum += d;
            if (d < 0.01) {
                break;
            }
            at += d * dir;
        }
        accum += _accum;
    }

    float falloff = max(0.0, min(1.0,(accum)/(max_dist * float(smoothing_steps * 2 + 1))));
    vec4 gradColor = get_gradient_color(falloff);
    vec4 tgt_col = mix(vec4(1.0,1.0,1.0,1.0), energy * gradColor, falloff);


    COLOR = tgt_col;

}```
short wedge