From eb557172be724be37731778af06adf817b70405b Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 13 Jul 2025 19:06:59 +0200 Subject: [PATCH] Shader fixes --- armorpaint/assets/plugins/hello_node.js | 2 +- armorpaint/sources/make_blur.ts | 49 ++++++++++++++--------- armorpaint/sources/make_clone.ts | 5 ++- armorpaint/sources/make_colorid_picker.ts | 4 +- armorpaint/sources/make_discard.ts | 20 +++++---- armorpaint/sources/make_particle.ts | 2 +- armorsculpt/sources/make_brush.ts | 2 +- base/sources/ts/parser_material.ts | 26 ++++++------ base/sources/ts/strings.ts | 34 ++++++++++++++++ 9 files changed, 98 insertions(+), 46 deletions(-) diff --git a/armorpaint/assets/plugins/hello_node.js b/armorpaint/assets/plugins/hello_node.js index 2e14fb9c..ddbbded5 100644 --- a/armorpaint/assets/plugins/hello_node.js +++ b/armorpaint/assets/plugins/hello_node.js @@ -68,7 +68,7 @@ parser_material_custom_nodes_set(node_type, function(node, socket_name) { let my_out = "my_out"; node_shader_write_frag(kong, - "var " + my_out + ": float = cos(sin(tex_coord.x * 200.0 * " + scale + ") + cos(tex_coord.y * 200.0 * " + scale + "));" + "var " + my_out + ": float = cos(sin(input.tex_coord.x * 200.0 * " + scale + ") + cos(input.tex_coord.y * 200.0 * " + scale + "));" ); if (socket_name == "Color") { diff --git a/armorpaint/sources/make_blur.ts b/armorpaint/sources/make_blur.ts index 9f579dd6..67b86772 100644 --- a/armorpaint/sources/make_blur.ts +++ b/armorpaint/sources/make_blur.ts @@ -1,6 +1,8 @@ function make_blur_run(kong: node_shader_t) { - node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(sp.x * constants.gbuffer_size.x, sp.y * constants.gbuffer_size.y)].ba;"); + // node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(sp.x * constants.gbuffer_size.x, sp.y * constants.gbuffer_size.y)].ba;"); + 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_write_frag(kong, "var basecol: float3 = float3(0.0, 0.0, 0.0);"); node_shader_write_frag(kong, "var roughness: float = 0.0;"); @@ -26,47 +28,54 @@ function make_blur_run(kong: node_shader_t) { 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;"); if (context_raw.tool == workspace_tool_t.SMUDGE) { - node_shader_write_frag(kong, "const blur_weight: float[7] = {1.0 / 28.0, 2.0 / 28.0, 3.0 / 28.0, 4.0 / 28.0, 5.0 / 28.0, 6.0 / 28.0, 7.0 / 28.0};"); + // node_shader_write_frag(kong, "const blur_weight: float[7] = {1.0 / 28.0, 2.0 / 28.0, 3.0 / 28.0, 4.0 / 28.0, 5.0 / 28.0, 6.0 / 28.0, 7.0 / 28.0};"); + node_shader_add_function(kong, str_get_smudge_tool_weight); node_shader_add_constant(kong, "brush_direction: float3", "_brush_direction"); node_shader_write_frag(kong, "var blur_direction: float2 = constants.brush_direction.yx;"); node_shader_write_frag(kong, "for (var i: int = 0; i < 7; i += 1) {"); - node_shader_write_frag(kong, "var tex_coord_inp2: float2 = gbuffer2[uint2((sp.x + blur_direction.x * blur_step * float(i)) * constants.gbuffer_size.x, (sp.y + blur_direction.y * blur_step * float(i)) * constants.gbuffer_size.y)].ba;"); + // node_shader_write_frag(kong, "var tex_coord_inp2: float2 = gbuffer2[uint2((sp.x + blur_direction.x * blur_step * float(i)) * constants.gbuffer_size.x, (sp.y + blur_direction.y * blur_step * float(i)) * constants.gbuffer_size.y)].ba;"); + node_shader_write_frag(kong, "var tex_coord_inp24: float4 = gbuffer2[uint2(uint((sp.x + blur_direction.x * blur_step * float(i)) * constants.gbuffer_size.x), uint((sp.y + blur_direction.y * blur_step * float(i)) * constants.gbuffer_size.y))];"); + node_shader_write_frag(kong, "var tex_coord_inp2: float2 = tex_coord_inp24.ba;"); node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp2);"); - node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight[i];"); - node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight[i];"); - node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp2) * blur_weight[i];"); + 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;"); + node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight_i;"); + node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp2) * blur_weight_i;"); 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;"); - node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp2).rgb * blur_weight[i];"); + node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp2).rgb * blur_weight_i;"); node_shader_write_frag(kong, "}"); } else { - node_shader_write_frag(kong, "const blur_weight: float[15] = {0.034619 / 2.0, 0.044859 / 2.0, 0.055857 / 2.0, 0.066833 / 2.0, 0.076841 / 2.0, 0.084894 / 2.0, 0.090126 / 2.0, 0.09194 / 2.0, 0.090126 / 2.0, 0.084894 / 2.0, 0.076841 / 2.0, 0.066833 / 2.0, 0.055857 / 2.0, 0.044859 / 2.0, 0.034619 / 2.0};"); + // node_shader_write_frag(kong, "const blur_weight: float[15] = {0.034619 / 2.0, 0.044859 / 2.0, 0.055857 / 2.0, 0.066833 / 2.0, 0.076841 / 2.0, 0.084894 / 2.0, 0.090126 / 2.0, 0.09194 / 2.0, 0.090126 / 2.0, 0.084894 / 2.0, 0.076841 / 2.0, 0.066833 / 2.0, 0.055857 / 2.0, 0.044859 / 2.0, 0.034619 / 2.0};"); + node_shader_add_function(kong, str_get_blur_tool_weight); // X - node_shader_write_frag(kong, "for (var i: int = -7; i <= 7; i += 1) {"); - node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i), 0.0));"); - node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight[i + 7];"); - node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight[i + 7];"); - node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i), 0.0)) * blur_weight[i + 7];"); + node_shader_write_frag(kong, "for (var i: int = 0; i <= 14; i += 1) {"); + node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0));"); + 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;"); + node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight_i;"); + node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0)) * blur_weight_i;"); 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;"); - node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i), 0.0)).rgb * blur_weight[i + 7];"); + node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp + float2(blur_step * float(i - 7), 0.0)).rgb * blur_weight_i;"); node_shader_write_frag(kong, "}"); // Y - node_shader_write_frag(kong, "for (var j: int = -7; j <= 7; j += 1) {"); - node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j)));"); - node_shader_write_frag(kong, "opacity += texpaint_sample.a * blur_weight[j + 7];"); - node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight[j + 7];"); - node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = texture(texpaint_pack_undo, tex_coord_inp + float2(0.0, blur_step * float(j))) * blur_weight[j + 7];"); + node_shader_write_frag(kong, "for (var j: int = 0; j <= 14; j += 1) {"); + node_shader_write_frag(kong, "var texpaint_sample: float4 = sample(texpaint_undo, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7)));"); + 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;"); + node_shader_write_frag(kong, "basecol += texpaint_sample.rgb * blur_weight_j;"); + node_shader_write_frag(kong, "var texpaint_pack_sample: float4 = sample(texpaint_pack_undo, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7))) * blur_weight_j;"); 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;"); - node_shader_write_frag(kong, "nortan += texture(texpaint_nor_undo, tex_coord_inp + float2(0.0, blur_step * float(j))).rgb * blur_weight[j + 7];"); + node_shader_write_frag(kong, "nortan += sample(texpaint_nor_undo, sampler_linear, tex_coord_inp + float2(0.0, blur_step * float(j - 7))).rgb * blur_weight_j;"); node_shader_write_frag(kong, "}"); } node_shader_write_frag(kong, "opacity *= constants.brush_opacity;"); diff --git a/armorpaint/sources/make_clone.ts b/armorpaint/sources/make_clone.ts index dbc5f566..60ebf9e9 100644 --- a/armorpaint/sources/make_clone.ts +++ b/armorpaint/sources/make_clone.ts @@ -1,7 +1,10 @@ function make_clone_run(kong: node_shader_t) { node_shader_add_constant(kong, "clone_delta: float2", "_clone_delta"); - node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2((sp.xy + constants.clone_delta) * constants.gbuffer_size)].ba;"); + // node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2((sp.xy + constants.clone_delta) * constants.gbuffer_size)].ba;"); + node_shader_write_frag(kong, "var tex_coord_coord: uint2 = uint2(uint((sp.x + constants.clone_delta.x) * constants.gbuffer_size.x), uint((sp.y + constants.clone_delta.y) * constants.gbuffer_size.y));"); + node_shader_write_frag(kong, "var tex_coord_inp4: float4 = gbuffer2[tex_coord_coord];"); + node_shader_write_frag(kong, "var tex_coord_inp: float2 = tex_coord_inp4.ba;"); node_shader_write_frag(kong, "var texpaint_pack_sample: float3 = sample_lod(texpaint_pack_undo, sampler_linear, tex_coord_inp, 0.0).rgb;"); let base: string = "sample_lod(texpaint_undo, sampler_linear, tex_coord_inp, 0.0).rgb"; diff --git a/armorpaint/sources/make_colorid_picker.ts b/armorpaint/sources/make_colorid_picker.ts index 84206b2d..3a87277b 100644 --- a/armorpaint/sources/make_colorid_picker.ts +++ b/armorpaint/sources/make_colorid_picker.ts @@ -7,7 +7,9 @@ function make_colorid_picker_run(kong: node_shader_t) { node_shader_add_constant(kong, "gbuffer_size: float2", "_gbuffer_size"); node_shader_add_constant(kong, "inp: float4", "_input_brush"); - node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(constants.inp.x * constants.gbuffer_size.x, constants.inp.y * constants.gbuffer_size.y)].ba;"); + // node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(constants.inp.x * constants.gbuffer_size.x, constants.inp.y * constants.gbuffer_size.y)].ba;"); + node_shader_write_frag(kong, "var tex_coord_inp4: float4 = gbuffer2[uint2(uint(constants.inp.x * constants.gbuffer_size.x), uint(constants.inp.y * constants.gbuffer_size.y))];"); + node_shader_write_frag(kong, "var tex_coord_inp: float2 = tex_coord_inp4.ba;"); if (context_raw.tool == workspace_tool_t.COLORID) { kong.frag_out = "float4"; diff --git a/armorpaint/sources/make_discard.ts b/armorpaint/sources/make_discard.ts index 71e40b5e..085653ee 100644 --- a/armorpaint/sources/make_discard.ts +++ b/armorpaint/sources/make_discard.ts @@ -2,10 +2,12 @@ function make_discard_color_id(kong: node_shader_t) { node_shader_add_texture(kong, "texpaint_colorid"); // 1x1 picker node_shader_add_texture(kong, "texcolorid", "_texcolorid"); // color map - node_shader_write_frag(kong, "var colorid_c1: float3 = texpaint_colorid[uint2(0, 0)].rgb;"); - node_shader_write_frag(kong, "var colorid_c2: float3 = sample_lod(texcolorid, sampler_linear, tex_coord_pick, 0).rgb;"); + // node_shader_write_frag(kong, "var colorid_c1: float3 = texpaint_colorid[uint2(0, 0)].rgb;"); + node_shader_write_frag(kong, "var colorid_c14: float4 = texpaint_colorid[uint2(uint(0), uint(0))];"); + node_shader_write_frag(kong, "var colorid_c1: float3 = colorid_c14.rgb;"); + node_shader_write_frag(kong, "var colorid_c2: float3 = sample_lod(texcolorid, sampler_linear, input.tex_coord_pick, 0.0).rgb;"); // node_shader_write_frag(kong, "if (any(colorid_c1 != colorid_c2)) { discard };"); - node_shader_write_frag(kong, "if (colorid_c1 != colorid_c2) { discard; }"); + node_shader_write_frag(kong, "if (colorid_c1.r != colorid_c2.r || colorid_c1.g != colorid_c2.g || colorid_c1.b != colorid_c2.b) { discard; }"); } function make_discard_face(kong: node_shader_t) { @@ -13,16 +15,18 @@ function make_discard_face(kong: node_shader_t) { node_shader_add_texture(kong, "textrianglemap", "_textrianglemap"); node_shader_add_constant(kong, "textrianglemap_size: float2", "_texpaint_size"); node_shader_add_constant(kong, "gbuffer_size: float2", "_gbuffer_size"); - node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(inp.x * constants.gbuffer_size.x, inp.y * constants.gbuffer_size.y)].ba;"); - node_shader_write_frag(kong, "var face_c1: float4 = textrianglemap[uint2(tex_coord_inp * constants.textrianglemap_size)];"); - node_shader_write_frag(kong, "var face_c2: float4 = sample_lod(textrianglemap, sampler_linear, tex_coord_pick, 0.0);"); + // node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(inp.x * constants.gbuffer_size.x, inp.y * constants.gbuffer_size.y)].ba;"); + node_shader_write_frag(kong, "var tex_coord_inp4: float4 = gbuffer2[uint2(uint(inp.x * constants.gbuffer_size.x), uint(inp.y * constants.gbuffer_size.y))];"); + node_shader_write_frag(kong, "var tex_coord_inp: float2 = tex_coord_inp4.ba;"); + node_shader_write_frag(kong, "var face_c1: float4 = textrianglemap[uint2(uint(tex_coord_inp.x * constants.textrianglemap_size.x), uint(tex_coord_inp.y * constants.textrianglemap_size.y))];"); + node_shader_write_frag(kong, "var face_c2: float4 = sample_lod(textrianglemap, sampler_linear, input.tex_coord_pick, 0.0);"); // node_shader_write_frag(kong, "if (any(face_c1 != face_c2)) { discard; }"); - node_shader_write_frag(kong, "if (face_c1 != face_c2) { discard; }"); + node_shader_write_frag(kong, "if (face_c1.x != face_c2.x || face_c1.y != face_c2.y || face_c1.z != face_c2.z || face_c1.w != face_c2.w) { discard; }"); } function make_discard_uv_island(kong: node_shader_t) { node_shader_add_texture(kong, "texuvislandmap", "_texuvislandmap"); - node_shader_write_frag(kong, "if (sample_lod(texuvislandmap, sampler_linear, tex_coord_pick, 0.0).r == 0.0) { discard; }"); + node_shader_write_frag(kong, "if (sample_lod(texuvislandmap, sampler_linear, input.tex_coord_pick, 0.0).r == 0.0) { discard; }"); } function make_discard_material_id(kong: node_shader_t) { diff --git a/armorpaint/sources/make_particle.ts b/armorpaint/sources/make_particle.ts index 1787e2dc..4922bf14 100644 --- a/armorpaint/sources/make_particle.ts +++ b/armorpaint/sources/make_particle.ts @@ -13,7 +13,7 @@ function make_particle_mask(kong: node_shader_t) { node_shader_write_frag(kong, "dist = length(pa - ba * h) * 10.0;"); node_shader_write_frag(kong, "if (dist > 1.0) { discard; }"); - node_shader_write_frag(kong, "var str: float = clamp(pow(1.0 / dist * brush_hardness * 0.2, 4.0), 0.0, 1.0) * opacity;"); + node_shader_write_frag(kong, "var str: float = clamp(pow(1.0 / dist * constants.brush_hardness * 0.2, 4.0), 0.0, 1.0) * opacity;"); node_shader_write_frag(kong, "if (constants.particle_hit.x == 0.0 && constants.particle_hit.y == 0.0 && constants.particle_hit.z == 0.0) { str = 0.0; }"); node_shader_write_frag(kong, "if (str == 0.0) { discard; }"); ///else diff --git a/armorsculpt/sources/make_brush.ts b/armorsculpt/sources/make_brush.ts index 27ebbf1b..f847bf42 100644 --- a/armorsculpt/sources/make_brush.ts +++ b/armorsculpt/sources/make_brush.ts @@ -15,7 +15,7 @@ function make_brush_run(kong: node_shader_t) { node_shader_add_constant(kong, "texpaint_undo_size: float2", "_size(texpaint_undo)"); - node_shader_write_attrib_frag(kong, "var wposition: float3 = (constants.W * texpaint_undo[uint2(tex_coord.x * constants.texpaint_undo_size.x, tex_coord.y * constants.texpaint_undo_size.y)]).xyz;"); + node_shader_write_attrib_frag(kong, "var wposition: float3 = (constants.W * texpaint_undo[uint2(input.tex_coord.x * constants.texpaint_undo_size.x, input.tex_coord.y * constants.texpaint_undo_size.y)]).xyz;"); node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, sampler_linear, constants.inplast.xy, 0.0).r;"); diff --git a/base/sources/ts/parser_material.ts b/base/sources/ts/parser_material.ts index cb2584ed..5554c336 100644 --- a/base/sources/ts/parser_material.ts +++ b/base/sources/ts/parser_material.ts @@ -27,7 +27,7 @@ let parser_material_nodes: ui_node_t[]; let parser_material_links: ui_node_link_t[]; let parser_material_cotangent_frame_written: bool; -let parser_material_tex_coord: string = "tex_coord"; +let parser_material_tex_coord: string = "input.tex_coord"; let parser_material_eps: f32 = 0.000001; let parser_material_custom_nodes: map_t = map_create(); // JSValue -> (n: ui_node_t, s: string)=>string @@ -641,7 +641,7 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t) parser_material_write(parser_material_kong, "var " + store + "_rad: float = " + angle + " * (" + pi + " / 180);"); parser_material_write(parser_material_kong, "var " + store + "_x: float = cos(" + store + "_rad);"); parser_material_write(parser_material_kong, "var " + store + "_y: float = sin(" + store + "_rad);"); - return "sample(" + tex_name + ", sampler_linear, + tex_coord + float2(" + store + "_x, " + store + "_y) * " + mask + ").rgb;"; + return "sample(" + tex_name + ", sampler_linear, + input.tex_coord + float2(" + store + "_x, " + store + "_y) * " + mask + ").rgb;"; } else if (node.type == "BLUR") { if (parser_material_blur_passthrough) { @@ -659,7 +659,7 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t) parser_material_write(parser_material_kong, "var " + store + "_res: float3 = float3(0.0, 0.0, 0.0);"); parser_material_write(parser_material_kong, "for (var i: int = -" + steps + "; i <= " + steps + "; i += 1) {"); parser_material_write(parser_material_kong, "for (var j: int = -" + steps + "; j <= " + steps + "; j += 1) {"); - parser_material_write(parser_material_kong, store + "_res += sample(" + tex_name + ", sampler_linear, tex_coord + float2(i, j) / constants." + tex_name + "_size).rgb;"); + parser_material_write(parser_material_kong, store + "_res += sample(" + tex_name + ", sampler_linear, input.tex_coord + float2(i, j) / constants." + tex_name + "_size).rgb;"); parser_material_write(parser_material_kong, "}"); parser_material_write(parser_material_kong, "}"); parser_material_write(parser_material_kong, store + "_res /= (" + steps + " * 2 + 1) * (" + steps + " * 2 + 1);"); @@ -877,11 +877,11 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t) let l: any = node.buttons[0].default_value; if (socket == node.outputs[0]) { // Base node_shader_add_texture(parser_material_kong, "texpaint" + l, "_texpaint" + l); - return "sample(texpaint" + l + ", sampler_linear, tex_coord).rgb"; + return "sample(texpaint" + l + ", sampler_linear, input.tex_coord).rgb"; } else if (socket == node.outputs[5]) { // Normal node_shader_add_texture(parser_material_kong, "texpaint_nor" + l, "_texpaint_nor" + l); - return "sample(texpaint_nor" + l + ", sampler_linear, tex_coord).rgb"; + return "sample(texpaint_nor" + l + ", sampler_linear, input.tex_coord).rgb"; } } else if (node.type == "MATERIAL") { @@ -1204,7 +1204,7 @@ function parse_normal_map_color_input(inp: ui_node_socket_t) { node_shader_add_function(parser_material_kong, str_cotangent_frame); } parser_material_kong.frag_n = true; - parser_material_write(parser_material_kong, "var TBN: float3x3 = cotangent_frame(n, vvec, tex_coord);"); + parser_material_write(parser_material_kong, "var TBN: float3x3 = cotangent_frame(n, vvec, input.tex_coord);"); parser_material_write(parser_material_kong, "n = TBN * normalize(texn);"); } @@ -1275,30 +1275,30 @@ function parser_material_parse_value(node: ui_node_t, socket: ui_node_socket_t): let l: any = node.buttons[0].default_value; if (socket == node.outputs[1]) { // Opac node_shader_add_texture(parser_material_kong, "texpaint" + l, "_texpaint" + l); - return "sample(texpaint" + l + ", sampler_linear, tex_coord).a"; + return "sample(texpaint" + l + ", sampler_linear, input.tex_coord).a"; } else if (socket == node.outputs[2]) { // Occ node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l); - return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).r"; + return "sample(texpaint_pack" + l + ", sampler_linear, input.tex_coord).r"; } else if (socket == node.outputs[3]) { // Rough node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l); - return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).g"; + return "sample(texpaint_pack" + l + ", sampler_linear, input.tex_coord).g"; } else if (socket == node.outputs[4]) { // Metal node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l); - return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).b"; + return "sample(texpaint_pack" + l + ", sampler_linear, input.tex_coord).b"; } else if (socket == node.outputs[7]) { // Height node_shader_add_texture(parser_material_kong, "texpaint_pack" + l, "_texpaint_pack" + l); - return "sample(texpaint_pack" + l + ", sampler_linear, tex_coord).a"; + return "sample(texpaint_pack" + l + ", sampler_linear, input.tex_coord).a"; } } else if (node.type == "LAYER_MASK") { if (socket == node.outputs[0]) { let l: any = node.buttons[0].default_value; node_shader_add_texture(parser_material_kong, "texpaint" + l, "_texpaint" + l); - return "sample(texpaint" + l + ", sampler_linear, tex_coord).r"; + return "sample(texpaint" + l + ", sampler_linear, input.tex_coord).r"; } } else if (node.type == "MATERIAL") { @@ -1513,7 +1513,7 @@ function parser_material_parse_value(node: ui_node_t, socket: ui_node_socket_t): let tex_name: string = "texbake_" + parser_material_node_name(node); node_shader_add_texture(parser_material_kong, "" + tex_name, "_" + tex_name); let store: string = parser_material_store_var_name(node); - parser_material_write(parser_material_kong, "var " + store + "_res: float = sample(" + tex_name + ", sampler_linear, tex_coord).r;"); + parser_material_write(parser_material_kong, "var " + store + "_res: float = sample(" + tex_name + ", sampler_linear, input.tex_coord).r;"); return store + "_res"; } else if (node.type == "NORMAL") { diff --git a/base/sources/ts/strings.ts b/base/sources/ts/strings.ts index f5d01c12..742de70a 100644 --- a/base/sources/ts/strings.ts +++ b/base/sources/ts/strings.ts @@ -394,3 +394,37 @@ fun get_nor_from_depth(p0: float3, uv: float2, invVP: flaot4x4, tex_step: float2 return normalize(cross(p2 - p0, p1 - p0)); \ } \ "; + +//// +let str_get_smudge_tool_weight: string = "\ +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; \ +} \ +"; + +let str_get_blur_tool_weight: string = "\ +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; \ +} \ +"; +////