Files
armorpaint/paint/sources/nodes_material/geometry_node.c
T

126 lines
10 KiB
C
Raw Normal View History

2026-03-09 13:17:15 +01:00
#include "../global.h"
2026-04-04 21:38:20 +02:00
char *geometry_node_vector(ui_node_t *node, ui_node_socket_t *socket) {
if (socket == node->outputs->buffer[0]) { // Position
parser_material_kong->frag_wposition = true;
return "input.wposition";
}
else if (socket == node->outputs->buffer[1]) { // Normal
parser_material_kong->frag_n = true;
return "n";
}
else if (socket == node->outputs->buffer[2]) { // Tangent
parser_material_kong->frag_wtangent = true;
return "input.wtangent";
}
else if (socket == node->outputs->buffer[3]) { // Incoming
parser_material_kong->frag_vvec = true;
return "vvec";
}
else { // Parametric
parser_material_kong->frag_mposition = true;
return "input.mposition";
}
}
char *geometry_node_value(ui_node_t *node, ui_node_socket_t *socket) {
if (socket == node->outputs->buffer[5]) { // Pointiness
f32 strength = 1.0;
f32 radius = 1.0;
f32 offset = 0.0;
char *store = parser_material_store_var_name(node);
parser_material_kong->frag_n = true;
parser_material_write(parser_material_kong, string("var %s_dx: float3 = ddx3(n);", store));
parser_material_write(parser_material_kong, string("var %s_dy: float3 = ddy3(n);", store));
parser_material_write(parser_material_kong,
string("var %s_curvature: float = max(dot(%s_dx, %s_dx), dot(%s_dy, %s_dy));", store, store, store, store, store));
parser_material_write(parser_material_kong, string("%s_curvature = clamp(pow(%s_curvature, (1.0 / %s) * 0.25) * %s * 2.0 + %s / 10.0, 0.0, 1.0);",
store, store, f32_to_string(radius), f32_to_string(strength), f32_to_string(offset)));
return string("%s_curvature", store);
}
return "";
}
2026-03-06 12:56:38 +01:00
void geometry_node_init() {
2026-03-31 18:47:10 +02:00
2026-04-05 16:09:00 +02:00
ui_node_t *geometry_node_def = GC_ALLOC_INIT(ui_node_t, {.id = 0,
.name = _tr("Geometry"),
.type = "NEW_GEOMETRY",
.x = 0,
.y = 0,
.color = 0xffb34f5a,
.inputs = any_array_create_from_raw((void *[]){}, 0),
.outputs = any_array_create_from_raw(
(void *[]){
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Position"),
.type = "VECTOR",
.color = 0xff6363c7,
.default_value = f32_array_create_xyz(0.0, 0.0, 0.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Normal"),
.type = "VECTOR",
.color = 0xff6363c7,
.default_value = f32_array_create_xyz(0.0, 0.0, 0.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Tangent"),
.type = "VECTOR",
.color = 0xff6363c7,
.default_value = f32_array_create_xyz(0.0, 0.0, 0.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Incoming"),
.type = "VECTOR",
.color = 0xff6363c7,
.default_value = f32_array_create_xyz(0.0, 0.0, 0.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Parametric"),
.type = "VECTOR",
.color = 0xff6363c7,
.default_value = f32_array_create_xyz(0.0, 0.0, 0.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
.node_id = 0,
.name = _tr("Pointiness"),
.type = "VALUE",
.color = 0xffa1a1a1,
.default_value = f32_array_create_x(0.0),
.min = 0.0,
.max = 1.0,
.precision = 100,
.display = 0}),
},
6),
.buttons = any_array_create_from_raw((void *[]){}, 0),
.width = 0,
.flags = 0});
2026-03-31 18:47:10 +02:00
2026-03-06 12:56:38 +01:00
any_array_push(nodes_material_input, geometry_node_def);
any_map_set(parser_material_node_vectors, "NEW_GEOMETRY", geometry_node_vector);
any_map_set(parser_material_node_values, "NEW_GEOMETRY", geometry_node_value);
}