42 lines
2.0 KiB
Plaintext
42 lines
2.0 KiB
Plaintext
shader_type spatial;
|
|
render_mode blend_mix, cull_back, diffuse_burley, specular_schlick_ggx;
|
|
|
|
// --- Parameters -------------------------------------------------------
|
|
// Solid tint colors, one per vertex-color channel (R, G, B).
|
|
uniform vec3 color_red : source_color = vec3(1.0, 0.0, 0.0);
|
|
uniform vec3 color_green : source_color = vec3(0.0, 1.0, 0.0);
|
|
uniform vec3 color_blue : source_color = vec3(0.0, 0.0, 1.0);
|
|
|
|
// The brush texture. Its R/G/B channels each hold a different brush-stroke
|
|
// variation, used purely as an alpha/shape mask (not as color).
|
|
uniform sampler2D pattern_texture : hint_default_black, repeat_enable, filter_linear_mipmap;
|
|
|
|
// How many times the brush pattern repeats over the mesh UVs.
|
|
uniform vec2 pattern_tiling = vec2(1.0, 1.0);
|
|
|
|
// --- Hard region selection ---------------------------------------------
|
|
// Vertex color picks the region on/off (assumes verts are painted with
|
|
// clean, mostly-pure R/G/B — not blended mixes). Threshold decides how
|
|
// strong a channel needs to be to count as "painted", smoothness gives
|
|
// a tiny anti-aliased edge instead of a jagged one.
|
|
uniform float region_threshold : hint_range(0.0, 1.0) = 0.5;
|
|
uniform float region_smoothness : hint_range(0.0, 0.5) = 0.05;
|
|
|
|
void fragment() {
|
|
vec4 tex = texture(pattern_texture, UV * pattern_tiling);
|
|
|
|
// Hard (but lightly smoothed) on/off mask per channel from vertex color.
|
|
float mask_r = smoothstep(region_threshold - region_smoothness, region_threshold + region_smoothness, COLOR.r);
|
|
float mask_g = smoothstep(region_threshold - region_smoothness, region_threshold + region_smoothness, COLOR.g);
|
|
float mask_b = smoothstep(region_threshold - region_smoothness, region_threshold + region_smoothness, COLOR.b);
|
|
|
|
// Inside each region, the matching texture channel is only the brush
|
|
// stroke's alpha/shape — the actual color comes from the tint uniform.
|
|
vec3 result =
|
|
mask_r * color_red * tex.r
|
|
+ mask_g * color_green * tex.g
|
|
+ mask_b * color_blue * tex.b;
|
|
|
|
ALBEDO = result;
|
|
}
|