2024-03-14 15:31:22 +01:00
|
|
|
|
2024-04-15 21:28:01 +02:00
|
|
|
function make_sculpt_run(data: material_t, matcon: material_context_t): node_shader_context_t {
|
2024-08-31 17:24:01 +02:00
|
|
|
let context_id: string = "paint";
|
|
|
|
|
|
2024-04-25 22:04:43 +02:00
|
|
|
let props: shader_context_t = {
|
2024-03-14 15:31:22 +01:00
|
|
|
name: context_id,
|
|
|
|
|
depth_write: false,
|
2024-08-31 17:24:01 +02:00
|
|
|
compare_mode: "always",
|
2024-03-14 15:31:22 +01:00
|
|
|
cull_mode: "none",
|
2024-04-25 22:04:43 +02:00
|
|
|
vertex_elements: [
|
|
|
|
|
{
|
|
|
|
|
name: "pos",
|
|
|
|
|
data: "float2"
|
|
|
|
|
}
|
|
|
|
|
],
|
2024-08-31 17:24:01 +02:00
|
|
|
color_attachments: [
|
|
|
|
|
"RGBA32",
|
|
|
|
|
"RGBA32",
|
|
|
|
|
"RGBA32",
|
|
|
|
|
"R8"
|
|
|
|
|
]
|
2024-04-25 22:04:43 +02:00
|
|
|
};
|
2024-08-31 17:24:01 +02:00
|
|
|
let con_paint: node_shader_context_t = node_shader_context_create(data, props);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
con_paint.data.color_writes_red = [true, true, true, true];
|
|
|
|
|
con_paint.data.color_writes_green = [true, true, true, true];
|
|
|
|
|
con_paint.data.color_writes_blue = [true, true, true, true];
|
|
|
|
|
con_paint.data.color_writes_alpha = [true, true, true, true];
|
|
|
|
|
con_paint.allow_vcols = mesh_data_get_vertex_array(context_raw.paint_object.data, "col") != null;
|
|
|
|
|
|
2025-04-02 22:52:04 +02:00
|
|
|
let kong: node_shader_t = node_shader_context_make_kong(con_paint);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-11-09 11:31:18 +01:00
|
|
|
let decal: bool = context_is_decal();
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-03 21:29:51 +02:00
|
|
|
node_shader_add_out(kong, "tex_coord: float2");
|
2025-04-10 15:40:40 +02:00
|
|
|
node_shader_write_vert(kong, "var madd: float2 = float2(0.5, 0.5);");
|
2025-04-04 23:38:01 +02:00
|
|
|
node_shader_write_vert(kong, "output.tex_coord = input.pos.xy * madd + madd;");
|
|
|
|
|
node_shader_write_vert(kong, "output.tex_coord.y = 1.0 - output.tex_coord.y;");
|
|
|
|
|
node_shader_write_vert(kong, "output.pos = float4(input.pos.xy, 0.0, 1.0);");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-04 23:38:01 +02:00
|
|
|
node_shader_add_constant(kong, "inp: float4", "_input_brush");
|
|
|
|
|
node_shader_add_constant(kong, "inplast: float4", "_input_brush_last");
|
|
|
|
|
node_shader_add_texture(kong, "gbufferD");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-03 21:29:51 +02:00
|
|
|
kong.frag_out = "float4[2]";
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-04 23:38:01 +02:00
|
|
|
node_shader_add_constant(kong, "brush_radius: float", "_brush_radius");
|
|
|
|
|
node_shader_add_constant(kong, "brush_opacity: float", "_brush_opacity");
|
|
|
|
|
node_shader_add_constant(kong, "brush_hardness: float", "_brush_hardness");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
if (context_raw.tool == workspace_tool_t.BRUSH ||
|
|
|
|
|
context_raw.tool == workspace_tool_t.ERASER ||
|
|
|
|
|
context_raw.tool == workspace_tool_t.CLONE ||
|
|
|
|
|
context_raw.tool == workspace_tool_t.BLUR ||
|
|
|
|
|
context_raw.tool == workspace_tool_t.SMUDGE ||
|
|
|
|
|
context_raw.tool == workspace_tool_t.PARTICLE ||
|
|
|
|
|
decal) {
|
|
|
|
|
|
2024-08-31 17:24:01 +02:00
|
|
|
let depth_reject: bool = !context_raw.xray;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-02 22:52:04 +02:00
|
|
|
make_brush_run(kong);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-04-03 21:29:51 +02:00
|
|
|
node_shader_write_frag(kong, "var basecol: float3 = float3(1.0, 1.0, 1.0);");
|
|
|
|
|
node_shader_write_frag(kong, "var opacity: float = 1.0;");
|
|
|
|
|
node_shader_write_frag(kong, "if (opacity == 0.0) { discard; }");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-04 23:38:01 +02:00
|
|
|
node_shader_write_frag(kong, "var str: float = clamp((constants.brush_radius - dist) * constants.brush_hardness * 400.0, 0.0, 1.0) * opacity;");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-04 23:38:01 +02:00
|
|
|
node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo");
|
2025-04-19 12:29:49 +02:00
|
|
|
node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, sampler_linear, input.tex_coord, 0.0);");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-03 21:29:51 +02:00
|
|
|
node_shader_write_frag(kong, "if (sample_undo.r == 0 && sample_undo.g == 0 && sample_undo.b == 0) { discard; }");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_add_function(kong, str_octahedron_wrap);
|
2025-04-04 23:38:01 +02:00
|
|
|
node_shader_add_texture(kong, "gbuffer0_undo");
|
2025-04-19 12:29:49 +02:00
|
|
|
node_shader_write_frag(kong, "var g0_undo: float2 = sample_lod(gbuffer0_undo, sampler_linear, constants.inp.xy, 0.0).rg;");
|
2025-04-03 21:29:51 +02:00
|
|
|
node_shader_write_frag(kong, "var wn: float3;");
|
2025-04-02 22:52:04 +02:00
|
|
|
node_shader_write_frag(kong, "wn.z = 1.0 - abs(g0_undo.x) - abs(g0_undo.y);");
|
2025-04-03 21:29:51 +02:00
|
|
|
// node_shader_write_frag(kong, "wn.xy = wn.z >= 0.0 ? g0_undo.xy : octahedron_wrap(g0_undo.xy);");
|
|
|
|
|
node_shader_write_frag(kong, "if (wn.z >= 0.0) { wn.xy = g0_undo.xy; } else { wn.xy = octahedron_wrap(g0_undo.xy); }");
|
|
|
|
|
node_shader_write_frag(kong, "var n: float3 = normalize(wn);");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-11 10:09:04 +02:00
|
|
|
node_shader_write_frag(kong, "output[0] = float4(sample_undo.rgb + n * 0.1 * str, 1.0);");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-04-11 10:09:04 +02:00
|
|
|
node_shader_write_frag(kong, "output[1] = float4(str, 0.0, 0.0, 1.0);");
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
parser_material_finalize(con_paint);
|
|
|
|
|
con_paint.data.shader_from_source = true;
|
2025-04-02 22:52:04 +02:00
|
|
|
gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_paint.data.vertex_shader), ADDRESS(con_paint.data.fragment_shader));
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
return con_paint;
|
|
|
|
|
}
|