material-maker/addons/procedural_material/paint_tool/paint.shader

28 lines
947 B
GLSL

shader_type canvas_item;
uniform sampler2D self_tex;
uniform sampler2D tex2view_tex;
uniform sampler2D brush_texture : hint_white;
uniform vec2 brush_pos = vec2(0.5, 0.5);
uniform vec2 brush_ppos = vec2(0.5, 0.5);
uniform vec2 brush_size = vec2(0.25, 0.25);
uniform float brush_strength = 1.0;
uniform vec4 brush_color = vec4(1.0, 0.0, 0.0, 1.0);
float brush(float v) {
return clamp(v / (1.0-brush_strength), 0.0, 1.0);
}
void fragment() {
vec4 t2v = texture(tex2view_tex, UV);
vec2 xy = t2v.xy;
vec2 b = brush_pos/brush_size;
vec2 bv = (brush_ppos-brush_pos)/brush_size;
vec2 p = xy/brush_size;
float x = clamp(dot(p-b, bv)/dot(bv, bv), 0.0, 1.0);
float a = 1.0-length(p-(b+x*bv));
a = brush(max(0.0, a))*brush_color.w*t2v.z;
vec4 color = brush_color*texture(brush_texture, 2.0*vec2(brush_size.y/brush_size.x, 1.0)*xy);
COLOR = vec4(mix(texture(self_tex, UV).xyz, color.xyz, a), 1.0);
}