Files
armorpaint/paint/sources/render/make_brush.c
T

90 lines
4.4 KiB
C
Raw Normal View History

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-03-06 12:56:38 +01:00
void make_brush_run(node_shader_t *kong) {
2024-03-14 15:31:22 +01:00
2025-04-02 22:52:04 +02:00
node_shader_write_frag(kong, "var dist: float = 0.0;");
2024-03-14 15:31:22 +01:00
2026-04-05 16:41:00 +02:00
if (g_context->tool == TOOL_TYPE_PARTICLE) {
2024-03-20 16:13:54 +01:00
return;
}
2024-03-14 15:31:22 +01:00
2026-05-13 17:11:52 +02:00
bool fill_layer = g_context->layer->fill_material != NULL;
2026-03-06 12:56:38 +01:00
bool decal = context_is_decal();
2024-03-20 16:13:54 +01:00
if (decal && !fill_layer) {
2025-04-21 19:36:51 +02:00
node_shader_write_frag(kong, "if (constants.decal_mask.z > 0.0) {");
2024-03-20 16:13:54 +01:00
}
2024-03-14 15:31:22 +01:00
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "var depth: float = sample_lod(gbufferD, sampler_linear, constants.inp.xy, 0.0).r;");
node_shader_add_constant(kong, "invVP: float4x4", "_inv_view_proj_matrix");
2025-09-20 22:13:46 +02:00
node_shader_write_frag(kong, "var winp: float4 = float4(float2(constants.inp.x, 1.0 - constants.inp.y) * 2.0 - 1.0, depth, 1.0);");
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "winp = constants.invVP * winp;");
node_shader_write_frag(kong, "winp.xyz = winp.xyz / winp.w;");
2026-03-06 12:56:38 +01:00
kong->frag_wposition = true;
2025-09-16 20:44:07 +02:00
2026-04-05 16:41:00 +02:00
if (g_config->brush_angle_reject || g_context->xray) {
2025-09-16 20:44:07 +02:00
node_shader_add_function(kong, str_octahedron_wrap);
2026-03-07 21:12:59 +01:00
node_shader_add_texture(kong, "gbuffer0", NULL);
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "var g0: float2 = sample_lod(gbuffer0, sampler_linear, constants.inp.xy, 0.0).rg;");
node_shader_write_frag(kong, "var wn: float3;");
node_shader_write_frag(kong, "wn.z = 1.0 - abs(g0.x) - abs(g0.y);");
// node_shader_write_frag(kong, "wn.xy = wn.z >= 0.0 ? g0.xy : octahedron_wrap(g0.xy);");
2025-10-15 18:39:55 +02:00
node_shader_write_frag(kong,
"if (wn.z >= 0.0) { wn.x = g0.x; wn.y = g0.y; } else { var f2: float2 = octahedron_wrap(g0.xy); wn.x = f2.x; wn.y = f2.y; }");
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "wn = normalize(wn);");
node_shader_write_frag(kong, "var plane_dist: float = dot(wn, winp.xyz - input.wposition);");
if (g_config->brush_angle_reject && !g_context->xray && !make_material_transluc_used) {
2025-09-16 20:44:07 +02:00
// constants.inp.w = paint2d ? 0.0 : 1.0
2026-03-30 18:28:28 +02:00
node_shader_write_frag(kong, "if (plane_dist < -0.03 && constants.inp.w == 0.0) { discard; }");
2026-03-06 12:56:38 +01:00
kong->frag_n = true;
2026-04-05 16:41:00 +02:00
f32 angle = g_context->brush_angle_reject_dot;
2026-08-21 22:35:41 +02:00
node_shader_write_frag(kong, string_tmp("if (dot(wn, n) < %s && constants.inp.w == 0.0) { discard; }", f32_to_string(angle)));
2024-03-14 15:31:22 +01:00
}
2025-09-16 20:44:07 +02:00
}
2024-03-14 15:31:22 +01:00
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, sampler_linear, constants.inplast.xy, 0.0).r;");
2024-03-14 15:31:22 +01:00
2025-09-20 22:13:46 +02:00
node_shader_write_frag(kong, "var winplast: float4 = float4(float2(constants.inplast.x, 1.0 - constants.inplast.y) * 2.0 - 1.0, depthlast, 1.0);");
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "winplast = constants.invVP * winplast;");
node_shader_write_frag(kong, "winplast.xyz = winplast.xyz / winplast.w;");
2024-03-14 15:31:22 +01:00
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "var pa: float3 = input.wposition - winp.xyz;");
2026-04-05 16:41:00 +02:00
if (g_context->xray) {
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "pa += wn * float3(plane_dist, plane_dist, plane_dist);");
2024-03-14 15:31:22 +01:00
}
2025-09-16 20:44:07 +02:00
node_shader_write_frag(kong, "var ba: float3 = winplast.xyz - winp.xyz;");
2025-04-02 22:52:04 +02:00
2026-07-11 22:58:31 +02:00
node_shader_add_constant(kong, "VP: float4x4", "_view_proj_matrix");
node_shader_add_constant(kong, "camera_up: float3", "_camera_up");
node_shader_add_constant(kong, "aspect_ratio: float", "_aspect_ratio_window");
node_shader_add_constant(kong, "camera_align: float", "_brush_camera_align");
node_shader_write_frag(kong, "if (constants.camera_align > 0.0) {");
node_shader_write_frag(kong, "var vp_up_y: float = (constants.VP * float4(constants.camera_up, 0.0)).y;");
node_shader_write_frag(kong, "var ca_scale: float = (1.0 / winp.w) / (vp_up_y * constants.brush_radius);");
node_shader_write_frag(kong, "var sa: float2 = sp.xy - constants.inp.xy;");
node_shader_write_frag(kong, "sa.x *= constants.aspect_ratio;");
node_shader_write_frag(kong, "sa = sa * ca_scale;");
// Capsule
node_shader_write_frag(kong, "var sb: float2 = constants.inplast.xy - constants.inp.xy;");
node_shader_write_frag(kong, "sb.x *= constants.aspect_ratio;");
node_shader_write_frag(kong, "sb = sb * ca_scale;");
node_shader_write_frag(kong, "var sh: float = clamp(dot(sa, sb) / dot(sb, sb), 0.0, 1.0);");
node_shader_write_frag(kong, "dist = length(sa - sb * sh) * 2.0 * constants.brush_radius;");
node_shader_write_frag(kong, "}");
node_shader_write_frag(kong, "else {");
// Capsule
node_shader_write_frag(kong, "var h: float = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);");
node_shader_write_frag(kong, "dist = length(pa - ba * h);");
node_shader_write_frag(kong, "}");
2024-03-14 15:31:22 +01:00
2025-04-05 22:22:43 +02:00
node_shader_write_frag(kong, "if (dist > constants.brush_radius) { discard; }");
2024-03-14 15:31:22 +01:00
2024-03-20 16:13:54 +01:00
if (decal && !fill_layer) {
2025-04-02 22:52:04 +02:00
node_shader_write_frag(kong, "}");
2024-03-20 16:13:54 +01:00
}
2024-03-14 15:31:22 +01:00
}