From f01c48b112e054bd054c5866adcca4eac62e0116 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Tue, 30 Sep 2025 13:57:44 +0200 Subject: [PATCH] Shader fixes --- base/sources/libs/kong/backends/spirv.c | 62 +++++++++++++++++++++++++ paint/sources/parser_material.ts | 12 ++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/base/sources/libs/kong/backends/spirv.c b/base/sources/libs/kong/backends/spirv.c index 11f095aa..f1a785e8 100644 --- a/base/sources/libs/kong/backends/spirv.c +++ b/base/sources/libs/kong/backends/spirv.c @@ -264,6 +264,18 @@ typedef enum spirv_glsl_std { SPIRV_GLSL_STD_FRACT = 10, SPIRV_GLSL_STD_SIN = 13, SPIRV_GLSL_STD_COS = 14, + //// + SPIRV_GLSL_STD_TRUNC = 3, + SPIRV_GLSL_STD_FSIGN = 6, + SPIRV_GLSL_STD_RADIANS = 11, + SPIRV_GLSL_STD_DEGREES = 12, + SPIRV_GLSL_STD_TAN = 15, + SPIRV_GLSL_STD_SINH = 19, + SPIRV_GLSL_STD_COSH = 20, + SPIRV_GLSL_STD_TANH = 21, + SPIRV_GLSL_STD_EXP = 27, + SPIRV_GLSL_STD_LOG = 28, + //// SPIRV_GLSL_STD_ASIN = 16, SPIRV_GLSL_STD_ACOS = 17, SPIRV_GLSL_STD_ATAN = 18, @@ -2489,6 +2501,56 @@ static void write_function(instructions_buffer *instructions, function *f, spirv //// + else if (func == add_name("tan")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_TAN, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("log")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_LOG, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("exp")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_EXP, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("sign")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FSIGN, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("trunc")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_TRUNC, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("sinh")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_SINH, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("cosh")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_COSH, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("tanh")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_TANH, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("radians")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_RADIANS, operand); + hmput(index_map, o->op_call.var.index, id); + } + else if (func == add_name("degrees")) { + spirv_id operand = get_var(instructions, o->op_call.parameters[0]); + spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_DEGREES, operand); + hmput(index_map, o->op_call.var.index, id); + } else if (func == add_name("ddx2")) { spirv_id operand = get_var(instructions, o->op_call.parameters[0]); spirv_id id = write_op_dpdx(instructions, spirv_float2_type, operand); diff --git a/paint/sources/parser_material.ts b/paint/sources/parser_material.ts index 166626fb..c06ec222 100644 --- a/paint/sources/parser_material.ts +++ b/paint/sources/parser_material.ts @@ -1596,10 +1596,18 @@ function parser_material_parse_value(node: ui_node_t, socket: ui_node_socket_t): out_val = "max(" + val1 + ", " + val2 + ")"; } else if (op == "LESS_THAN") { - out_val = "float(" + val1 + " < " + val2 + ")"; + // out_val = "float(" + val1 + " < " + val2 + ")"; + let store: string = parser_material_store_var_name(node) + "_lessthan"; + parser_material_write(parser_material_kong, "var " + store + ": float = 0.0;"); + parser_material_write(parser_material_kong, "if (" + val1 + " < " + val2 + ") { " + store + " = 1.0; }"); + out_val = store; } else if (op == "GREATER_THAN") { - out_val = "float(" + val1 + " > " + val2 + ")"; + // out_val = "float(" + val1 + " > " + val2 + ")"; + let store: string = parser_material_store_var_name(node) + "_greaterthan"; + parser_material_write(parser_material_kong, "var " + store + ": float = 0.0;"); + parser_material_write(parser_material_kong, "if (" + val1 + " > " + val2 + ") { " + store + " = 1.0; }"); + out_val = store; } else if (op == "SIGN") { out_val = "sign(" + val1 + ")";