2020-10-15 08:47:55 +02:00
|
|
|
shader_type canvas_item;
|
|
|
|
render_mode blend_disabled, unshaded;
|
|
|
|
|
|
|
|
uniform sampler2D tex2view_tex;
|
|
|
|
uniform sampler2D seams : hint_white;
|
2020-11-14 21:36:21 +01:00
|
|
|
uniform float seams_multiplier = 0.0625;
|
2020-11-03 06:08:02 +01:00
|
|
|
uniform sampler2D mesh_normal_tex;
|
2020-11-14 21:36:21 +01:00
|
|
|
uniform sampler2D layer_albedo_tex;
|
|
|
|
uniform sampler2D layer_mr_tex;
|
|
|
|
uniform sampler2D layer_emission_tex;
|
|
|
|
uniform sampler2D layer_depth_tex;
|
2020-10-15 08:47:55 +02:00
|
|
|
|
2020-10-19 23:13:45 +02:00
|
|
|
uniform bool erase = false;
|
2020-11-01 22:52:21 +01:00
|
|
|
uniform bool fill = false;
|
2020-10-24 12:43:31 +02:00
|
|
|
uniform float pressure = 1.0;
|
2020-10-15 08:47:55 +02:00
|
|
|
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);
|
2020-11-08 15:10:46 +01:00
|
|
|
uniform float brush_hardness = 0.5;
|
|
|
|
uniform float brush_opacity = 1.0;
|
|
|
|
uniform float stroke_length = 0.0;
|
|
|
|
uniform float stroke_angle = 0.0;
|
2020-10-15 08:47:55 +02:00
|
|
|
uniform float pattern_scale = 10.0;
|
2020-10-22 07:41:38 +02:00
|
|
|
uniform float pattern_angle = 0.0;
|
2020-10-15 08:47:55 +02:00
|
|
|
|
2020-10-17 21:04:19 +02:00
|
|
|
// BEGIN_PATTERN
|
|
|
|
float brush_function(vec2 uv) {
|
2020-10-19 23:13:45 +02:00
|
|
|
return clamp(max(0.0, 1.0-length(2.0*(uv-vec2(0.5)))) / (0.5), 0.0, 1.0);
|
2020-10-17 21:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uniform sampler2D brush_texture : hint_white;
|
|
|
|
vec4 pattern_function(vec2 uv) {
|
|
|
|
return texture(brush_texture, uv);
|
2020-10-15 08:47:55 +02:00
|
|
|
}
|
2020-10-17 21:04:19 +02:00
|
|
|
// END_PATTERN
|
2020-10-15 08:47:55 +02:00
|
|
|
|
2020-11-08 15:10:46 +01:00
|
|
|
float brush(vec2 uv) {
|
|
|
|
return clamp(brush_opacity*brush_function(uv)/(1.0-brush_hardness), 0.0, 1.0);
|
|
|
|
}
|
2020-10-15 08:47:55 +02:00
|
|
|
|
|
|
|
void fragment() {
|
|
|
|
// Get UV from seams texture
|
2020-11-14 21:36:21 +01:00
|
|
|
vec2 uv = UV+(texture(seams, UV).xy-vec2(0.5))*seams_multiplier;
|
2020-10-15 08:47:55 +02:00
|
|
|
// Get View position
|
|
|
|
vec4 tex2view = texture(tex2view_tex, uv);
|
|
|
|
vec2 xy = tex2view.xy;
|
|
|
|
// Get distance to brush center
|
|
|
|
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);
|
|
|
|
// Get position in brush
|
|
|
|
vec2 local_uv = p-(b+x*bv);
|
2020-10-19 23:13:45 +02:00
|
|
|
|
2020-10-22 07:41:38 +02:00
|
|
|
mat2 texture_rotation = mat2(vec2(cos(pattern_angle), sin(pattern_angle)), vec2(-sin(pattern_angle), cos(pattern_angle)));
|
2020-10-19 23:13:45 +02:00
|
|
|
vec2 pattern_uv = pattern_scale*texture_rotation*(vec2(brush_size.y/brush_size.x, 1.0)*(xy - vec2(0.5, 0.5)));
|
|
|
|
vec4 color = pattern_function(fract(pattern_uv));
|
2020-11-01 22:52:21 +01:00
|
|
|
|
2020-11-08 15:10:46 +01:00
|
|
|
float a = fill ? 1.0 : brush(0.5*local_uv+vec2(0.5))*color.a*tex2view.z;
|
2020-11-01 22:52:21 +01:00
|
|
|
|
2020-10-15 08:47:55 +02:00
|
|
|
vec4 screen_color = texture(SCREEN_TEXTURE, UV);
|
|
|
|
if (erase) {
|
|
|
|
COLOR = vec4(screen_color.xyz, max(screen_color.a-a, 0.0));
|
|
|
|
} else {
|
|
|
|
float alpha_sum = min(1.0, a + screen_color.a);
|
2020-10-19 23:13:45 +02:00
|
|
|
COLOR = vec4((color.xyz*a+screen_color.xyz*(vec3(alpha_sum)-a))/alpha_sum, alpha_sum);
|
2020-11-14 21:36:21 +01:00
|
|
|
//COLOR=vec4(vec3(texture(seams, UV).y), 1.0);
|
2020-10-15 08:47:55 +02:00
|
|
|
}
|
|
|
|
}
|