2026-03-09 13:17:15 +01:00
|
|
|
|
2026-06-04 11:00:05 +02:00
|
|
|
#include "../global.h"
|
2026-03-09 13:17:15 +01:00
|
|
|
|
2026-04-21 10:52:27 +02:00
|
|
|
char *str_get_smudge_tool_weight = "\
|
2026-04-01 21:10:04 +02:00
|
|
|
fun get_smudge_tool_weight(i: int): float { \
|
|
|
|
|
if (i == 0) { return 1.0 / 28.0; } \
|
|
|
|
|
if (i == 1) { return 2.0 / 28.0; } \
|
|
|
|
|
if (i == 2) { return 3.0 / 28.0; } \
|
|
|
|
|
if (i == 3) { return 4.0 / 28.0; } \
|
|
|
|
|
if (i == 4) { return 5.0 / 28.0; } \
|
|
|
|
|
if (i == 5) { return 6.0 / 28.0; } \
|
|
|
|
|
return 7.0 / 28.0; \
|
|
|
|
|
} \
|
|
|
|
|
";
|
|
|
|
|
|
2026-04-21 10:52:27 +02:00
|
|
|
char *str_get_blur_tool_weight = "\
|
2026-04-01 21:10:04 +02:00
|
|
|
fun get_blur_tool_weight(i: int): float { \
|
|
|
|
|
if (i == 0) { return 0.034619 / 2.0; } \
|
|
|
|
|
if (i == 1) { return 0.044859 / 2.0; } \
|
|
|
|
|
if (i == 2) { return 0.055857 / 2.0; } \
|
|
|
|
|
if (i == 3) { return 0.066833 / 2.0; } \
|
|
|
|
|
if (i == 4) { return 0.076841 / 2.0; } \
|
|
|
|
|
if (i == 5) { return 0.084894 / 2.0; } \
|
|
|
|
|
if (i == 6) { return 0.090126 / 2.0; } \
|
|
|
|
|
if (i == 7) { return 0.09194 / 2.0; } \
|
|
|
|
|
if (i == 8) { return 0.090126 / 2.0; } \
|
|
|
|
|
if (i == 9) { return 0.084894 / 2.0; } \
|
|
|
|
|
if (i == 10) { return 0.076841 / 2.0; } \
|
|
|
|
|
if (i == 11) { return 0.066833 / 2.0; } \
|
|
|
|
|
if (i == 12) { return 0.055857 / 2.0; } \
|
|
|
|
|
if (i == 13) { return 0.044859 / 2.0; } \
|
|
|
|
|
return 0.034619 / 2.0; \
|
|
|
|
|
} \
|
|
|
|
|
";
|
|
|
|
|
|
2026-03-06 12:56:38 +01:00
|
|
|
void make_blur_run(node_shader_t *kong) {
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "var basecol: float3 = float3(0.0, 0.0, 0.0);");
|
|
|
|
|
node_shader_write_frag(kong, "var roughness: float = 0.0;");
|
|
|
|
|
node_shader_write_frag(kong, "var metallic: float = 0.0;");
|
|
|
|
|
node_shader_write_frag(kong, "var occlusion: float = 0.0;");
|
|
|
|
|
node_shader_write_frag(kong, "var nortan: float3 = float3(0.0, 0.0, 0.0);");
|
|
|
|
|
node_shader_write_frag(kong, "var height: float = 0.0;");
|
|
|
|
|
node_shader_write_frag(kong, "var mat_opacity: float = 1.0;");
|
2026-04-05 16:41:00 +02:00
|
|
|
bool is_mask = slot_layer_is_mask(g_context->layer);
|
2024-03-14 15:31:22 +01:00
|
|
|
if (is_mask) {
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "var opacity: float = 1.0;");
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "var opacity: float = 0.0;");
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2026-04-05 16:41:00 +02:00
|
|
|
if (g_context->material->paint_emis) {
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "var emis: float = 0.0;");
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2026-04-05 16:41:00 +02:00
|
|
|
if (g_context->material->paint_subs) {
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "var subs: float = 0.0;");
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2026-05-14 11:24:04 +02:00
|
|
|
if (g_context->blur_type == BLUR_TYPE_SMUDGE) {
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_add_function(kong, str_get_smudge_tool_weight);
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong, "var smudge_delta: float2 = constants.inp.xy - constants.inplast.xy;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "for (var i: int = 0; i < 7; i += 1) {");
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong, "var smudge_sp: float2 = sp.xy - smudge_delta * ((float(i) + 1.0) / 7.0);");
|
|
|
|
|
node_shader_write_frag(kong, "smudge_sp = float2(clamp(smudge_sp.x, 0.0, 0.9999), clamp(smudge_sp.y, 0.0, 0.9999));");
|
|
|
|
|
node_shader_write_frag(kong, "var tex_coord_inp24: float4 = gbuffer2[uint2(uint(smudge_sp.x * constants.gbuffer_size.x), uint(smudge_sp.y * "
|
|
|
|
|
"constants.gbuffer_size.y))];");
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_write_frag(kong, "var tex_coord_inp2: float2 = tex_coord_inp24.ba;");
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_ref, sampler_linear, tex_coord_inp2);");
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_write_frag(kong, "var blur_weight_i: float = get_smudge_tool_weight(i);");
|
|
|
|
|
node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight_i;");
|
2026-04-15 12:11:27 +02:00
|
|
|
node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * texpaint_sample.a * blur_weight_i;");
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_ref, sampler_linear, tex_coord_inp2) * blur_weight_i;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "roughness += texpaint_pack_sample.g;");
|
|
|
|
|
node_shader_write_frag(kong, "metallic += texpaint_pack_sample.b;");
|
|
|
|
|
node_shader_write_frag(kong, "occlusion += texpaint_pack_sample.r;");
|
|
|
|
|
node_shader_write_frag(kong, "height += texpaint_pack_sample.a;");
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong, "nortan += sample(texpaint_nor_ref, sampler_linear, tex_coord_inp2).rgb * blur_weight_i;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "}");
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong,
|
|
|
|
|
"var tex_coord_inp4: float4 = gbuffer2[uint2(uint(sp.x * constants.gbuffer_size.x), uint(sp.y * constants.gbuffer_size.y))];");
|
|
|
|
|
node_shader_write_frag(kong, "var tex_coord_inp: float2 = tex_coord_inp4.ba;");
|
|
|
|
|
node_shader_add_constant(kong, "texpaint_size: float2", "_texpaint_size");
|
|
|
|
|
node_shader_write_frag(kong, "var blur_step: float = 1.0 / constants.texpaint_size.x;");
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_add_function(kong, str_get_blur_tool_weight);
|
2024-03-14 15:31:22 +01:00
|
|
|
// X
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_write_frag(kong, "for (var i: int = 0; i <= 14; i += 1) {");
|
2025-10-15 18:39:55 +02:00
|
|
|
node_shader_write_frag(kong,
|
2026-08-23 18:57:24 +02:00
|
|
|
"var texpaint_sample: float4 = sample(texpaint_ref, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0));");
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_write_frag(kong, "var blur_weight_i: float = get_blur_tool_weight(i);");
|
|
|
|
|
node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight_i;");
|
2026-04-15 12:11:27 +02:00
|
|
|
node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * texpaint_sample.a * blur_weight_i;");
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_ref, sampler_linear, tex_coord_inp + float2(blur_step * float(i "
|
2026-03-06 12:56:38 +01:00
|
|
|
"- 7), 0.0)) * blur_weight_i;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "roughness += texpaint_pack_sample.g;");
|
|
|
|
|
node_shader_write_frag(kong, "metallic += texpaint_pack_sample.b;");
|
|
|
|
|
node_shader_write_frag(kong, "occlusion += texpaint_pack_sample.r;");
|
|
|
|
|
node_shader_write_frag(kong, "height += texpaint_pack_sample.a;");
|
2025-10-15 18:39:55 +02:00
|
|
|
node_shader_write_frag(
|
2026-08-23 18:57:24 +02:00
|
|
|
kong, "nortan += sample(texpaint_nor_ref, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0)).rgb * blur_weight_i;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "}");
|
2024-03-14 15:31:22 +01:00
|
|
|
// Y
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_write_frag(kong, "for (var j: int = 0; j <= 14; j += 1) {");
|
2025-10-15 18:39:55 +02:00
|
|
|
node_shader_write_frag(kong,
|
2026-08-23 18:57:24 +02:00
|
|
|
"var texpaint_sample: float4 = sample(texpaint_ref, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7)));");
|
2025-07-13 19:06:59 +02:00
|
|
|
node_shader_write_frag(kong, "var blur_weight_j: float = get_blur_tool_weight(j);");
|
|
|
|
|
node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight_j;");
|
2026-04-15 12:11:27 +02:00
|
|
|
node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * texpaint_sample.a * blur_weight_j;");
|
2026-08-23 18:57:24 +02:00
|
|
|
node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_ref, sampler_linear, tex_coord_inp + float2(0.0, blur_step * "
|
2026-03-06 12:56:38 +01:00
|
|
|
"float(j - 7))) * blur_weight_j;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "roughness += texpaint_pack_sample.g;");
|
|
|
|
|
node_shader_write_frag(kong, "metallic += texpaint_pack_sample.b;");
|
|
|
|
|
node_shader_write_frag(kong, "occlusion += texpaint_pack_sample.r;");
|
|
|
|
|
node_shader_write_frag(kong, "height += texpaint_pack_sample.a;");
|
2025-10-15 18:39:55 +02:00
|
|
|
node_shader_write_frag(
|
2026-08-23 18:57:24 +02:00
|
|
|
kong, "nortan += sample(texpaint_nor_ref, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7))).rgb * blur_weight_j;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "}");
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2026-04-15 12:11:27 +02:00
|
|
|
node_shader_write_frag(kong, "var blur_src_alpha: float = opacity;");
|
2025-07-12 21:23:44 +02:00
|
|
|
node_shader_write_frag(kong, "opacity *= constants.brush_opacity;");
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|