#Moving Shader mask independently from Sprite

7 messages · Page 1 of 1 (latest)

potent musk
#

I am trying to achieve an effect like you can see in the gif.
After trying out a few possibilites I feel like the best way to achieve this effect is to use a shader mask on a sprite.
How can I rotate the shader independently from the sprite itself?
I am using a shader script with fragment() to set the alpha value of the masked pixels to zero. I think I could add a "uniform float amount : hint_range(0, 360);" to get the rotation angle as a parameter for the AnimationPlayer. But how can I do the rotation of the texture itself?

Or is there an easier / better way to do this?

Thanks!

potent musk
#

I have tried this:

shader_type canvas_item;
render_mode unshaded;

uniform float cutoff : hint_range(0., 1.);
uniform int angle_mask : hint_range(0, 360);
uniform sampler2D mask : hint_albedo;
const float PI = 3.14159265359;


// https://godotengine.org/qa/41400/simple-texture-rotation-shader
vec2 rotateUVmatrix(vec2 uv, vec2 pivot, float rotation)
{
    mat2 rotation_matrix=mat2(  vec2(sin(rotation),-cos(rotation)),
                                vec2(cos(rotation),sin(rotation))
                                );
    uv -= pivot;
    uv= uv*rotation_matrix;
    uv += pivot;
    return uv;
}

void fragment()
{
    vec2 rotated_uv = rotateUVmatrix(UV, vec2(0.5, 0.5), float(angle_mask)*(PI/180.));
    float value = texture(mask, rotated_uv).a;
    float alpha = step(cutoff, value);
    COLOR = vec4(COLOR.rgb, alpha);
}

But it moves both the shader mask and the sprite itself simutaneously.

small solar
#

Anyone know what a glitch where a chunk of the screen is flickering white on an otherwise correctly behaving shader means?

#

Am I doing too much inside a fragment?

jolly bramble
#

@small solar Why are you ressurecting someone elses thread about a different topic?

small solar
#

Wrong channel

#

😬