From 35e52dbcb5bee39ea6fc52ba52b806a391e1a12b Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 19 Apr 2025 12:29:49 +0200 Subject: [PATCH] Use static samplers --- armorlab/shaders/inpaint_preview.kong | 9 +- armorlab/shaders/layer_copy_rrrr.kong | 4 +- armorlab/sources/make_material.ts | 13 -- armorlab/sources/make_mesh.ts | 14 +- armorlab/sources/make_paint.ts | 14 +- armorpaint/shaders/dilate_pass.kong | 7 +- armorpaint/shaders/layer_invert.kong | 4 +- armorpaint/shaders/layer_merge.kong | 31 ++-- armorpaint/shaders/layer_view.kong | 14 +- armorpaint/shaders/mask_colorid.kong | 7 +- armorpaint/shaders/mask_merge.kong | 9 +- armorpaint/sources/make_bake.ts | 12 +- armorpaint/sources/make_blur.ts | 14 +- armorpaint/sources/make_brush.ts | 6 +- armorpaint/sources/make_clone.ts | 6 +- armorpaint/sources/make_colorid_picker.ts | 8 +- armorpaint/sources/make_discard.ts | 8 +- armorpaint/sources/make_material.ts | 22 +-- armorpaint/sources/make_mesh.ts | 46 +++--- armorpaint/sources/make_mesh_preview.ts | 2 +- armorpaint/sources/make_paint.ts | 24 +-- armorsculpt/sources/make_brush.ts | 4 +- armorsculpt/sources/make_material.ts | 21 --- armorsculpt/sources/make_mesh.ts | 24 +-- armorsculpt/sources/make_mesh_preview.ts | 2 +- armorsculpt/sources/make_sculpt.ts | 4 +- base/assets/Scene.arm | Bin 178153 -> 178066 bytes base/shaders/bloom_downsample_pass.kong | 12 +- base/shaders/bloom_upsample_pass.kong | 18 +-- base/shaders/compositor_pass.kong | 11 +- base/shaders/copy_mrt3_pass.kong | 15 +- base/shaders/copy_pass.kong | 5 +- base/shaders/cursor.kong | 4 +- base/shaders/deferred_light.kong | 27 +--- base/shaders/draw/draw_image.kong | 4 +- base/shaders/draw/draw_text.kong | 4 +- base/shaders/histogram_pass.kong | 13 +- base/shaders/layer_copy.kong | 4 +- base/shaders/layer_copy_bgra.kong | 4 +- base/shaders/mask_apply.kong | 9 +- base/shaders/prefilter_envmap.kong | 4 +- base/shaders/ssao_blur_pass.kong | 17 +- base/shaders/ssao_pass.kong | 11 +- base/shaders/supersample_resolve.kong | 20 +-- base/shaders/taa_pass.kong | 9 +- base/shaders/world_pass.kong | 4 +- base/sources/backends/direct3d12_gpu.c | 179 ++++------------------ base/sources/backends/direct3d12_gpu.h | 7 - base/sources/backends/metal_gpu.h | 4 - base/sources/backends/metal_gpu.m | 78 ---------- base/sources/backends/vulkan_gpu.c | 77 ---------- base/sources/backends/vulkan_gpu.h | 4 - base/sources/backends/webgpu_gpu.c | 18 --- base/sources/backends/webgpu_gpu.h | 4 - base/sources/iron.h | 8 - base/sources/iron_draw.c | 11 -- base/sources/iron_gpu.c | 117 -------------- base/sources/iron_gpu.h | 66 -------- base/sources/ts/iron/iron.ts | 19 --- base/sources/ts/iron/material_data.ts | 5 - base/sources/ts/iron/scene.ts | 12 -- base/sources/ts/iron/shader_data.ts | 41 ----- base/sources/ts/iron/uniforms.ts | 33 ---- base/sources/ts/node_shader.ts | 24 +-- base/sources/ts/parser_material.ts | 50 +++--- base/sources/ts/strings.ts | 4 +- base/sources/ts/util_clone.ts | 5 - base/tests/cube/shaders/mesh.kong | 4 +- base/tests/fall/shaders/mesh.kong | 4 +- 69 files changed, 262 insertions(+), 1036 deletions(-) diff --git a/armorlab/shaders/inpaint_preview.kong b/armorlab/shaders/inpaint_preview.kong index 435ba95c..fb805f0d 100644 --- a/armorlab/shaders/inpaint_preview.kong +++ b/armorlab/shaders/inpaint_preview.kong @@ -2,14 +2,11 @@ #[set(everything)] const tex0: tex2d; -#[set(everything)] -const tex0_sampler: sampler; - #[set(everything)] const texa: tex2d; #[set(everything)] -const texa_sampler: sampler; +const sampler_linear: sampler; struct vert_in { pos: float2; @@ -29,8 +26,8 @@ fun inpaint_preview_vert(input: vert_in): vert_out { } fun inpaint_preview_frag(input: vert_out): float4 { - var col: float4 = sample_lod(tex0, tex0_sampler, input.tex, 0.0); - var mask: float = clamp(sample_lod(texa, texa_sampler, input.tex, 0.0).r + 0.5, 0.0, 1.0); + var col: float4 = sample_lod(tex0, sampler_linear, input.tex, 0.0); + var mask: float = clamp(sample_lod(texa, sampler_linear, input.tex, 0.0).r + 0.5, 0.0, 1.0); return col * mask; } diff --git a/armorlab/shaders/layer_copy_rrrr.kong b/armorlab/shaders/layer_copy_rrrr.kong index 4d8d5777..57e6b3b8 100644 --- a/armorlab/shaders/layer_copy_rrrr.kong +++ b/armorlab/shaders/layer_copy_rrrr.kong @@ -3,7 +3,7 @@ const tex: tex2d; #[set(everything)] -const tex_sampler: sampler; +const sampler_linear: sampler; struct vert_in { pos: float2; @@ -23,7 +23,7 @@ fun layer_copy_rrrr_vert(input: vert_in): vert_out { } fun layer_copy_rrrr_frag(input: vert_out): float4 { - return sample_lod(tex, tex_sampler, input.tex, 0.0).rrrr; + return sample_lod(tex, sampler_linear, input.tex, 0.0).rrrr; } #[pipe] diff --git a/armorlab/sources/make_material.ts b/armorlab/sources/make_material.ts index f08c1099..51648f4d 100644 --- a/armorlab/sources/make_material.ts +++ b/armorlab/sources/make_material.ts @@ -28,16 +28,6 @@ function make_material_parse_mesh_material() { let con: node_shader_context_t = make_mesh_run(mm); let scon: shader_context_t = shader_context_create(con.data); - let override_context: _shader_override_t = {}; - // if (con.kong.shared_samplers.length > 0) { - // let sampler: string = con.kong.shared_samplers[0]; - // override_context.shared_sampler = substring(sampler, string_last_index_of(sampler, " ") + 1, sampler.length); - // } - if (!context_raw.texture_filter) { - override_context.filter = "point"; - } - override_context.addressing = "repeat"; - scon._.override_context = override_context; array_push(m._.shader.contexts, scon); array_push(m._.shader._.contexts, scon); @@ -88,9 +78,6 @@ function make_material_parse_paint_material() { return; } - let override_context: _shader_override_t = {}; - override_context.addressing = "repeat"; - scon2._.override_context = override_context; let mcon3: material_context_t = material_context_create(mcon2); array_push(m._.shader.contexts, scon2); diff --git a/armorlab/sources/make_mesh.ts b/armorlab/sources/make_mesh.ts index 31f0f30b..701847c0 100644 --- a/armorlab/sources/make_mesh.ts +++ b/armorlab/sources/make_mesh.ts @@ -88,16 +88,16 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_add_texture(kong, "senvmap_radiance", "_envmap_radiance"); } - node_shader_add_shared_sampler(kong, "texpaint"); - node_shader_write_frag(kong, "texpaint_sample = sample_lod(texpaint, shared_sampler, input.tex_coord, 0.0);"); + node_shader_add_texture(kong, "texpaint"); + node_shader_write_frag(kong, "texpaint_sample = sample_lod(texpaint, sampler_linear, input.tex_coord, 0.0);"); node_shader_write_frag(kong, "texpaint_opac = texpaint_sample.a;"); node_shader_write_frag(kong, "basecol = texpaint_sample.rgb * texpaint_opac;"); - node_shader_add_shared_sampler(kong, "texpaint_nor"); - node_shader_write_frag(kong, "texpaint_nor_sample = sample_lod(texpaint_nor, shared_sampler, input.tex_coord, 0.0);"); + node_shader_add_texture(kong, "texpaint_nor"); + node_shader_write_frag(kong, "texpaint_nor_sample = sample_lod(texpaint_nor, sampler_linear, input.tex_coord, 0.0);"); node_shader_write_frag(kong, "ntex = lerp3(ntex, texpaint_nor_sample.rgb, texpaint_opac);"); - node_shader_add_shared_sampler(kong, "texpaint_pack"); - node_shader_write_frag(kong, "texpaint_pack_sample = sample_lod(texpaint_pack, shared_sampler, input.tex_coord, 0.0);"); + node_shader_add_texture(kong, "texpaint_pack"); + node_shader_write_frag(kong, "texpaint_pack_sample = sample_lod(texpaint_pack, sampler_linear, input.tex_coord, 0.0);"); node_shader_write_frag(kong, "occlusion = lerp(occlusion, texpaint_pack_sample.r, texpaint_opac);"); node_shader_write_frag(kong, "roughness = lerp(roughness, texpaint_pack_sample.g, texpaint_opac);"); node_shader_write_frag(kong, "metallic = lerp(metallic, texpaint_pack_sample.b, texpaint_opac);"); @@ -142,7 +142,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_write_frag(kong, "var wreflect: float3 = reflect(-vvec, n);"); node_shader_write_frag(kong, "var envlod: float = roughness * float(constants.envmap_num_mipmaps);"); node_shader_add_function(frag, str_envmap_equirect); - node_shader_write_frag(kong, "var prefiltered_color: float3 = sample_lod(senvmap_radiance, senvmap_radiance_sampler, envmap_equirect(wreflect, constants.envmap_data.x), envlod).rgb;"); + node_shader_write_frag(kong, "var prefiltered_color: float3 = sample_lod(senvmap_radiance, sampler_linear, envmap_equirect(wreflect, constants.envmap_data.x), envlod).rgb;"); // node_shader_add_constant(kong, "shirr: float4[7]", "_envmap_irradiance"); node_shader_add_constant(kong, "shirr0: float4", "_envmap_irradiance0"); node_shader_add_constant(kong, "shirr1: float4", "_envmap_irradiance1"); diff --git a/armorlab/sources/make_paint.ts b/armorlab/sources/make_paint.ts index a47636ed..8f60c5ed 100644 --- a/armorlab/sources/make_paint.ts +++ b/armorlab/sources/make_paint.ts @@ -54,9 +54,9 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad node_shader_add_texture(kong, "texpaint"); node_shader_add_texture(kong, "texpaint_nor"); node_shader_add_texture(kong, "texpaint_pack"); - node_shader_write_frag(kong, "output[0] = sample_lod(texpaint, texpaint_sampler, tex_coord_inp, 0.0);"); - node_shader_write_frag(kong, "output[1] = sample_lod(texpaint_nor, texpaint_nor_sampler, tex_coord_inp, 0.0);"); - node_shader_write_frag(kong, "output[2] = sample_lod(texpaint_pack, texpaint_pack_sampler, tex_coord_inp, 0.0);"); + node_shader_write_frag(kong, "output[0] = sample_lod(texpaint, sampler_linear, tex_coord_inp, 0.0);"); + node_shader_write_frag(kong, "output[1] = sample_lod(texpaint_nor, sampler_linear, tex_coord_inp, 0.0);"); + node_shader_write_frag(kong, "output[2] = sample_lod(texpaint_pack, sampler_linear, tex_coord_inp, 0.0);"); node_shader_write_frag(kong, "output[3].rg = tex_coord_inp.xy;"); con_paint.data.shader_from_source = true; gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_paint.data.vertex_shader), ADDRESS(con_paint.data.fragment_shader)); @@ -98,7 +98,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad node_shader_write_frag(kong, "var dist: float = 0.0;"); - node_shader_write_frag(kong, "var depth: float = sample_lod(gbufferD, gbufferD_sampler, constants.inp.xy, 0.0).r;"); + 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"); node_shader_write_frag(kong, "var winp: float4 = float4(float2(constants.inp.x, 1.0 - constants.inp.y) * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);"); @@ -106,7 +106,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad node_shader_write_frag(kong, "winp.xyz /= winp.w;"); kong.frag_wposition = true; - node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, gbufferD_sampler, constants.inplast.xy, 0.0).r;"); + node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, sampler_linear, constants.inplast.xy, 0.0).r;"); node_shader_write_frag(kong, "var winplast: float4 = float4(float2(constants.inplast.x, 1.0 - constants.inplast.y) * 2.0 - 1.0, depthlast * 2.0 - 1.0, 1.0);"); node_shader_write_frag(kong, "winplast = constants.invVP * winplast;"); @@ -145,11 +145,11 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad node_shader_write_frag(kong, "var sample_tc: float2 = float2(input.wvpposition.xy / input.wvpposition.w) * 0.5 + 0.5;"); node_shader_write_frag(kong, "sample_tc.y = 1.0 - sample_tc.y;"); node_shader_add_texture(kong, "paintmask"); - node_shader_write_frag(kong, "var sample_mask: float = sample_lod(paintmask, paintmask_sampler, sample_tc, 0.0).r;"); + node_shader_write_frag(kong, "var sample_mask: float = sample_lod(paintmask, sampler_linear, sample_tc, 0.0).r;"); node_shader_write_frag(kong, "str = max(str, sample_mask);"); node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); - node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, texpaint_undo_sampler, sample_tc, 0.0);"); + node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, sampler_linear, sample_tc, 0.0);"); if (context_raw.tool == workspace_tool_t.ERASER) { node_shader_write_frag(kong, "output[0] = float4(0.0, 0.0, 0.0, 0.0);"); diff --git a/armorpaint/shaders/dilate_pass.kong b/armorpaint/shaders/dilate_pass.kong index 6c6b8d8c..634c806e 100644 --- a/armorpaint/shaders/dilate_pass.kong +++ b/armorpaint/shaders/dilate_pass.kong @@ -8,14 +8,11 @@ const constants: { #[set(everything)] const tex: tex2d; -#[set(everything)] -const tex_sampler: sampler; - #[set(everything)] const texdilate: tex2d; #[set(everything)] -const texdilate_sampler: sampler; +const sampler_linear: sampler; // const offsets: float2[8] = { // float2(-1.0, 0.0), float2( 1.0, 0.0), float2( 0.0, 1.0), float2( 0.0, -1.0), @@ -89,7 +86,7 @@ fun dilate_pass_frag(input: vert_out): float4 { var cur_dist: float = length(input.tex - cur_uv); if (cur_dist < min_dist) { var project_uv: float2 = cur_uv + get_offset(j) * texel_size * float2(i, i) * float2(0.25, 0.25); - var direction: float4 = sample_lod(tex, tex_sampler, project_uv, 0.0); + var direction: float4 = sample_lod(tex, sampler_linear, project_uv, 0.0); min_dist = cur_dist; if (direction.x != 0.0 || direction.y != 0.0 || direction.z != 0.0) { var delta: float4 = offset_col - direction; diff --git a/armorpaint/shaders/layer_invert.kong b/armorpaint/shaders/layer_invert.kong index 92acb1bc..e4670fb4 100644 --- a/armorpaint/shaders/layer_invert.kong +++ b/armorpaint/shaders/layer_invert.kong @@ -8,7 +8,7 @@ const constants: { const tex: tex2d; #[set(everything)] -const tex_sampler: sampler; +const sampler_linear: sampler; struct vert_in { pos: float3; @@ -31,7 +31,7 @@ fun layer_invert_vert(input: vert_in): vert_out { } fun layer_invert_frag(input: vert_out): float4 { - return float4(1.0, 1.0, 1.0, 1.0) - sample_lod(tex, tex_sampler, input.tex, 0.0) * input.col; + return float4(1.0, 1.0, 1.0, 1.0) - sample_lod(tex, sampler_linear, input.tex, 0.0) * input.col; } #[pipe] diff --git a/armorpaint/shaders/layer_merge.kong b/armorpaint/shaders/layer_merge.kong index d4e24244..464038ec 100644 --- a/armorpaint/shaders/layer_merge.kong +++ b/armorpaint/shaders/layer_merge.kong @@ -9,26 +9,17 @@ const constants: { #[set(everything)] const tex0: tex2d; -#[set(everything)] -const tex0_sampler: sampler; - #[set(everything)] const tex1: tex2d; -#[set(everything)] -const tex1_sampler: sampler; - #[set(everything)] const texmask: tex2d; -#[set(everything)] -const texmask_sampler: sampler; - #[set(everything)] const texa: tex2d; #[set(everything)] -const texa_sampler: sampler; +const sampler_linear: sampler; struct vert_in { pos: float2; @@ -63,17 +54,17 @@ fun rgb_to_hsv(c: float3): float3 { } fun layer_merge_frag(input: vert_out): float4 { - var col0: float4 = sample_lod(tex0, tex0_sampler, input.tex, 0.0); - var cola: float4 = sample_lod(texa, texa_sampler, input.tex, 0.0); + var col0: float4 = sample_lod(tex0, sampler_linear, input.tex, 0.0); + var cola: float4 = sample_lod(texa, sampler_linear, input.tex, 0.0); var str: float = col0.a * constants.opac; - str *= sample_lod(texmask, texmask_sampler, input.tex, 0.0).r; + str *= sample_lod(texmask, sampler_linear, input.tex, 0.0).r; if (constants.blending == -1) { // Merging _nor and _pack - var col1: float4 = sample_lod(tex1, tex1_sampler, input.tex, 0.0); + var col1: float4 = sample_lod(tex1, sampler_linear, input.tex, 0.0); return float4(lerp4(cola, col1, str)); } if (constants.blending == -2) { // Merging _nor with normal blending - var col1: float4 = sample_lod(tex1, tex1_sampler, input.tex, 0.0); + var col1: float4 = sample_lod(tex1, sampler_linear, input.tex, 0.0); // Whiteout blend var n1: float3 = cola.rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0); var n2: float3 = lerp3(float3(0.5, 0.5, 1.0), col1.rgb, str) * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0); @@ -82,15 +73,15 @@ fun layer_merge_frag(input: vert_out): float4 { max(col1.a, cola.a)); } if (constants.blending == -3) { // Merging _pack with height blending - var col1: float4 = sample_lod(tex1, tex1_sampler, input.tex, 0.0); + var col1: float4 = sample_lod(tex1, sampler_linear, input.tex, 0.0); return float4(lerp3(cola.rgb, col1.rgb, str), cola.a + col1.a); } if (constants.blending == -4) { // Merge _pack.height into _nor var tex_step: float = 1.0 / constants.tex1w; - var height0: float = sample_lod(tex1, tex1_sampler, float2(input.tex.x - tex_step, input.tex.y), 0.0).a; - var height1: float = sample_lod(tex1, tex1_sampler, float2(input.tex.x + tex_step, input.tex.y), 0.0).a; - var height2: float = sample_lod(tex1, tex1_sampler, float2(input.tex.x, input.tex.y - tex_step), 0.0).a; - var height3: float = sample_lod(tex1, tex1_sampler, float2(input.tex.x, input.tex.y + tex_step), 0.0).a; + var height0: float = sample_lod(tex1, sampler_linear, float2(input.tex.x - tex_step, input.tex.y), 0.0).a; + var height1: float = sample_lod(tex1, sampler_linear, float2(input.tex.x + tex_step, input.tex.y), 0.0).a; + var height2: float = sample_lod(tex1, sampler_linear, float2(input.tex.x, input.tex.y - tex_step), 0.0).a; + var height3: float = sample_lod(tex1, sampler_linear, float2(input.tex.x, input.tex.y + tex_step), 0.0).a; var height_dx: float = height0 - height1; var height_dy: float = height2 - height3; // Whiteout blend diff --git a/armorpaint/shaders/layer_view.kong b/armorpaint/shaders/layer_view.kong index f58a7975..24a65f1e 100644 --- a/armorpaint/shaders/layer_view.kong +++ b/armorpaint/shaders/layer_view.kong @@ -9,7 +9,7 @@ const constants: { const tex: tex2d; #[set(everything)] -const tex_sampler: sampler; +const sampler_linear: sampler; struct vert_in { pos: float3; @@ -33,22 +33,22 @@ fun layer_view_vert(input: vert_in): vert_out { fun layer_view_frag(input: vert_out): float4 { if (constants.channel == 1) { - return sample_lod(tex, tex_sampler, input.tex, 0.0).rrra * input.col; + return sample_lod(tex, sampler_linear, input.tex, 0.0).rrra * input.col; } if (constants.channel == 2) { - return sample_lod(tex, tex_sampler, input.tex, 0.0).ggga * input.col; + return sample_lod(tex, sampler_linear, input.tex, 0.0).ggga * input.col; } if (constants.channel == 3) { - return sample_lod(tex, tex_sampler, input.tex, 0.0).bbba * input.col; + return sample_lod(tex, sampler_linear, input.tex, 0.0).bbba * input.col; } if (constants.channel == 4) { - return sample_lod(tex, tex_sampler, input.tex, 0.0).aaaa * input.col; + return sample_lod(tex, sampler_linear, input.tex, 0.0).aaaa * input.col; } if (constants.channel == 5) { - return sample_lod(tex, tex_sampler, input.tex, 0.0).rgba * input.col; + return sample_lod(tex, sampler_linear, input.tex, 0.0).rgba * input.col; } // else { - var tex_sample: float4 = sample_lod(tex, tex_sampler, input.tex, 0.0); + var tex_sample: float4 = sample_lod(tex, sampler_linear, input.tex, 0.0); tex_sample.rgb *= tex_sample.a; return tex_sample * input.col; // } diff --git a/armorpaint/shaders/mask_colorid.kong b/armorpaint/shaders/mask_colorid.kong index f5300210..91b2f616 100644 --- a/armorpaint/shaders/mask_colorid.kong +++ b/armorpaint/shaders/mask_colorid.kong @@ -4,14 +4,11 @@ #[set(everything)] const texpaint_colorid: tex2d; // 1x1 picked color -#[set(everything)] -const texpaint_colorid_sampler: sampler; - #[set(everything)] const texcolorid: tex2d; #[set(everything)] -const texcolorid_sampler: sampler; +const sampler_linear: sampler; struct vert_in { pos: float2; @@ -33,7 +30,7 @@ fun mask_colorid_vert(input: vert_in): vert_out { fun mask_colorid_frag(input: vert_out): float4 { var coord: uint2 = uint2(0, 0); var colorid_c1: float4 = texpaint_colorid[coord]; - var colorid_c2: float4 = sample_lod(texcolorid, texcolorid_sampler, input.tex, 0.0); + var colorid_c2: float4 = sample_lod(texcolorid, sampler_linear, input.tex, 0.0); if (colorid_c1.x != colorid_c2.x || colorid_c1.y != colorid_c2.y || colorid_c1.z != colorid_c2.z) { discard; } diff --git a/armorpaint/shaders/mask_merge.kong b/armorpaint/shaders/mask_merge.kong index 51af5870..fa071f35 100644 --- a/armorpaint/shaders/mask_merge.kong +++ b/armorpaint/shaders/mask_merge.kong @@ -8,14 +8,11 @@ const constants: { #[set(everything)] const tex0: tex2d; -#[set(everything)] -const tex0_sampler: sampler; - #[set(everything)] const texa: tex2d; #[set(everything)] -const texa_sampler: sampler; +const sampler_linear: sampler; struct vert_in { pos: float2; @@ -35,8 +32,8 @@ fun mask_merge_vert(input: vert_in): vert_out { } fun mask_merge_frag(input: vert_out): float4 { - var col0: float = sample_lod(tex0, tex0_sampler, input.tex, 0.0).r; - var cola: float = sample_lod(texa, texa_sampler, input.tex, 0.0).r; + var col0: float = sample_lod(tex0, sampler_linear, input.tex, 0.0).r; + var cola: float = sample_lod(texa, sampler_linear, input.tex, 0.0).r; var str: float = constants.opac; var out_color: float = 0.0; diff --git a/armorpaint/sources/make_bake.ts b/armorpaint/sources/make_bake.ts index c4d4caca..2f3ab748 100644 --- a/armorpaint/sources/make_bake.ts +++ b/armorpaint/sources/make_bake.ts @@ -22,7 +22,7 @@ function make_bake_run(con: node_shader_context_t, kong: node_shader_t) { else if (context_raw.bake_type == bake_type_t.NORMAL) { // Tangent kong.frag_n = true; node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); // Baked high-poly normals - node_shader_write_frag(kong, "var n0: float3 = sample_lod(texpaint_undo, texpaint_undo_sampler, input.tex_coord, 0.0).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);"); + node_shader_write_frag(kong, "var n0: float3 = sample_lod(texpaint_undo, sampler_linear, input.tex_coord, 0.0).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);"); node_shader_add_function(kong, str_cotangent_frame); node_shader_add_function(kong, str_transpose); node_shader_write_frag(kong, "var invTBN: float3x3 = _transpose(cotangent_frame(n, n, input.tex_coord));"); @@ -39,7 +39,7 @@ function make_bake_run(con: node_shader_context_t, kong: node_shader_t) { else if (context_raw.bake_type == bake_type_t.HEIGHT) { kong.frag_wposition = true; node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); // Baked high-poly positions - node_shader_write_frag(kong, "var wpos0: float3 = sample_lod(texpaint_undo, texpaint_undo_sampler, input.tex_coord, 0.0).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);"); + node_shader_write_frag(kong, "var wpos0: float3 = sample_lod(texpaint_undo, sampler_linear, input.tex_coord, 0.0).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);"); node_shader_write_frag(kong, "var res: float = distance(wpos0, input.wposition) * 10.0;"); node_shader_write_frag(kong, "output[0] = float4(res, res, res, 1.0);"); } @@ -47,9 +47,9 @@ function make_bake_run(con: node_shader_context_t, kong: node_shader_t) { node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); // Baked height node_shader_write_frag(kong, "var tex_dx: float2 = ddx2(input.tex_coord);"); node_shader_write_frag(kong, "var tex_dy: float2 = ddy2(input.tex_coord);"); - node_shader_write_frag(kong, "var h0: float = sample_lod(texpaint_undo, texpaint_undo_sampler, input.tex_coord, 0.0).r * 100;"); - node_shader_write_frag(kong, "var h1: float = sample_lod(texpaint_undo, texpaint_undo_sampler, input.tex_coord + tex_dx, 0.0).r * 100;"); - node_shader_write_frag(kong, "var h2: float = sample_lod(texpaint_undo, texpaint_undo_sampler, input.tex_coord + tex_dy, 0.0).r * 100;"); + node_shader_write_frag(kong, "var h0: float = sample_lod(texpaint_undo, sampler_linear, input.tex_coord, 0.0).r * 100;"); + node_shader_write_frag(kong, "var h1: float = sample_lod(texpaint_undo, sampler_linear, input.tex_coord + tex_dx, 0.0).r * 100;"); + node_shader_write_frag(kong, "var h2: float = sample_lod(texpaint_undo, sampler_linear, input.tex_coord + tex_dy, 0.0).r * 100;"); node_shader_write_frag(kong, "output[0] = float4((h1 - h0) * 0.5 + 0.5, (h2 - h0) * 0.5 + 0.5, 0.0, 1.0);"); } else if (context_raw.bake_type == bake_type_t.POSITION) { @@ -64,7 +64,7 @@ function make_bake_run(con: node_shader_context_t, kong: node_shader_t) { } else if (context_raw.bake_type == bake_type_t.MATERIALID) { node_shader_add_texture(kong, "texpaint_nor_undo", "_texpaint_nor_undo"); - node_shader_write_frag(kong, "var sample_matid: float = sample_lod(texpaint_nor_undo, texpaint_nor_undo_sampler, input.tex_coord, 0.0).a + 1.0 / 255.0;"); + node_shader_write_frag(kong, "var sample_matid: float = sample_lod(texpaint_nor_undo, sampler_linear, input.tex_coord, 0.0).a + 1.0 / 255.0;"); node_shader_write_frag(kong, "var matid_r: float = frac(sin(dot(float2(sample_matid, sample_matid * 20.0), float2(12.9898, 78.233))) * 43758.5453);"); node_shader_write_frag(kong, "var matid_g: float = frac(sin(dot(float2(sample_matid * 20.0, sample_matid), float2(12.9898, 78.233))) * 43758.5453);"); node_shader_write_frag(kong, "var matid_b: float = frac(sin(dot(float2(sample_matid, sample_matid * 40.0), float2(12.9898, 78.233))) * 43758.5453);"); diff --git a/armorpaint/sources/make_blur.ts b/armorpaint/sources/make_blur.ts index 19e3de31..160c6909 100644 --- a/armorpaint/sources/make_blur.ts +++ b/armorpaint/sources/make_blur.ts @@ -31,34 +31,34 @@ function make_blur_run(kong: node_shader_t) { 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 texpaint_sample: float4 = sample(texpaint_undo, texpaint_undo_sampler, tex_coord_inp2);"); + 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, texpaint_pack_undo_sampler, tex_coord_inp2) * 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, texpaint_nor_undo_sampler, 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};"); // 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, texpaint_undo_sampler, tex_coord_inp + float2(blur_step * float(i), 0.0));"); + 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, texpaint_pack_undo_sampler, tex_coord_inp + float2(blur_step * float(i), 0.0)) * 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, "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, texpaint_nor_undo_sampler, 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), 0.0)).rgb * blur_weight[i + 7];"); 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, texpaint_undo_sampler, tex_coord_inp + float2(0.0, blur_step * float(j)));"); + 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];"); diff --git a/armorpaint/sources/make_brush.ts b/armorpaint/sources/make_brush.ts index 433ff1b6..cc2f074d 100644 --- a/armorpaint/sources/make_brush.ts +++ b/armorpaint/sources/make_brush.ts @@ -14,7 +14,7 @@ function make_brush_run(kong: node_shader_t) { } if (config_raw.brush_3d) { - node_shader_write_frag(kong, "var depth: float = sample_lod(gbufferD, gbufferD_sampler, constants.inp.xy, 0.0).r;"); + 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"); node_shader_write_frag(kong, "var winp: float4 = float4(float2(constants.inp.x, 1.0 - constants.inp.y) * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);"); @@ -25,7 +25,7 @@ function make_brush_run(kong: node_shader_t) { if (config_raw.brush_angle_reject || context_raw.xray) { node_shader_add_function(kong, str_octahedron_wrap); node_shader_add_texture(kong, "gbuffer0"); - node_shader_write_frag(kong, "var g0: float2 = sample_lod(gbuffer0, gbuffer0_sampler, constants.inp.xy, 0.0).rg;"); + 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);"); @@ -41,7 +41,7 @@ function make_brush_run(kong: node_shader_t) { } } - node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, gbufferD_sampler, constants.inplast.xy, 0.0).r;"); + node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, sampler_linear, constants.inplast.xy, 0.0).r;"); node_shader_write_frag(kong, "var winplast: float4 = float4(float2(constants.inplast.x, 1.0 - constants.inplast.y) * 2.0 - 1.0, depthlast * 2.0 - 1.0, 1.0);"); node_shader_write_frag(kong, "winplast = constants.invVP * winplast;"); diff --git a/armorpaint/sources/make_clone.ts b/armorpaint/sources/make_clone.ts index 1ab6dda3..fc8cedb3 100644 --- a/armorpaint/sources/make_clone.ts +++ b/armorpaint/sources/make_clone.ts @@ -3,12 +3,12 @@ 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) * gbuffer_size)].ba;"); - node_shader_write_frag(kong, "var texpaint_pack_sample: float3 = sample_lod(texpaint_pack_undo, texpaint_pack_undo_sampler, tex_coord_inp, 0.0).rgb;"); - let base: string = "sample_lod(texpaint_undo, texpaint_undo_sampler, tex_coord_inp, 0.0).rgb"; + 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"; let rough: string = "texpaint_pack_sample.g"; let met: string = "texpaint_pack_sample.b"; let occ: string = "texpaint_pack_sample.r"; - let nortan: string = "sample_lod(texpaint_nor_undo, texpaint_nor_undo_sampler, tex_coord_inp, 0.0).rgb"; + let nortan: string = "sample_lod(texpaint_nor_undo, sampler_linear, tex_coord_inp, 0.0).rgb"; let height: string = "0.0"; let opac: string = "1.0"; node_shader_write_frag(kong, "var basecol: float3 = " + base + ";"); diff --git a/armorpaint/sources/make_colorid_picker.ts b/armorpaint/sources/make_colorid_picker.ts index 7c83086c..84206b2d 100644 --- a/armorpaint/sources/make_colorid_picker.ts +++ b/armorpaint/sources/make_colorid_picker.ts @@ -12,7 +12,7 @@ function make_colorid_picker_run(kong: node_shader_t) { if (context_raw.tool == workspace_tool_t.COLORID) { kong.frag_out = "float4"; node_shader_add_texture(kong, "texcolorid", "_texcolorid"); - node_shader_write_frag(kong, "var idcol: float3 = sample_lod(texcolorid, texcolorid_sampler, tex_coord_inp, 0.0).rgb;"); + node_shader_write_frag(kong, "var idcol: float3 = sample_lod(texcolorid, sampler_linear, tex_coord_inp, 0.0).rgb;"); node_shader_write_frag(kong, "output = float4(idcol, 1.0);"); } else if (context_raw.tool == workspace_tool_t.PICKER || context_raw.tool == workspace_tool_t.MATERIAL) { @@ -29,9 +29,9 @@ function make_colorid_picker_run(kong: node_shader_t) { node_shader_add_texture(kong, "texpaint"); node_shader_add_texture(kong, "texpaint_nor"); node_shader_add_texture(kong, "texpaint_pack"); - node_shader_write_frag(kong, "output[0] = sample_lod(texpaint, texpaint_sampler, tex_coord_inp, 0.0);"); - node_shader_write_frag(kong, "output[1] = sample_lod(texpaint_nor, texpaint_nor_sampler, tex_coord_inp, 0.0);"); - node_shader_write_frag(kong, "output[2] = sample_lod(texpaint_pack, texpaint_pack_sampler, tex_coord_inp, 0.0);"); + node_shader_write_frag(kong, "output[0] = sample_lod(texpaint, sampler_linear, tex_coord_inp, 0.0);"); + node_shader_write_frag(kong, "output[1] = sample_lod(texpaint_nor, sampler_linear, tex_coord_inp, 0.0);"); + node_shader_write_frag(kong, "output[2] = sample_lod(texpaint_pack, sampler_linear, tex_coord_inp, 0.0);"); node_shader_write_frag(kong, "output[3].rg = tex_coord_inp.xy;"); } } diff --git a/armorpaint/sources/make_discard.ts b/armorpaint/sources/make_discard.ts index 80be4e89..71e40b5e 100644 --- a/armorpaint/sources/make_discard.ts +++ b/armorpaint/sources/make_discard.ts @@ -3,7 +3,7 @@ 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, texcolorid_sampler, tex_coord_pick, 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, "if (any(colorid_c1 != colorid_c2)) { discard };"); node_shader_write_frag(kong, "if (colorid_c1 != colorid_c2) { discard; }"); } @@ -15,14 +15,14 @@ function make_discard_face(kong: node_shader_t) { 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, textrianglemap_sampler, tex_coord_pick, 0.0);"); + node_shader_write_frag(kong, "var face_c2: float4 = sample_lod(textrianglemap, sampler_linear, 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; }"); } 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, texuvislandmap_sampler, tex_coord_pick, 0.0).r == 0.0) { discard; }"); + node_shader_write_frag(kong, "if (sample_lod(texuvislandmap, sampler_linear, tex_coord_pick, 0.0).r == 0.0) { discard; }"); } function make_discard_material_id(kong: node_shader_t) { @@ -31,5 +31,5 @@ function make_discard_material_id(kong: node_shader_t) { node_shader_write_frag(kong, "picker_sample_tc.y = 1.0 - picker_sample_tc.y;"); node_shader_add_texture(kong, "texpaint_nor_undo", "_texpaint_nor_undo"); let matid: i32 = context_raw.materialid_picked / 255; - node_shader_write_frag(kong, "if (" + matid + " != sample_lod(texpaint_nor_undo, texpaint_nor_undo_sampler, picker_sample_tc, 0.0).a) { discard; }"); + node_shader_write_frag(kong, "if (" + matid + " != sample_lod(texpaint_nor_undo, sampler_linear, picker_sample_tc, 0.0).a) { discard; }"); } diff --git a/armorpaint/sources/make_material.ts b/armorpaint/sources/make_material.ts index 228324cd..1732cb91 100644 --- a/armorpaint/sources/make_material.ts +++ b/armorpaint/sources/make_material.ts @@ -69,15 +69,6 @@ function make_material_parse_mesh_material() { let con: node_shader_context_t = make_mesh_run(mm); let scon: shader_context_t = shader_context_create(con.data); - let override_context: _shader_override_t = {}; - if (con.kong.shared_samplers.length > 0) { - let sampler: string = con.kong.shared_samplers[0]; - override_context.shared_sampler = substring(sampler, string_last_index_of(sampler, " ") + 1, sampler.length); - } - if (!context_raw.texture_filter) { - override_context.filter = "point"; - } - scon._.override_context = override_context; array_push(m._.shader.contexts, scon); array_push(m._.shader._.contexts, scon); @@ -88,15 +79,7 @@ function make_material_parse_mesh_material() { }; let con: node_shader_context_t = make_mesh_run(mm, i); let scon: shader_context_t = shader_context_create(con.data); - let override_context: _shader_override_t = {}; - if (con.kong.shared_samplers.length > 0) { - let sampler: string = con.kong.shared_samplers[0]; - override_context.shared_sampler = substring(sampler, string_last_index_of(sampler, " ") + 1, sampler.length); - } - if (!context_raw.texture_filter) { - override_context.filter = "point"; - } - scon._.override_context = override_context; + array_push(m._.shader.contexts, scon); array_push(m._.shader._.contexts, scon); @@ -225,9 +208,6 @@ function make_material_parse_paint_material(bake_previews: bool = true) { if (compile_error) { return; } - let override_context: _shader_override_t = {}; - override_context.addressing = "repeat"; - scon._.override_context = override_context; let mcon: material_context_t = material_context_create(tmcon); array_push(m._.shader.contexts, scon); diff --git a/armorpaint/sources/make_mesh.ts b/armorpaint/sources/make_mesh.ts index 2aa6ff8f..458ea068 100644 --- a/armorpaint/sources/make_mesh.ts +++ b/armorpaint/sources/make_mesh.ts @@ -55,7 +55,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte num_layers++; texture_count++; node_shader_add_texture(kong, "texpaint_pack_vert" + l.id, "_texpaint_pack_vert" + l.id, true); - node_shader_write_vert(kong, "height += sample_lod(texpaint_pack_vert" + l.id + ", texpaint_pack_vert" + l.id + "_sampler, input.tex, 0.0).a;"); + node_shader_write_vert(kong, "height += sample_lod(texpaint_pack_vert" + l.id + ", sampler_linear, input.tex, 0.0).a;"); let masks: slot_layer_t[] = slot_layer_get_masks(l); if (masks != null) { for (let i: i32 = 0; i < masks.length; ++i) { @@ -65,7 +65,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } texture_count++; node_shader_add_texture(kong, "texpaint_vert" + m.id, "_texpaint_vert" + m.id); - node_shader_write_vert(kong, "height *= sample_lod(texpaint_vert" + m.id + ", texpaint_vert" + m.id + "_sampler, input.tex, 0.0).r;"); + node_shader_write_vert(kong, "height *= sample_lod(texpaint_vert" + m.id + ", sampler_linear, input.tex, 0.0).r;"); } } } @@ -83,7 +83,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte texture_count++; node_shader_add_texture(kong, "texcolorid", "_texcolorid"); node_shader_write_frag(kong, "output[0] = float4(n.xy, 1.0, pack_f32_i16(0.0, uint(0)));"); - node_shader_write_frag(kong, "var idcol: float3 = pow3(sample_lod(texcolorid, texcolorid_sampler, input.tex_coord, 0.0).rgb, float3(2.2, 2.2, 2.2));"); + node_shader_write_frag(kong, "var idcol: float3 = pow3(sample_lod(texcolorid, sampler_linear, input.tex_coord, 0.0).rgb, float3(2.2, 2.2, 2.2));"); node_shader_write_frag(kong, "output[1] = float4(idcol.rgb, 1.0);"); // occ } else { @@ -95,9 +95,9 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_add_texture(kong, "gbuffer2"); node_shader_write_frag(kong, "var fragcoord: float2 = (input.wvpposition.xy / input.wvpposition.w) * 0.5 + 0.5;"); node_shader_write_frag(kong, "fragcoord.y = 1.0 - fragcoord.y;"); - node_shader_write_frag(kong, "var gbuffer0_sample: float4 = sample_lod(gbuffer0, gbuffer0_sampler, fragcoord, 0.0);"); - node_shader_write_frag(kong, "var gbuffer1_sample: float4 = sample_lod(gbuffer1, gbuffer1_sampler, fragcoord, 0.0);"); - node_shader_write_frag(kong, "var gbuffer2_sample: float4 = sample_lod(gbuffer2, gbuffer2_sampler, fragcoord, 0.0);"); + node_shader_write_frag(kong, "var gbuffer0_sample: float4 = sample_lod(gbuffer0, sampler_linear, fragcoord, 0.0);"); + node_shader_write_frag(kong, "var gbuffer1_sample: float4 = sample_lod(gbuffer1, sampler_linear, fragcoord, 0.0);"); + node_shader_write_frag(kong, "var gbuffer2_sample: float4 = sample_lod(gbuffer2, sampler_linear, fragcoord, 0.0);"); node_shader_write_frag(kong, "var basecol: float3 = gbuffer0_sample.rgb;"); node_shader_write_frag(kong, "var roughness: float = gbuffer2_sample.g;"); node_shader_write_frag(kong, "var metallic: float = gbuffer2_sample.b;"); @@ -205,8 +205,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } } - node_shader_add_shared_sampler(kong, "texpaint" + l.id); - node_shader_write_frag(kong, "texpaint_sample = sample_lod(texpaint" + l.id + ", shared_sampler, input.tex_coord, 0.0);"); + node_shader_add_texture(kong, "texpaint" + l.id); + node_shader_write_frag(kong, "texpaint_sample = sample_lod(texpaint" + l.id + ", sampler_linear, input.tex_coord, 0.0);"); node_shader_write_frag(kong, "texpaint_opac = texpaint_sample.a;"); // ///if (arm_direct3d12 || arm_vulkan) // if (raw.viewport_mode == viewport_mode_t.LIT) { @@ -232,9 +232,9 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte if (!slot_layer_is_visible(m)) { continue; } - node_shader_add_shared_sampler(kong, "texpaint" + m.id); + node_shader_add_texture(kong, "texpaint" + m.id); node_shader_write_frag(kong, "{"); // Group mask is sampled across multiple layers - node_shader_write_frag(kong, "var texpaint_mask_sample" + m.id + ": float = sample_lod(texpaint" + m.id + ", shared_sampler, input.tex_coord, 0.0).r;"); + node_shader_write_frag(kong, "var texpaint_mask_sample" + m.id + ": float = sample_lod(texpaint" + m.id + ", sampler_linear, input.tex_coord, 0.0).r;"); let opac: f32 = slot_layer_get_opacity(m); let mask: string = make_material_blend_mode_mask(m.blending, texpaint_mask, "texpaint_mask_sample" + m.id, "float(" + opac + ")"); node_shader_write_frag(kong, texpaint_mask + " = " + mask + ";"); @@ -259,8 +259,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } if (l.paint_nor || make_material_emis_used) { - node_shader_add_shared_sampler(kong, "texpaint_nor" + l.id); - node_shader_write_frag(kong, "texpaint_nor_sample = sample_lod(texpaint_nor" + l.id + ", shared_sampler, input.tex_coord, 0.0);"); + node_shader_add_texture(kong, "texpaint_nor" + l.id); + node_shader_write_frag(kong, "texpaint_nor_sample = sample_lod(texpaint_nor" + l.id + ", sampler_linear, input.tex_coord, 0.0);"); if (make_material_emis_used) { node_shader_write_frag(kong, "if (texpaint_opac > 0.0) { matid = texpaint_nor_sample.a; }"); @@ -282,8 +282,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } if (l.paint_occ || l.paint_rough || l.paint_met || (l.paint_height && make_material_height_used)) { - node_shader_add_shared_sampler(kong, "texpaint_pack" + l.id); - node_shader_write_frag(kong, "texpaint_pack_sample = sample_lod(texpaint_pack" + l.id + ", shared_sampler, input.tex_coord, 0.0);"); + node_shader_add_texture(kong, "texpaint_pack" + l.id); + node_shader_write_frag(kong, "texpaint_pack_sample = sample_lod(texpaint_pack" + l.id + ", sampler_linear, input.tex_coord, 0.0);"); if (l.paint_occ) { node_shader_write_frag(kong, "occlusion = lerp(occlusion, texpaint_pack_sample.r, texpaint_opac);"); @@ -300,10 +300,10 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_write_frag(kong, "{"); node_shader_add_constant(kong, "texpaint_size: float2", "_texpaint_size"); node_shader_write_frag(kong, "var tex_step: float = 1.0 / constants.texpaint_size.x;"); - node_shader_write_frag(kong, "height0 " + assign + " sample_lod(texpaint_pack" + l.id + ", shared_sampler, float2(input.tex_coord.x - tex_step, input.tex_coord.y), 0.0).a * texpaint_opac;"); - node_shader_write_frag(kong, "height1 " + assign + " sample_lod(texpaint_pack" + l.id + ", shared_sampler, float2(input.tex_coord.x + tex_step, input.tex_coord.y), 0.0).a * texpaint_opac;"); - node_shader_write_frag(kong, "height2 " + assign + " sample_lod(texpaint_pack" + l.id + ", shared_sampler, float2(input.tex_coord.x, input.tex_coord.y - tex_step), 0.0).a * texpaint_opac;"); - node_shader_write_frag(kong, "height3 " + assign + " sample_lod(texpaint_pack" + l.id + ", shared_sampler, float2(input.tex_coord.x, input.tex_coord.y + tex_step), 0.0).a * texpaint_opac;"); + node_shader_write_frag(kong, "height0 " + assign + " sample_lod(texpaint_pack" + l.id + ", sampler_linear, float2(input.tex_coord.x - tex_step, input.tex_coord.y), 0.0).a * texpaint_opac;"); + node_shader_write_frag(kong, "height1 " + assign + " sample_lod(texpaint_pack" + l.id + ", sampler_linear, float2(input.tex_coord.x + tex_step, input.tex_coord.y), 0.0).a * texpaint_opac;"); + node_shader_write_frag(kong, "height2 " + assign + " sample_lod(texpaint_pack" + l.id + ", sampler_linear, float2(input.tex_coord.x, input.tex_coord.y - tex_step), 0.0).a * texpaint_opac;"); + node_shader_write_frag(kong, "height3 " + assign + " sample_lod(texpaint_pack" + l.id + ", sampler_linear, float2(input.tex_coord.x, input.tex_coord.y + tex_step), 0.0).a * texpaint_opac;"); node_shader_write_frag(kong, "}"); } } @@ -324,7 +324,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } if (last_pass && context_raw.draw_wireframe) { - node_shader_write_frag(kong, "var wireframe: float = sample_lod(texuvmap, texuvmap_sampler, input.tex_coord, 0.0).a;"); + node_shader_write_frag(kong, "var wireframe: float = sample_lod(texuvmap, sampler_linear, input.tex_coord, 0.0).a;"); node_shader_write_frag(kong, "basecol *= 1.0 - wireframe * 0.25;"); node_shader_write_frag(kong, "roughness = max(roughness, wireframe);"); } @@ -377,7 +377,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_write_frag(kong, "var wreflect: float3 = reflect(-vvec, n);"); node_shader_write_frag(kong, "var envlod: float = roughness * float(constants.envmap_num_mipmaps);"); node_shader_add_function(kong, str_envmap_equirect); - node_shader_write_frag(kong, "var prefiltered_color: float3 = sample_lod(senvmap_radiance, senvmap_radiance_sampler, envmap_equirect(wreflect, constants.envmap_data.x), envlod).rgb;"); + node_shader_write_frag(kong, "var prefiltered_color: float3 = sample_lod(senvmap_radiance, sampler_linear, envmap_equirect(wreflect, constants.envmap_data.x), envlod).rgb;"); // node_shader_add_constant(kong, "shirr: float4[7]", "_envmap_irradiance"); node_shader_add_constant(kong, "shirr0: float4", "_envmap_irradiance0"); node_shader_add_constant(kong, "shirr1: float4", "_envmap_irradiance1"); @@ -437,7 +437,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } else if (context_raw.viewport_mode == viewport_mode_t.MATERIAL_ID) { let id: i32 = context_raw.layer.id; - node_shader_add_shared_sampler(kong, "texpaint_nor" + id); + node_shader_add_texture(kong, "texpaint_nor" + id); node_shader_add_constant(kong, "texpaint_size: float2", "_texpaint_size"); node_shader_write_frag(kong, "var sample_matid: float = texpaint_nor" + id + "[uint2(input.tex_coord * constants.texpaint_size)].a + 1.0 / 255.0;"); node_shader_write_frag(kong, "var matid_r: float = frac(sin(dot(float2(sample_matid, sample_matid * 20.0), float2(12.9898, 78.233))) * 43758.5453);"); @@ -456,7 +456,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte else if (context_raw.viewport_mode == viewport_mode_t.MASK && (slot_layer_get_masks(context_raw.layer) != null || slot_layer_is_mask(context_raw.layer))) { if (slot_layer_is_mask(context_raw.layer)) { let id: i32 = context_raw.layer.id; - node_shader_write_frag(kong, "var mask_view: float = sample_lod(texpaint" + id + ", shared_sampler, input.tex_coord, 0.0).r;"); + node_shader_write_frag(kong, "var mask_view: float = sample_lod(texpaint" + id + ", sampler_linear, input.tex_coord, 0.0).r;"); } else { node_shader_write_frag(kong, "var mask_view: float = 0.0;"); @@ -465,7 +465,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte if (!slot_layer_is_visible(m)) { continue; } - node_shader_write_frag(kong, "var mask_sample" + m.id + ": float = sample_lod(texpaint_view_mask" + m.id + ", shared_sampler, input.tex_coord, 0.0).r;"); + node_shader_write_frag(kong, "var mask_sample" + m.id + ": float = sample_lod(texpaint_view_mask" + m.id + ", sampler_linear, input.tex_coord, 0.0).r;"); let opac: f32 = slot_layer_get_opacity(m); let mask: string = make_material_blend_mode_mask(m.blending, "mask_view", "mask_sample" + m.id, "float(" + opac + ")"); node_shader_write_frag(kong, "mask_view = " + mask + ";"); diff --git a/armorpaint/sources/make_mesh_preview.ts b/armorpaint/sources/make_mesh_preview.ts index 5ea2a9f2..246a8aba 100644 --- a/armorpaint/sources/make_mesh_preview.ts +++ b/armorpaint/sources/make_mesh_preview.ts @@ -86,7 +86,7 @@ function make_mesh_preview_run(data: material_t, matcon: material_context_t): no if (decal) { if (context_raw.tool == workspace_tool_t.TEXT) { node_shader_add_texture(kong, "textexttool", "_textexttool"); - node_shader_write_frag(kong, "opacity *= sample_lod(textexttool, textexttool_sampler, input.tex_coord / float(" + brush_scale + "), 0.0).r;"); + node_shader_write_frag(kong, "opacity *= sample_lod(textexttool, sampler_linear, input.tex_coord / float(" + brush_scale + "), 0.0).r;"); } } if (decal) { diff --git a/armorpaint/sources/make_paint.ts b/armorpaint/sources/make_paint.ts index 388963c5..3522b5c9 100644 --- a/armorpaint/sources/make_paint.ts +++ b/armorpaint/sources/make_paint.ts @@ -144,7 +144,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad } if (depth_reject) { - node_shader_write_frag(kong, "if (sp.z > sample_lod(gbufferD, gbufferD_sampler, sp.xy, 0.0).r + 0.0005) { discard; }"); + node_shader_write_frag(kong, "if (sp.z > sample_lod(gbufferD, sampler_linear, sp.xy, 0.0).r + 0.0005) { discard; }"); } make_brush_run(kong); @@ -155,7 +155,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad if (angle_fill) { node_shader_add_function(kong, str_octahedron_wrap); node_shader_add_texture(kong, "gbuffer0"); - node_shader_write_frag(kong, "var g0: float2 = sample_lod(gbuffer0, gbuffer0_sampler, constants.inp.xy, 0.0).rg;"); + 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);"); @@ -167,7 +167,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad } let stencil_fill: bool = context_raw.tool == workspace_tool_t.FILL && context_raw.brush_stencil_image != null; if (stencil_fill) { - node_shader_write_frag(kong, "if (sp.z > sample_lod(gbufferD, gbufferD_sampler, sp.xy, 0.0).r + 0.0005) { discard; }"); + node_shader_write_frag(kong, "if (sp.z > sample_lod(gbufferD, sampler_linear, sp.xy, 0.0).r + 0.0005) { discard; }"); } } @@ -260,7 +260,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad if (context_raw.brush_mask_image != null && context_raw.tool == workspace_tool_t.DECAL) { node_shader_add_texture(kong, "texbrushmask", "_texbrushmask"); - node_shader_write_frag(kong, "var mask_sample: float4 = sample_lod(texbrushmask, texbrushmask_sampler, uvsp, 0.0);"); + node_shader_write_frag(kong, "var mask_sample: float4 = sample_lod(texbrushmask, sampler_linear, uvsp, 0.0);"); if (context_raw.brush_mask_image_is_alpha) { node_shader_write_frag(kong, "opacity *= mask_sample.a;"); } @@ -270,7 +270,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad } else if (context_raw.tool == workspace_tool_t.TEXT) { node_shader_add_texture(kong, "textexttool", "_textexttool"); - node_shader_write_frag(kong, "opacity *= sample_lod(textexttool, textexttool_sampler, uvsp, 0.0).r;"); + node_shader_write_frag(kong, "opacity *= sample_lod(textexttool, sampler_linear, uvsp, 0.0).r;"); } if (context_raw.brush_stencil_image != null && ( @@ -294,7 +294,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad node_shader_write_frag(kong, "stencil_uv += float2(0.5 / stencil_ratio, 0.5);"); node_shader_write_frag(kong, "stencil_uv.x *= stencil_ratio;"); node_shader_write_frag(kong, "if (stencil_uv.x < 0 || stencil_uv.x > 1 || stencil_uv.y < 0 || stencil_uv.y > 1) { discard; }"); - node_shader_write_frag(kong, "var texbrushstencil_sample: float4 = sample_lod(texbrushstencil, texbrushstencil_sampler, stencil_uv, 0.0);"); + node_shader_write_frag(kong, "var texbrushstencil_sample: float4 = sample_lod(texbrushstencil, sampler_linear, stencil_uv, 0.0);"); if (context_raw.brush_stencil_image_is_alpha) { node_shader_write_frag(kong, "opacity *= texbrushstencil_sample.a;"); } @@ -325,7 +325,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad node_shader_write_frag(kong, "pa_mask *= distance(constants.eye, winp.xyz) / 1.5;"); } node_shader_write_frag(kong, "pa_mask = pa_mask.xy * 0.5 + 0.5;"); - node_shader_write_frag(kong, "var mask_sample: float4 = sample_lod(texbrushmask, texbrushmask_sampler, pa_mask, 0.0);"); + node_shader_write_frag(kong, "var mask_sample: float4 = sample_lod(texbrushmask, sampler_linear, pa_mask, 0.0);"); if (context_raw.brush_mask_image_is_alpha) { node_shader_write_frag(kong, "opacity *= mask_sample.a;"); } @@ -350,12 +350,12 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad node_shader_write_frag(kong, "var sample_tc: float2 = float2(input.wvpposition.xy / input.wvpposition.w) * 0.5 + 0.5;"); node_shader_write_frag(kong, "sample_tc.y = 1.0 - sample_tc.y;"); node_shader_add_texture(kong, "paintmask"); - node_shader_write_frag(kong, "var sample_mask: float = sample_lod(paintmask, paintmask_sampler, sample_tc, 0.0).r;"); + node_shader_write_frag(kong, "var sample_mask: float = sample_lod(paintmask, sampler_linear, sample_tc, 0.0).r;"); node_shader_write_frag(kong, "str = max(str, sample_mask);"); // write(frag, "str = clamp(str + sample_mask, 0.0, 1.0);"); node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); - node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, texpaint_undo_sampler, sample_tc, 0.0);"); + node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, sampler_linear, sample_tc, 0.0);"); let matid: f32 = context_raw.material.id / 255; if (context_raw.picker_mask_handle.position == picker_mask_t.MATERIAL) { @@ -409,7 +409,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad if (decal) { node_shader_add_texture(kong, "texpaint_pack_undo", "_texpaint_pack_undo"); - node_shader_write_frag(kong, "var sample_pack_undo: float4 = sample_lod(texpaint_pack_undo, texpaint_pack_undo_sampler, sample_tc, 0.0);"); + node_shader_write_frag(kong, "var sample_pack_undo: float4 = sample_lod(texpaint_pack_undo, sampler_linear, sample_tc, 0.0);"); node_shader_write_frag(kong, "output[2] = lerp4(sample_pack_undo, float4(occlusion, roughness, metallic, " + height + "), str);"); } else { @@ -425,8 +425,8 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad else { node_shader_add_texture(kong, "texpaint_nor_undo", "_texpaint_nor_undo"); node_shader_add_texture(kong, "texpaint_pack_undo", "_texpaint_pack_undo"); - node_shader_write_frag(kong, "var sample_nor_undo: float4 = sample_lod(texpaint_nor_undo, texpaint_nor_undo_sampler, sample_tc, 0.0);"); - node_shader_write_frag(kong, "var sample_pack_undo: float4 = sample_lod(texpaint_pack_undo, texpaint_pack_undo_sampler, sample_tc, 0.0);"); + node_shader_write_frag(kong, "var sample_nor_undo: float4 = sample_lod(texpaint_nor_undo, sampler_linear, sample_tc, 0.0);"); + node_shader_write_frag(kong, "var sample_pack_undo: float4 = sample_lod(texpaint_pack_undo, sampler_linear, sample_tc, 0.0);"); ///if is_forge node_shader_write_frag(kong, "output[0] = float4(" + make_material_blend_mode(kong, context_raw.brush_blending, "sample_undo.rgb", "basecol", "str") + ", mat_opacity);"); ///else diff --git a/armorsculpt/sources/make_brush.ts b/armorsculpt/sources/make_brush.ts index 7265a98b..27ebbf1b 100644 --- a/armorsculpt/sources/make_brush.ts +++ b/armorsculpt/sources/make_brush.ts @@ -4,7 +4,7 @@ function make_brush_run(kong: node_shader_t) { node_shader_write_frag(kong, "var dist: float = 0.0;"); if (config_raw.brush_3d) { - node_shader_write_frag(kong, "var depth: float = sample_lod(gbufferD, gbufferD_sampler, inp.xy, 0.0).r;"); + node_shader_write_frag(kong, "var depth: float = sample_lod(gbufferD, sampler_linear, inp.xy, 0.0).r;"); node_shader_add_constant(kong, "invVP: float4x4", "_inv_view_proj_matrix"); node_shader_write_frag(kong, "var winp: float4 = float4(float2(inp.x, 1.0 - inp.y) * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);"); @@ -17,7 +17,7 @@ function make_brush_run(kong: node_shader_t) { 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_frag(kong, "var depthlast: float = sample_lod(gbufferD, gbufferD_sampler, constants.inplast.xy, 0.0).r;"); + node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, sampler_linear, constants.inplast.xy, 0.0).r;"); node_shader_write_frag(kong, "var winplast: float4 = float4(float2(constants.inplast.x, 1.0 - constants.inplast.y) * 2.0 - 1.0, depthlast * 2.0 - 1.0, 1.0);"); node_shader_write_frag(kong, "winplast = constants.invVP * winplast;"); diff --git a/armorsculpt/sources/make_material.ts b/armorsculpt/sources/make_material.ts index 224d21a6..7e2dcd4e 100644 --- a/armorsculpt/sources/make_material.ts +++ b/armorsculpt/sources/make_material.ts @@ -65,15 +65,6 @@ function make_material_parse_mesh_material() { let mm: material_t = { name: "Material", canvas: null }; let con: node_shader_context_t = make_mesh_run(mm); let scon: shader_context_t = shader_context_create(con.data); - let override_context: _shader_override_t = {}; - if (con.kong.shared_samplers.length > 0) { - let sampler: string = con.kong.shared_samplers[0]; - override_context.shared_sampler = substring(sampler, string_last_index_of(sampler, " ") + 1, sampler.length); - } - if (!context_raw.texture_filter) { - override_context.filter = "point"; - } - scon._.override_context = override_context; array_push(m._.shader.contexts, scon); array_push(m._.shader._.contexts, scon); @@ -81,15 +72,6 @@ function make_material_parse_mesh_material() { let mm: material_t = { name: "Material", canvas: null }; let con: node_shader_context_t = make_mesh_run(mm, i); let scon: shader_context_t = shader_context_create(con.data); - let override_context: _shader_override_t = {}; - if (con.kong.shared_samplers.length > 0) { - let sampler: string = con.kong.shared_samplers[0]; - override_context.shared_sampler = substring(sampler, string_last_index_of(sampler, " ") + 1, sampler.length); - } - if (!context_raw.texture_filter) { - override_context.filter = "point"; - } - scon._.override_context = override_context; array_push(m._.shader.contexts, scon); array_push(m._.shader._.contexts, scon); @@ -202,9 +184,6 @@ function make_material_parse_paint_material(bake_previews: bool = true) { return; } - let override_context: _shader_override_t = {}; - override_context.addressing = "repeat"; - scon2._.override_context = override_context; let mcon3: material_context_t = material_context_create(mcon2); array_push(m._.shader.contexts, scon2); diff --git a/armorsculpt/sources/make_mesh.ts b/armorsculpt/sources/make_mesh.ts index a88a38ac..0453e6fa 100644 --- a/armorsculpt/sources/make_mesh.ts +++ b/armorsculpt/sources/make_mesh.ts @@ -41,7 +41,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte let lid: i32 = project_layers[0].id; node_shader_add_texture(kong, "texpaint_vert", "_texpaint_vert" + lid, true); node_shader_add_constant(kong, "texpaint_vert_size: float2", "_size(texpaint_vert" + lid + ")"); - node_shader_write_vert(kong, "var meshpos: float3 = sample_lod(texpaint_vert, texpaint_vert_sampler, uint2(vertex_id() % constants.texpaint_vert_size.x, vertex_id() / constants.texpaint_vert_size.y), 0).xyz;"); + node_shader_write_vert(kong, "var meshpos: float3 = sample_lod(texpaint_vert, sampler_linear, uint2(vertex_id() % constants.texpaint_vert_size.x, vertex_id() / constants.texpaint_vert_size.y), 0).xyz;"); // + input.pos.xyz * 0.000001 node_shader_write_vert(kong, "output.pos = constants.WVP * float4(meshpos.xyz, 1.0);"); @@ -55,9 +55,9 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_write_attrib_vert(kong, "var base_vertex0: int = vertex_id() - (vertex_id() % 3);"); node_shader_write_attrib_vert(kong, "var base_vertex1: int = base_vertex0 + 1;"); node_shader_write_attrib_vert(kong, "var base_vertex2: int = base_vertex0 + 2;"); - node_shader_write_attrib_vert(kong, "var meshpos0: float3 = sample_lod(texpaint_vert, texpaint_vert_sampler, uint2(base_vertex0 % constants.texpaint_vert_size.x, base_vertex0 / constants.texpaint_vert_size.y), 0).xyz;"); - node_shader_write_attrib_vert(kong, "var meshpos1: float3 = sample_lod(texpaint_vert, texpaint_vert_sampler, uint2(base_vertex1 % constants.texpaint_vert_size.x, base_vertex1 / constants.texpaint_vert_size.y), 0).xyz;"); - node_shader_write_attrib_vert(kong, "var meshpos2: float3 = sample_lod(texpaint_vert, texpaint_vert_sampler, uint2(base_vertex2 % constants.texpaint_vert_size.x, base_vertex2 / constants.texpaint_vert_size.y), 0).xyz;"); + node_shader_write_attrib_vert(kong, "var meshpos0: float3 = sample_lod(texpaint_vert, sampler_linear, uint2(base_vertex0 % constants.texpaint_vert_size.x, base_vertex0 / constants.texpaint_vert_size.y), 0).xyz;"); + node_shader_write_attrib_vert(kong, "var meshpos1: float3 = sample_lod(texpaint_vert, sampler_linear, uint2(base_vertex1 % constants.texpaint_vert_size.x, base_vertex1 / constants.texpaint_vert_size.y), 0).xyz;"); + node_shader_write_attrib_vert(kong, "var meshpos2: float3 = sample_lod(texpaint_vert, sampler_linear, uint2(base_vertex2 % constants.texpaint_vert_size.x, base_vertex2 / constants.texpaint_vert_size.y), 0).xyz;"); node_shader_write_attrib_vert(kong, "var meshnor: float3 = normalize(cross(meshpos2 - meshpos1, meshpos0 - meshpos1));"); node_shader_write_attrib_vert(kong, "output.wnormal = constants.N * meshnor;"); node_shader_write_attrib_frag(kong, "var n: float3 = normalize(input.wnormal);"); @@ -71,9 +71,9 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_add_texture(kong, "gbuffer2"); node_shader_write_frag(kong, "var fragcoord: float2 = (input.wvpposition.xy / input.wvpposition.w) * 0.5 + 0.5;"); node_shader_write_frag(kong, "fragcoord.y = 1.0 - fragcoord.y;"); - node_shader_write_frag(kong, "var gbuffer0_sample: float4 = sample_lod(gbuffer0, gbuffer0_sampler, fragcoord, 0.0);"); - node_shader_write_frag(kong, "var gbuffer1_sample: float4 = sample_lod(gbuffer1, gbuffer1_sampler, fragcoord, 0.0);"); - node_shader_write_frag(kong, "var gbuffer2_sample: float4 = sample_lod(gbuffer2, gbuffer2_sampler, fragcoord, 0.0);"); + node_shader_write_frag(kong, "var gbuffer0_sample: float4 = sample_lod(gbuffer0, sampler_linear, fragcoord, 0.0);"); + node_shader_write_frag(kong, "var gbuffer1_sample: float4 = sample_lod(gbuffer1, sampler_linear, fragcoord, 0.0);"); + node_shader_write_frag(kong, "var gbuffer2_sample: float4 = sample_lod(gbuffer2, sampler_linear, fragcoord, 0.0);"); node_shader_write_frag(kong, "var basecol: float3 = gbuffer0_sample.rgb;"); node_shader_write_frag(kong, "var roughness: float = gbuffer2_sample.g;"); node_shader_write_frag(kong, "var metallic: float = gbuffer2_sample.b;"); @@ -165,7 +165,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } } - node_shader_add_shared_sampler(kong, "texpaint" + l.id); + node_shader_add_texture(kong, "texpaint" + l.id); node_shader_write_frag(kong, "texpaint_sample = float4(0.8, 0.8, 0.8, 1.0);"); node_shader_write_frag(kong, "texpaint_opac = texpaint_sample.a;"); @@ -185,9 +185,9 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte for (let i: i32 = 0; i < masks.length; ++i) { let m: slot_layer_t = masks[i]; if (!slot_layer_is_visible(m)) continue; - node_shader_add_shared_sampler(kong, "texpaint" + m.id); + node_shader_add_texture(kong, "texpaint" + m.id); node_shader_write_frag(kong, "{"); // Group mask is sampled across multiple layers - node_shader_write_frag(kong, "var texpaint_mask_sample" + m.id + ": float = sample_lod(texpaint" + m.id + ", shared_sampler, input.tex_coord, 0.0).r;"); + node_shader_write_frag(kong, "var texpaint_mask_sample" + m.id + ": float = sample_lod(texpaint" + m.id + ", sampler_liniear, input.tex_coord, 0.0).r;"); node_shader_write_frag(kong, "}"); } node_shader_write_frag(kong, "texpaint_opac *= clamp(" + texpaint_mask + ", 0.0, 1.0);"); @@ -218,7 +218,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } if (last_pass && context_raw.draw_wireframe) { - node_shader_write_frag(kong, "basecol *= 1.0 - sample_lod(texuvmap, texuvmap_sampler, input.tex_coord, 0.0).r;"); + node_shader_write_frag(kong, "basecol *= 1.0 - sample_lod(texuvmap, sampler_linear, input.tex_coord, 0.0).r;"); } if (make_material_height_used) { @@ -270,7 +270,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_write_frag(kong, "var wreflect: float3 = reflect(-vvec, n);"); node_shader_write_frag(kong, "var envlod: float = roughness * float(constants.envmap_num_mipmaps);"); node_shader_add_function(kong, str_envmap_equirect); - node_shader_write_frag(kong, "var prefiltered_color: float3 = sample_lod(senvmap_radiance, senvmap_radiance_sampler, envmap_equirect(wreflect, constants.envmap_data.x), envlod).rgb;"); + node_shader_write_frag(kong, "var prefiltered_color: float3 = sample_lod(senvmap_radiance, sampler_linear, envmap_equirect(wreflect, constants.envmap_data.x), envlod).rgb;"); // node_shader_add_constant(kong, "shirr: float4[7]", "_envmap_irradiance"); node_shader_add_constant(kong, "shirr0: float4", "_envmap_irradiance0"); node_shader_add_constant(kong, "shirr1: float4", "_envmap_irradiance1"); diff --git a/armorsculpt/sources/make_mesh_preview.ts b/armorsculpt/sources/make_mesh_preview.ts index 2892aa0b..97c4b411 100644 --- a/armorsculpt/sources/make_mesh_preview.ts +++ b/armorsculpt/sources/make_mesh_preview.ts @@ -91,7 +91,7 @@ function make_mesh_preview_run(data: material_t, matcon: material_context_t): no if (decal) { if (context_raw.tool == workspace_tool_t.TEXT) { node_shader_add_texture(kong, "textexttool", "_textexttool"); - node_shader_write_frag(kong, "opacity *= sample_lod(textexttool, textexttool_sampler, input.tex_coord / float(" + brush_scale + "), 0.0).r;"); + node_shader_write_frag(kong, "opacity *= sample_lod(textexttool, sampler_linear, input.tex_coord / float(" + brush_scale + "), 0.0).r;"); } } if (decal) { diff --git a/armorsculpt/sources/make_sculpt.ts b/armorsculpt/sources/make_sculpt.ts index c9e9ea72..667de280 100644 --- a/armorsculpt/sources/make_sculpt.ts +++ b/armorsculpt/sources/make_sculpt.ts @@ -68,13 +68,13 @@ function make_sculpt_run(data: material_t, matcon: material_context_t): node_sha node_shader_write_frag(kong, "var str: float = clamp((constants.brush_radius - dist) * constants.brush_hardness * 400.0, 0.0, 1.0) * opacity;"); node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); - node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, texpaint_undo_sampler, input.tex_coord, 0.0);"); + node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, sampler_linear, input.tex_coord, 0.0);"); node_shader_write_frag(kong, "if (sample_undo.r == 0 && sample_undo.g == 0 && sample_undo.b == 0) { discard; }"); node_shader_add_function(kong, str_octahedron_wrap); node_shader_add_texture(kong, "gbuffer0_undo"); - node_shader_write_frag(kong, "var g0_undo: float2 = sample_lod(gbuffer0_undo, gbuffer0_undo_sampler, constants.inp.xy, 0.0).rg;"); + node_shader_write_frag(kong, "var g0_undo: float2 = sample_lod(gbuffer0_undo, 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_undo.x) - abs(g0_undo.y);"); // node_shader_write_frag(kong, "wn.xy = wn.z >= 0.0 ? g0_undo.xy : octahedron_wrap(g0_undo.xy);"); diff --git a/base/assets/Scene.arm b/base/assets/Scene.arm index 2b81f85d658e33a2cffab5ba583945a3290c2e44..a1f4c4fc8ae3805868539be16b247d3ea5dae0cc 100644 GIT binary patch delta 26 icmaF)o@>&3u7(!IEldlRGqOxyxSUC6yUGftqx=A(T?*R( delta 113 zcmbRAp6lg%u7(!IEldlRGjdK}xSUBRjE8}Np)@`*C8a2}xHvN}{lIOINEwO<7f>WO kGcP_ZGp8iA=)i3-KQSH7=LO3bimpl.currentTextures[i] = NULL; - list->impl.current_samplers[i] = NULL; } list->impl.heapIndex = 0; @@ -472,13 +414,6 @@ void iron_gpu_command_list_init(struct iron_gpu_command_list *list) { .Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, }; device->lpVtbl->CreateDescriptorHeap(device, &heapDesc, &IID_ID3D12DescriptorHeap, &list->impl.srvHeap); - - D3D12_DESCRIPTOR_HEAP_DESC samplerHeapDesc = { - .NumDescriptors = HEAP_SIZE, - .Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, - .Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, - }; - device->lpVtbl->CreateDescriptorHeap(device, &samplerHeapDesc, &IID_ID3D12DescriptorHeap, &list->impl.samplerHeap); } void iron_gpu_command_list_destroy(struct iron_gpu_command_list *list) {} @@ -486,7 +421,6 @@ void iron_gpu_command_list_destroy(struct iron_gpu_command_list *list) {} void iron_gpu_internal_reset_textures(struct iron_gpu_command_list *list) { for (int i = 0; i < IRON_INTERNAL_G5_TEXTURE_COUNT; ++i) { list->impl.currentTextures[i] = NULL; - list->impl.current_samplers[i] = NULL; } } @@ -574,7 +508,7 @@ void iron_gpu_command_list_render_target_to_texture_barrier(struct iron_gpu_comm } void iron_gpu_command_list_set_vertex_constant_buffer(struct iron_gpu_command_list *list, iron_gpu_buffer_t *buffer, int offset, size_t size) { - list->impl._commandList->lpVtbl->SetGraphicsRootConstantBufferView(list->impl._commandList, 2, buffer->impl.constant_buffer->lpVtbl->GetGPUVirtualAddress(buffer->impl.constant_buffer) + offset); + list->impl._commandList->lpVtbl->SetGraphicsRootConstantBufferView(list->impl._commandList, 1, buffer->impl.constant_buffer->lpVtbl->GetGPUVirtualAddress(buffer->impl.constant_buffer) + offset); } void iron_gpu_command_list_draw_indexed_vertices(struct iron_gpu_command_list *list) { @@ -636,7 +570,6 @@ void iron_gpu_command_list_disable_scissor(struct iron_gpu_command_list *list) { void iron_gpu_internal_set_textures(iron_gpu_command_list_t *list) { if (list->impl.currentTextures[0] != NULL) { int srvStep = device->lpVtbl->GetDescriptorHandleIncrementSize(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); - int samplerStep = device->lpVtbl->GetDescriptorHandleIncrementSize(device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); if (list->impl.heapIndex + IRON_INTERNAL_G5_TEXTURE_COUNT >= HEAP_SIZE) { list->impl.heapIndex = 0; @@ -644,26 +577,17 @@ void iron_gpu_internal_set_textures(iron_gpu_command_list_t *list) { D3D12_GPU_DESCRIPTOR_HANDLE srvGpu; list->impl.srvHeap->lpVtbl->GetGPUDescriptorHandleForHeapStart(list->impl.srvHeap, &srvGpu); - D3D12_GPU_DESCRIPTOR_HANDLE samplerGpu; - list->impl.samplerHeap->lpVtbl->GetGPUDescriptorHandleForHeapStart(list->impl.samplerHeap, &samplerGpu); srvGpu.ptr += list->impl.heapIndex * srvStep; - samplerGpu.ptr += list->impl.heapIndex * samplerStep; for (int i = 0; i < IRON_INTERNAL_G5_TEXTURE_COUNT; ++i) { - if (list->impl.currentTextures[i] != NULL && list->impl.current_samplers[i] != NULL) { - ID3D12DescriptorHeap *samplerDescriptorHeap = list->impl.current_samplers[i]->impl.sampler_heap; - + if (list->impl.currentTextures[i] != NULL) { D3D12_CPU_DESCRIPTOR_HANDLE srvCpu; list->impl.srvHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart(list->impl.srvHeap, &srvCpu); - D3D12_CPU_DESCRIPTOR_HANDLE samplerCpu; - list->impl.samplerHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart(list->impl.samplerHeap, &samplerCpu); srvCpu.ptr += list->impl.heapIndex * srvStep; - samplerCpu.ptr += list->impl.heapIndex * samplerStep; ++list->impl.heapIndex; bool is_depth = list->impl.currentTextures[i]->impl.stage_depth == i; D3D12_CPU_DESCRIPTOR_HANDLE sourceCpu; - if (is_depth) { list->impl.currentTextures[i]->impl.srvDepthDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart( list->impl.currentTextures[i]->impl.srvDepthDescriptorHeap, &sourceCpu); @@ -672,19 +596,13 @@ void iron_gpu_internal_set_textures(iron_gpu_command_list_t *list) { list->impl.currentTextures[i]->impl.srvDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart( list->impl.currentTextures[i]->impl.srvDescriptorHeap, &sourceCpu); } - - D3D12_CPU_DESCRIPTOR_HANDLE handle; - samplerDescriptorHeap->lpVtbl->GetCPUDescriptorHandleForHeapStart(samplerDescriptorHeap, &handle); - device->lpVtbl->CopyDescriptorsSimple(device, 1, srvCpu, sourceCpu, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); - device->lpVtbl->CopyDescriptorsSimple(device, 1, samplerCpu, handle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); } } - ID3D12DescriptorHeap *heaps[2] = {list->impl.srvHeap, list->impl.samplerHeap}; - list->impl._commandList->lpVtbl->SetDescriptorHeaps(list->impl._commandList, 2, heaps); + ID3D12DescriptorHeap *heaps[1] = {list->impl.srvHeap}; + list->impl._commandList->lpVtbl->SetDescriptorHeaps(list->impl._commandList, 1, heaps); list->impl._commandList->lpVtbl->SetGraphicsRootDescriptorTable(list->impl._commandList, 0, srvGpu); - list->impl._commandList->lpVtbl->SetGraphicsRootDescriptorTable(list->impl._commandList, 1, samplerGpu); } } @@ -904,23 +822,6 @@ void iron_gpu_command_list_get_render_target_pixels(iron_gpu_command_list_t *lis render_target->impl.renderTargetReadback->lpVtbl->Unmap(render_target->impl.renderTargetReadback, 0, NULL); } -void iron_gpu_internal_sampler_set(iron_gpu_command_list_t *list, iron_gpu_sampler_t *sampler, int unit) { - if (unit < 0) { - return; - } - list->impl.current_samplers[unit] = sampler; -} - -void iron_gpu_command_list_set_sampler(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_sampler_t *sampler) { - if (unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT] >= 0) { - iron_gpu_internal_sampler_set(list, sampler, unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT]); - } - else if (unit.stages[IRON_GPU_SHADER_TYPE_VERTEX] >= 0) { - iron_gpu_internal_sampler_set(list, sampler, unit.stages[IRON_GPU_SHADER_TYPE_VERTEX]); - } - iron_gpu_internal_set_textures(list); -} - void iron_gpu_command_list_set_texture(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_texture_t *texture) { if (unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT] >= 0) { texture->impl.stage = unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT]; @@ -1112,32 +1013,6 @@ void iron_gpu_pipeline_compile(iron_gpu_pipeline_t *pipe) { device->lpVtbl->CreateGraphicsPipelineState(device, &psoDesc, &IID_ID3D12PipelineState, &pipe->impl.pso); } -void iron_gpu_sampler_init(iron_gpu_sampler_t *sampler, const iron_gpu_sampler_options_t *options) { - D3D12_DESCRIPTOR_HEAP_DESC descHeapSampler = { - .NumDescriptors = 2, - .Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, - .Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE, - }; - device->lpVtbl->CreateDescriptorHeap(device, &descHeapSampler, &IID_ID3D12DescriptorHeap, &sampler->impl.sampler_heap); - - D3D12_SAMPLER_DESC samplerDesc = { - .Filter = convert_filter(options->minification_filter, options->magnification_filter, options->mipmap_filter), - .AddressU = convert_texture_addressing(options->u_addressing), - .AddressV = convert_texture_addressing(options->v_addressing), - .AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP, - .MinLOD = 0, - .MaxLOD = 32, - .MipLODBias = 0.0f, - .MaxAnisotropy = 1, - .ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER, - }; - D3D12_CPU_DESCRIPTOR_HANDLE handle; - sampler->impl.sampler_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(sampler->impl.sampler_heap, &handle); - device->lpVtbl->CreateSampler(device, &samplerDesc, handle); -} - -void iron_gpu_sampler_destroy(iron_gpu_sampler_t *sampler) {} - void iron_gpu_shader_init(iron_gpu_shader_t *shader, const void *_data, size_t length, iron_gpu_shader_type_t type) { memset(shader->impl.constants, 0, sizeof(shader->impl.constants)); memset(shader->impl.attributes, 0, sizeof(shader->impl.attributes)); diff --git a/base/sources/backends/direct3d12_gpu.h b/base/sources/backends/direct3d12_gpu.h index fc8374ab..7841070e 100644 --- a/base/sources/backends/direct3d12_gpu.h +++ b/base/sources/backends/direct3d12_gpu.h @@ -17,7 +17,6 @@ struct ID3D12RootSignature; struct ID3D12StateObject; struct iron_gpu_pipeline; struct iron_gpu_texture; -struct iron_gpu_sampler; struct iron_gpu_shader; struct iron_gpu_command_list; struct iron_gpu_buffer; @@ -68,11 +67,9 @@ typedef struct { HANDLE fence_event; struct iron_gpu_texture *currentTextures[IRON_INTERNAL_G5_TEXTURE_COUNT]; - struct iron_gpu_sampler *current_samplers[IRON_INTERNAL_G5_TEXTURE_COUNT]; int heapIndex; struct ID3D12DescriptorHeap *srvHeap; - struct ID3D12DescriptorHeap *samplerHeap; } gpu_command_list_impl_t; typedef struct { @@ -84,10 +81,6 @@ typedef struct { int vertexOffset; } gpu_constant_location_impl_t; -typedef struct iron_gpu_sampler_impl { - struct ID3D12DescriptorHeap *sampler_heap; -} gpu_sampler_impl_t; - typedef struct { char name[64]; uint32_t offset; diff --git a/base/sources/backends/metal_gpu.h b/base/sources/backends/metal_gpu.h index 4022c8a6..636a1304 100644 --- a/base/sources/backends/metal_gpu.h +++ b/base/sources/backends/metal_gpu.h @@ -25,10 +25,6 @@ typedef struct { int vertexOffset; } gpu_constant_location_impl_t; -typedef struct iron_gpu_sampler_impl { - void *sampler; -} gpu_sampler_impl_t; - typedef struct { char name[1024]; void *mtlFunction; diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index 990163d0..f535ff78 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -491,18 +491,6 @@ void iron_gpu_command_list_set_texture_from_render_target_depth(iron_gpu_command } } -void iron_gpu_command_list_set_sampler(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_sampler_t *sampler) { - id encoder = getMetalEncoder(); - id mtl_sampler = (__bridge id)sampler->impl.sampler; - - if (unit.stages[IRON_GPU_SHADER_TYPE_VERTEX] >= 0) { - [encoder setVertexSamplerState:mtl_sampler atIndex:unit.stages[IRON_GPU_SHADER_TYPE_VERTEX]]; - } - if (unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT] >= 0) { - [encoder setFragmentSamplerState:mtl_sampler atIndex:unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT]]; - } -} - static MTLBlendFactor convert_blending_factor(iron_gpu_blending_factor_t factor) { switch (factor) { case IRON_GPU_BLEND_ONE: @@ -836,72 +824,6 @@ iron_gpu_texture_unit_t iron_gpu_pipeline_get_texture_unit(iron_gpu_pipeline_t * return unit; } -static MTLSamplerAddressMode convert_addressing(iron_gpu_texture_addressing_t mode) { - switch (mode) { - case IRON_GPU_TEXTURE_ADDRESSING_REPEAT: - return MTLSamplerAddressModeRepeat; - case IRON_GPU_TEXTURE_ADDRESSING_BORDER: - return MTLSamplerAddressModeClampToBorderColor; - case IRON_GPU_TEXTURE_ADDRESSING_CLAMP: - return MTLSamplerAddressModeClampToEdge; - case IRON_GPU_TEXTURE_ADDRESSING_MIRROR: - return MTLSamplerAddressModeMirrorRepeat; - default: - assert(false); - return MTLSamplerAddressModeRepeat; - } -} - -static MTLSamplerMipFilter convert_mipmap_mode(iron_gpu_mipmap_filter_t filter) { - switch (filter) { - case IRON_GPU_MIPMAP_FILTER_NONE: - return MTLSamplerMipFilterNotMipmapped; - case IRON_GPU_MIPMAP_FILTER_POINT: - return MTLSamplerMipFilterNearest; - case IRON_GPU_MIPMAP_FILTER_LINEAR: - return MTLSamplerMipFilterLinear; - default: - assert(false); - return MTLSamplerMipFilterNearest; - } -} - -static MTLSamplerMinMagFilter convert_texture_filter(iron_gpu_texture_filter_t filter) { - switch (filter) { - case IRON_GPU_TEXTURE_FILTER_POINT: - return MTLSamplerMinMagFilterNearest; - case IRON_GPU_TEXTURE_FILTER_LINEAR: - return MTLSamplerMinMagFilterLinear; - case IRON_GPU_TEXTURE_FILTER_ANISOTROPIC: - return MTLSamplerMinMagFilterLinear; // ? - default: - assert(false); - return MTLSamplerMinMagFilterNearest; - } -} - -void iron_gpu_sampler_init(iron_gpu_sampler_t *sampler, const iron_gpu_sampler_options_t *options) { - id device = getMetalDevice(); - - MTLSamplerDescriptor *desc = (MTLSamplerDescriptor *)[[MTLSamplerDescriptor alloc] init]; - desc.minFilter = convert_texture_filter(options->minification_filter); - desc.magFilter = convert_texture_filter(options->magnification_filter); - desc.sAddressMode = convert_addressing(options->u_addressing); - desc.tAddressMode = convert_addressing(options->v_addressing); - desc.mipFilter = convert_mipmap_mode(options->mipmap_filter); - desc.maxAnisotropy = 1; - desc.normalizedCoordinates = YES; - desc.lodMinClamp = 0; - desc.lodMaxClamp = 32; - - sampler->impl.sampler = (__bridge_retained void *)[device newSamplerStateWithDescriptor:desc]; -} - -void iron_gpu_sampler_destroy(iron_gpu_sampler_t *sampler) { - id mtl_sampler = (__bridge_transfer id)sampler->impl.sampler; - mtl_sampler = nil; -} - void iron_gpu_shader_destroy(iron_gpu_shader_t *shader) { id function = (__bridge_transfer id)shader->impl.mtlFunction; function = nil; diff --git a/base/sources/backends/vulkan_gpu.c b/base/sources/backends/vulkan_gpu.c index 36cd4317..bedbdffa 100644 --- a/base/sources/backends/vulkan_gpu.c +++ b/base/sources/backends/vulkan_gpu.c @@ -33,13 +33,6 @@ static iron_gpu_texture_t *vulkan_textures[16] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; -static VkSampler vulkan_samplers[16] = { - VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, - VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, - VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, - VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE -}; - static iron_gpu_texture_t *current_render_targets[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; @@ -2060,12 +2053,6 @@ void iron_gpu_command_list_wait_for_execution_to_finish(iron_gpu_command_list_t vkWaitForFences(vk_ctx.device, 1, &list->impl.fence, VK_TRUE, UINT64_MAX); } -void iron_gpu_command_list_set_sampler(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_sampler_t *sampler) { - if (unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT] >= 0) { - vulkan_samplers[unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler; - } -} - void iron_gpu_command_list_set_texture(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_texture_t *texture) { if (unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT] >= 0) { texture->impl.stage = unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT]; @@ -2715,70 +2702,6 @@ void iron_gpu_shader_destroy(iron_gpu_shader_t *shader) { shader->impl.source = NULL; } -static VkSamplerAddressMode convert_addressing(iron_gpu_texture_addressing_t mode) { - switch (mode) { - case IRON_GPU_TEXTURE_ADDRESSING_REPEAT: - return VK_SAMPLER_ADDRESS_MODE_REPEAT; - case IRON_GPU_TEXTURE_ADDRESSING_BORDER: - return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; - case IRON_GPU_TEXTURE_ADDRESSING_CLAMP: - return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - case IRON_GPU_TEXTURE_ADDRESSING_MIRROR: - return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; - default: - return VK_SAMPLER_ADDRESS_MODE_REPEAT; - } -} - -static VkSamplerMipmapMode convert_mipmap_mode(iron_gpu_mipmap_filter_t filter) { - switch (filter) { - case IRON_GPU_MIPMAP_FILTER_NONE: - case IRON_GPU_MIPMAP_FILTER_POINT: - return VK_SAMPLER_MIPMAP_MODE_NEAREST; - case IRON_GPU_MIPMAP_FILTER_LINEAR: - return VK_SAMPLER_MIPMAP_MODE_LINEAR; - default: - return VK_SAMPLER_MIPMAP_MODE_NEAREST; - } -} - -static VkFilter convert_texture_filter(iron_gpu_texture_filter_t filter) { - switch (filter) { - case IRON_GPU_TEXTURE_FILTER_POINT: - return VK_FILTER_NEAREST; - case IRON_GPU_TEXTURE_FILTER_LINEAR: - return VK_FILTER_LINEAR; - case IRON_GPU_TEXTURE_FILTER_ANISOTROPIC: - return VK_FILTER_LINEAR; // ? - default: - return VK_FILTER_NEAREST; - } -} - -void iron_gpu_sampler_init(iron_gpu_sampler_t *sampler, const iron_gpu_sampler_options_t *options) { - VkSamplerCreateInfo info = { - .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, - .pNext = NULL, - .flags = 0, - .addressModeU = convert_addressing(options->u_addressing), - .addressModeV = convert_addressing(options->v_addressing), - .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, - .mipmapMode = convert_mipmap_mode(options->mipmap_filter), - .magFilter = convert_texture_filter(options->magnification_filter), - .minFilter = convert_texture_filter(options->minification_filter), - .anisotropyEnable = (options->magnification_filter == IRON_GPU_TEXTURE_FILTER_ANISOTROPIC || options->minification_filter == IRON_GPU_TEXTURE_FILTER_ANISOTROPIC), - .maxAnisotropy = 1, - .maxLod = 32, - .minLod = 0, - }; - - vkCreateSampler(vk_ctx.device, &info, NULL, &sampler->impl.sampler); -} - -void iron_gpu_sampler_destroy(iron_gpu_sampler_t *sampler) { - vkDestroySampler(vk_ctx.device, sampler->impl.sampler, NULL); -} - static void prepare_texture_image(uint8_t *tex_colors, uint32_t width, uint32_t height, gpu_texture_impl_t *tex_obj, VkImageTiling tiling, VkImageUsageFlags usage, VkFlags required_props, VkDeviceSize *deviceSize, VkFormat tex_format) { diff --git a/base/sources/backends/vulkan_gpu.h b/base/sources/backends/vulkan_gpu.h index d8122fa2..307d6630 100644 --- a/base/sources/backends/vulkan_gpu.h +++ b/base/sources/backends/vulkan_gpu.h @@ -140,10 +140,6 @@ typedef struct { int length; } gpu_shader_impl_t; -typedef struct iron_gpu_sampler_impl { - VkSampler sampler; -} gpu_sampler_impl_t; - typedef struct { VkImageLayout imageLayout; VkDeviceSize deviceSize; diff --git a/base/sources/backends/webgpu_gpu.c b/base/sources/backends/webgpu_gpu.c index a22a0e75..0b76ecef 100644 --- a/base/sources/backends/webgpu_gpu.c +++ b/base/sources/backends/webgpu_gpu.c @@ -343,10 +343,6 @@ void iron_gpu_pipeline_compile(iron_gpu_pipeline_t *pipe) { pipe->impl.pipeline = wgpuDeviceCreateRenderPipeline(device, &rpDesc); } -void iron_gpu_sampler_init(iron_gpu_sampler_t *sampler, const iron_gpu_sampler_options_t *options) {} - -void iron_gpu_sampler_destroy(iron_gpu_sampler_t *sampler) {} - void iron_gpu_shader_init(iron_gpu_shader_t *shader, const void *source, size_t length, iron_gpu_shader_type_t type) { WGPUShaderModuleSPIRVDescriptor smSpirvDesc; memset(&smSpirvDesc, 0, sizeof(smSpirvDesc)); @@ -361,18 +357,6 @@ void iron_gpu_shader_init(iron_gpu_shader_t *shader, const void *source, size_t void iron_gpu_shader_destroy(iron_gpu_shader_t *shader) {} - - - - -#include -#include -#include - -extern WGPUDevice device; -extern WGPUQueue queue; -extern WGPUSwapChain swapChain; - void iron_gpu_command_list_init(iron_gpu_command_list_t *list) {} void iron_gpu_command_list_destroy(iron_gpu_command_list_t *list) {} @@ -476,6 +460,4 @@ void iron_gpu_command_list_set_texture(iron_gpu_command_list_t *list, iron_gpu_t } -void iron_gpu_command_list_set_sampler(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_sampler_t *sampler) {} - void iron_gpu_command_list_set_texture_from_render_target_depth(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_texture_t *renderTarget) {} diff --git a/base/sources/backends/webgpu_gpu.h b/base/sources/backends/webgpu_gpu.h index 2835932e..649c4886 100644 --- a/base/sources/backends/webgpu_gpu.h +++ b/base/sources/backends/webgpu_gpu.h @@ -22,10 +22,6 @@ typedef struct { int vertexOffset; } gpu_constant_location_impl_t; -typedef struct iron_gpu_sampler_impl { - int a; -} gpu_sampler_impl_t; - struct WGPUShaderModuleImpl; typedef struct { diff --git a/base/sources/iron.h b/base/sources/iron.h index 0e4e8244..ca4529dd 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -1257,14 +1257,6 @@ iron_gpu_texture_unit_t *gpu_get_texture_unit(iron_gpu_pipeline_t *pipeline, str return unit_copy; } -void gpu_set_texture_parameters(iron_gpu_texture_unit_t *unit, i32 u_addr, i32 v_addr, i32 min_filter, i32 mag_filter, i32 mip_filter) { - gpu_set_texture_addressing(*unit, GPU_TEXTURE_DIRECTION_U, (gpu_texture_addressing_t)u_addr); - gpu_set_texture_addressing(*unit, GPU_TEXTURE_DIRECTION_V, (gpu_texture_addressing_t)v_addr); - gpu_set_texture_minification_filter(*unit, (gpu_texture_filter_t)min_filter); - gpu_set_texture_magnification_filter(*unit, (gpu_texture_filter_t)mag_filter); - gpu_set_texture_mipmap_filter(*unit, (gpu_mipmap_filter_t)mip_filter); -} - void iron_set_window_title(string_t *title) { iron_window_set_title(title); #if defined(IRON_IOS) || defined(IRON_ANDROID) diff --git a/base/sources/iron_draw.c b/base/sources/iron_draw.c index c897eb71..96b0cf66 100644 --- a/base/sources/iron_draw.c +++ b/base/sources/iron_draw.c @@ -358,12 +358,6 @@ void draw_image_buffer(bool end) { gpu_set_vertex_buffer(&image_vertex_buffer); gpu_set_index_buffer(&image_index_buffer); gpu_set_texture(&image_tex_unit, image_last_texture); - gpu_set_texture_addressing(image_tex_unit, GPU_TEXTURE_DIRECTION_U, GPU_TEXTURE_ADDRESSING_CLAMP); - gpu_set_texture_addressing(image_tex_unit, GPU_TEXTURE_DIRECTION_V, GPU_TEXTURE_ADDRESSING_CLAMP); - // gpu_set_texture_mipmap_filter(image_tex_unit, draw_bilinear_filter ? GPU_MIPMAP_FILTER_LINEAR : GPU_MIPMAP_FILTER_NONE); - gpu_set_texture_mipmap_filter(image_tex_unit, GPU_MIPMAP_FILTER_NONE); - gpu_set_texture_minification_filter(image_tex_unit, draw_bilinear_filter ? GPU_TEXTURE_FILTER_LINEAR : GPU_TEXTURE_FILTER_POINT); - gpu_set_texture_magnification_filter(image_tex_unit, draw_bilinear_filter ? GPU_TEXTURE_FILTER_LINEAR : GPU_TEXTURE_FILTER_POINT); iron_gpu_draw_indexed_vertices_from_to(image_buffer_start * 2 * 3, (image_buffer_index - image_buffer_start) * 2 * 3); if (end || image_buffer_index + 1 >= DRAW_BUFFER_SIZE) { @@ -680,11 +674,6 @@ void draw_text_draw_buffer(bool end) { gpu_set_vertex_buffer(&text_vertex_buffer); gpu_set_index_buffer(&text_index_buffer); gpu_set_texture(&text_tex_unit, text_last_texture); - gpu_set_texture_addressing(text_tex_unit, GPU_TEXTURE_DIRECTION_U, GPU_TEXTURE_ADDRESSING_CLAMP); - gpu_set_texture_addressing(text_tex_unit, GPU_TEXTURE_DIRECTION_V, GPU_TEXTURE_ADDRESSING_CLAMP); - gpu_set_texture_mipmap_filter(text_tex_unit, GPU_MIPMAP_FILTER_NONE); - gpu_set_texture_minification_filter(text_tex_unit, draw_bilinear_filter ? GPU_TEXTURE_FILTER_LINEAR : GPU_TEXTURE_FILTER_POINT); - gpu_set_texture_magnification_filter(text_tex_unit, draw_bilinear_filter ? GPU_TEXTURE_FILTER_LINEAR : GPU_TEXTURE_FILTER_POINT); iron_gpu_draw_indexed_vertices_from_to(text_buffer_start * 2 * 3, (text_buffer_index - text_buffer_start) * 2 * 3); if (end || text_buffer_index + 1 >= DRAW_BUFFER_SIZE) { diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index 6e3955d2..29b74b00 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -10,21 +10,6 @@ #define CONSTANT_BUFFER_MULTIPLY 100 #define FRAMEBUFFER_COUNT 2 #define MAX_TEXTURES 16 -#define MAX_SAMPLERS_PER_STAGE 16 -#define MAX_SAMPLER_CACHE_SIZE 256 - -static iron_gpu_sampler_options_t sampler_options[IRON_GPU_SHADER_TYPE_COUNT][MAX_SAMPLERS_PER_STAGE]; - -struct sampler_cache_entry { - iron_gpu_sampler_options_t options; - iron_gpu_sampler_t sampler; -}; - -static struct sampler_cache_entry sampler_cache[MAX_SAMPLER_CACHE_SIZE]; -static int sampler_cache_size = 0; - -void iron_internal_samplers_reset(void); -iron_gpu_sampler_t *iron_internal_get_current_sampler(int stage, int unit); iron_gpu_command_list_t commandList; bool waitAfterNextDraw = false; @@ -67,7 +52,6 @@ typedef struct render_state { int depth_render_target_count; uint8_t vertex_constant_data[CONSTANT_BUFFER_SIZE]; - uint8_t fragment_constant_data[CONSTANT_BUFFER_SIZE]; } render_state; static render_state current_state; @@ -107,31 +91,11 @@ void gpu_internal_init_window(int depthBufferBits, bool vsync) { iron_gpu_command_list_begin(&commandList); } -void iron_gpu_internal_set_samplers(int count, iron_gpu_texture_unit_t *texture_units) { - for (int i = 0; i < count; ++i) { - for (int j = 0; j < IRON_GPU_SHADER_TYPE_COUNT; ++j) { - if (texture_units[i].stages[j] >= 0) { - iron_gpu_sampler_t *sampler = iron_internal_get_current_sampler(j, texture_units[i].stages[j]); - iron_gpu_texture_unit_t unit; - for (int k = 0; k < IRON_GPU_SHADER_TYPE_COUNT; ++k) { - unit.stages[k] = -1; - } - unit.stages[j] = texture_units[i].stages[j]; - iron_gpu_command_list_set_sampler(&commandList, unit, sampler); - } - } - } -} - static void iron_internal_start_draw(bool compute) { if ((constantBufferIndex + 1) >= CONSTANT_BUFFER_MULTIPLY || waitAfterNextDraw) { memcpy(current_state.vertex_constant_data, vertexConstantBuffer.data, CONSTANT_BUFFER_SIZE); } iron_gpu_constant_buffer_unlock(&vertexConstantBuffer); - - iron_gpu_internal_set_samplers(current_state.texture_count, current_state.texture_units); - iron_gpu_internal_set_samplers(current_state.depth_render_target_count, current_state.depth_render_target_units); - iron_gpu_command_list_set_vertex_constant_buffer(&commandList, &vertexConstantBuffer, constantBufferIndex * CONSTANT_BUFFER_SIZE, CONSTANT_BUFFER_SIZE); } @@ -253,8 +217,6 @@ void gpu_begin() { current_state.texture_count = 0; current_state.depth_render_target_count = 0; - iron_internal_samplers_reset(); - iron_gpu_command_list_begin(&commandList); // Currently we do not necessarily wait at the end of a frame so for now it's iron_internal_end_draw @@ -411,43 +373,6 @@ void gpu_set_matrix3(iron_gpu_constant_location_t *location, iron_matrix3x3_t va } } -void gpu_set_texture_addressing(iron_gpu_texture_unit_t unit, gpu_texture_direction_t dir, gpu_texture_addressing_t addressing) { - for (int i = 0; i < IRON_GPU_SHADER_TYPE_COUNT; ++i) { - if (unit.stages[i] >= 0) { - if (dir == GPU_TEXTURE_DIRECTION_U) { - sampler_options[i][unit.stages[i]].u_addressing = (iron_gpu_texture_addressing_t)addressing; - } - if (dir == GPU_TEXTURE_DIRECTION_V) { - sampler_options[i][unit.stages[i]].v_addressing = (iron_gpu_texture_addressing_t)addressing; - } - } - } -} - -void gpu_set_texture_magnification_filter(iron_gpu_texture_unit_t texunit, gpu_texture_filter_t filter) { - for (int i = 0; i < IRON_GPU_SHADER_TYPE_COUNT; ++i) { - if (texunit.stages[i] >= 0) { - sampler_options[i][texunit.stages[i]].magnification_filter = (iron_gpu_texture_filter_t)filter; - } - } -} - -void gpu_set_texture_minification_filter(iron_gpu_texture_unit_t texunit, gpu_texture_filter_t filter) { - for (int i = 0; i < IRON_GPU_SHADER_TYPE_COUNT; ++i) { - if (texunit.stages[i] >= 0) { - sampler_options[i][texunit.stages[i]].minification_filter = (iron_gpu_texture_filter_t)filter; - } - } -} - -void gpu_set_texture_mipmap_filter(iron_gpu_texture_unit_t texunit, gpu_mipmap_filter_t filter) { - for (int i = 0; i < IRON_GPU_SHADER_TYPE_COUNT; ++i) { - if (texunit.stages[i] >= 0) { - sampler_options[i][texunit.stages[i]].mipmap_filter = (iron_gpu_mipmap_filter_t)filter; - } - } -} - void gpu_restore_render_target(void) { iron_gpu_internal_restore_render_target(); current_state.viewport_set = false; @@ -607,45 +532,3 @@ void iron_gpu_internal_pipeline_init(iron_gpu_pipeline_t *pipe) { pipe->color_attachment_count = 1; pipe->depth_attachment_bits = 0; } - -void iron_gpu_sampler_options_set_defaults(iron_gpu_sampler_options_t *options) { - options->u_addressing = IRON_GPU_TEXTURE_ADDRESSING_CLAMP; - options->v_addressing = IRON_GPU_TEXTURE_ADDRESSING_CLAMP; - - options->magnification_filter = IRON_GPU_TEXTURE_FILTER_POINT; - options->minification_filter = IRON_GPU_TEXTURE_FILTER_POINT; - options->mipmap_filter = IRON_GPU_MIPMAP_FILTER_POINT; -} - -void iron_internal_samplers_reset(void) { - for (int i = 0; i < IRON_GPU_SHADER_TYPE_COUNT; ++i) { - for (int j = 0; j < MAX_SAMPLERS_PER_STAGE; ++j) { - iron_gpu_sampler_options_set_defaults(&sampler_options[i][j]); - } - } -} - -bool sampler_options_equals(iron_gpu_sampler_options_t *options1, iron_gpu_sampler_options_t *options2) { - return options1->u_addressing == options2->u_addressing && - options1->v_addressing == options2->v_addressing && - options1->minification_filter == options2->minification_filter && - options1->magnification_filter == options2->magnification_filter && - options1->mipmap_filter == options2->mipmap_filter; -} - -iron_gpu_sampler_t *iron_internal_get_current_sampler(int stage, int unit) { - // TODO: Please make this much faster - for (int i = 0; i < sampler_cache_size; ++i) { - if (sampler_options_equals(&sampler_cache[i].options, &sampler_options[stage][unit])) { - return &sampler_cache[i].sampler; - } - } - - assert(sampler_cache_size < MAX_SAMPLER_CACHE_SIZE); - iron_gpu_sampler_t *sampler = &sampler_cache[sampler_cache_size].sampler; - iron_gpu_sampler_init(sampler, &sampler_options[stage][unit]); - sampler_cache[sampler_cache_size].options = sampler_options[stage][unit]; - sampler_cache_size += 1; - - return sampler; -} diff --git a/base/sources/iron_gpu.h b/base/sources/iron_gpu.h index f0940a86..d221c127 100644 --- a/base/sources/iron_gpu.h +++ b/base/sources/iron_gpu.h @@ -73,30 +73,6 @@ struct iron_gpu_texture_unit; struct iron_gpu_constant_location; struct iron_gpu_buffer; -typedef enum { - GPU_TEXTURE_ADDRESSING_REPEAT, - GPU_TEXTURE_ADDRESSING_MIRROR, - GPU_TEXTURE_ADDRESSING_CLAMP, - GPU_TEXTURE_ADDRESSING_BORDER -} gpu_texture_addressing_t; - -typedef enum { - GPU_TEXTURE_DIRECTION_U, - GPU_TEXTURE_DIRECTION_V -} gpu_texture_direction_t; - -typedef enum { - GPU_TEXTURE_FILTER_POINT, - GPU_TEXTURE_FILTER_LINEAR, - GPU_TEXTURE_FILTER_ANISOTROPIC -} gpu_texture_filter_t; - -typedef enum { - GPU_MIPMAP_FILTER_NONE, - GPU_MIPMAP_FILTER_POINT, - GPU_MIPMAP_FILTER_LINEAR // linear texture filter + linear mip filter -> trilinear filter -} gpu_mipmap_filter_t; - typedef enum { GPU_USAGE_STATIC, GPU_USAGE_DYNAMIC, @@ -111,7 +87,6 @@ void gpu_scissor(int x, int y, int width, int height); void gpu_disable_scissor(void); void iron_gpu_draw_indexed_vertices(void); void iron_gpu_draw_indexed_vertices_from_to(int start, int count); -void gpu_set_texture_addressing(struct iron_gpu_texture_unit unit, gpu_texture_direction_t dir, gpu_texture_addressing_t addressing); void iron_gpu_set_pipeline(struct iron_gpu_pipeline *pipeline); void gpu_set_int(struct iron_gpu_constant_location *location, int value); void gpu_set_int2(struct iron_gpu_constant_location *location, int value1, int value2); @@ -126,9 +101,6 @@ void gpu_set_floats(struct iron_gpu_constant_location *location, f32_array_t *va void gpu_set_bool(struct iron_gpu_constant_location *location, bool value); void gpu_set_matrix3(struct iron_gpu_constant_location *location, iron_matrix3x3_t value); void gpu_set_matrix4(struct iron_gpu_constant_location *location, iron_matrix4x4_t value); -void gpu_set_texture_magnification_filter(struct iron_gpu_texture_unit unit, gpu_texture_filter_t filter); -void gpu_set_texture_minification_filter(struct iron_gpu_texture_unit unit, gpu_texture_filter_t filter); -void gpu_set_texture_mipmap_filter(struct iron_gpu_texture_unit unit, gpu_mipmap_filter_t filter); void gpu_restore_render_target(void); void gpu_set_render_targets(struct iron_gpu_texture **targets, int count); void gpu_set_texture(struct iron_gpu_texture_unit *unit, struct iron_gpu_texture *texture); @@ -297,25 +269,6 @@ typedef enum iron_gpu_compare_mode { IRON_GPU_COMPARE_MODE_GREATER_EQUAL } iron_gpu_compare_mode_t; -typedef enum iron_gpu_texture_addressing { - IRON_GPU_TEXTURE_ADDRESSING_REPEAT, - IRON_GPU_TEXTURE_ADDRESSING_MIRROR, - IRON_GPU_TEXTURE_ADDRESSING_CLAMP, - IRON_GPU_TEXTURE_ADDRESSING_BORDER -} iron_gpu_texture_addressing_t; - -typedef enum iron_gpu_texture_filter { - IRON_GPU_TEXTURE_FILTER_POINT, - IRON_GPU_TEXTURE_FILTER_LINEAR, - IRON_GPU_TEXTURE_FILTER_ANISOTROPIC -} iron_gpu_texture_filter_t; - -typedef enum iron_gpu_mipmap_filter { - IRON_GPU_MIPMAP_FILTER_NONE, - IRON_GPU_MIPMAP_FILTER_POINT, - IRON_GPU_MIPMAP_FILTER_LINEAR // linear texture filter + linear mip filter -> trilinear filter -} iron_gpu_mipmap_filter_t; - typedef struct iron_gpu_constant_location { gpu_constant_location_impl_t impl; } iron_gpu_constant_location_t; @@ -357,20 +310,6 @@ typedef struct iron_gpu_pipeline { gpu_pipeline_impl_t impl; } iron_gpu_pipeline_t; -typedef struct iron_gpu_sampler_options { - iron_gpu_texture_addressing_t u_addressing; - iron_gpu_texture_addressing_t v_addressing; - - iron_gpu_texture_filter_t minification_filter; - iron_gpu_texture_filter_t magnification_filter; - iron_gpu_mipmap_filter_t mipmap_filter; - -} iron_gpu_sampler_options_t; - -typedef struct iron_gpu_sampler { - gpu_sampler_impl_t impl; -} iron_gpu_sampler_t; - void iron_gpu_pipeline_init(iron_gpu_pipeline_t *pipeline); void iron_gpu_internal_pipeline_init(iron_gpu_pipeline_t *pipeline); void iron_gpu_pipeline_destroy(iron_gpu_pipeline_t *pipeline); @@ -381,10 +320,6 @@ iron_gpu_texture_unit_t iron_gpu_pipeline_get_texture_unit(iron_gpu_pipeline_t * void iron_gpu_shader_init(iron_gpu_shader_t *shader, const void *source, size_t length, iron_gpu_shader_type_t type); void iron_gpu_shader_destroy(iron_gpu_shader_t *shader); -void iron_gpu_sampler_options_set_defaults(iron_gpu_sampler_options_t *options); -void iron_gpu_sampler_init(iron_gpu_sampler_t *sampler, const iron_gpu_sampler_options_t *options); -void iron_gpu_sampler_destroy(iron_gpu_sampler_t *sampler); - struct iron_gpu_pipeline; struct iron_gpu_texture; struct iron_gpu_command_list; @@ -421,7 +356,6 @@ void iron_gpu_command_list_wait_for_execution_to_finish(iron_gpu_command_list_t void iron_gpu_command_list_get_render_target_pixels(iron_gpu_command_list_t *list, struct iron_gpu_texture *render_target, uint8_t *data); void iron_gpu_command_list_set_texture(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_texture_t *texture); void iron_gpu_command_list_set_texture_from_render_target_depth(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_texture_t *target); -void iron_gpu_command_list_set_sampler(iron_gpu_command_list_t *list, iron_gpu_texture_unit_t unit, iron_gpu_sampler_t *sampler); void iron_gpu_render_target_get_pixels(iron_gpu_texture_t *render_target, uint8_t *data); diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index 7aa23eb1..1dc19613 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -244,7 +244,6 @@ declare function gpu_get_constant_location(pipeline: any, name: string): any; declare function gpu_get_texture_unit(pipeline: any, name: string): any; declare function gpu_set_texture(stage: any, texture: any): void; declare function gpu_set_texture_depth(unit: any, texture: any): void; -declare function gpu_set_texture_parameters(tex_unit: any, u_addr: i32, v_addr: i32, min_filter: i32, mag_filter: i32, mip_filter: i32): void; declare function gpu_set_bool(location: any, value: bool): void; declare function gpu_set_int(location: any, value: i32): void; declare function gpu_set_float(location: any, value: f32): void; @@ -646,24 +645,6 @@ enum clear_flag_t { DEPTH = 2, } -enum tex_filter_t { - POINT, - LINEAR, - ANISOTROPIC, -} - -enum mip_map_filter_t { - NONE, - POINT, - LINEAR, -} - -enum tex_addressing_t { - REPEAT, - MIRROR, - CLAMP, -} - enum usage_t { STATIC, DYNAMIC, diff --git a/base/sources/ts/iron/material_data.ts b/base/sources/ts/iron/material_data.ts index d4ff0041..ac806aaa 100644 --- a/base/sources/ts/iron/material_data.ts +++ b/base/sources/ts/iron/material_data.ts @@ -109,8 +109,3 @@ function material_context_create(raw: material_context_t): material_context_t { return raw; } - -function material_context_set_tex_params(raw: material_context_t, texture_index: i32, context: shader_context_t, unit_index: i32) { - // This function is called by mesh_object_t for samplers set using material context - shader_context_set_tex_params(context, unit_index, raw.bind_textures[texture_index]); -} diff --git a/base/sources/ts/iron/scene.ts b/base/sources/ts/iron/scene.ts index 0decc726..10fdeec4 100644 --- a/base/sources/ts/iron/scene.ts +++ b/base/sources/ts/iron/scene.ts @@ -553,11 +553,6 @@ type bind_const_t = { type bind_tex_t = { name?: string; file?: string; - u_addressing?: string; - v_addressing?: string; - min_filter?: string; - mag_filter?: string; - mipmap_filter?: string; generate_mipmaps?: bool; mipmaps?: string[]; // Reference image names }; @@ -602,16 +597,9 @@ type shader_context_runtime_t = { pipe_state?: iron_gpu_pipeline_t; constants?: iron_gpu_constant_location_t[]; tex_units?: iron_gpu_texture_unit_t[]; - override_context?: _shader_override_t; structure?: iron_gpu_vertex_structure_t; }; -type _shader_override_t = { - addressing?: string; - filter?: string; - shared_sampler?: string; -}; - type vertex_element_t = { name?: string; data?: string; // "short4norm", "short2norm" diff --git a/base/sources/ts/iron/shader_data.ts b/base/sources/ts/iron/shader_data.ts index 531315c5..e1a6a583 100644 --- a/base/sources/ts/iron/shader_data.ts +++ b/base/sources/ts/iron/shader_data.ts @@ -317,36 +317,6 @@ function shader_context_get_blend_fac(s: string): blend_factor_t { return blend_factor_t.BLEND_ONE; } -function shader_context_get_tex_addresing(s: string): tex_addressing_t { - if (s == "repeat") { - return tex_addressing_t.REPEAT; - } - if (s == "mirror") { - return tex_addressing_t.MIRROR; - } - return tex_addressing_t.CLAMP; -} - -function shader_context_get_tex_filter(s: string): tex_filter_t { - if (s == "point") { - return tex_filter_t.POINT; - } - if (s == "linear") { - return tex_filter_t.LINEAR; - } - return tex_filter_t.ANISOTROPIC; -} - -function shader_context_get_mipmap_filter(s: string): mip_map_filter_t { - if (s == "no") { - return mip_map_filter_t.NONE; - } - if (s == "point") { - return mip_map_filter_t.POINT; - } - return mip_map_filter_t.LINEAR; -} - function shader_context_get_tex_format(s: string): tex_format_t { if (s == "RGBA32") { return tex_format_t.RGBA32; @@ -388,14 +358,3 @@ function shader_context_add_tex(raw: shader_context_t, tu: tex_unit_t, i: i32) { array_push(raw._.tex_units, unit); } - -function shader_context_set_tex_params(raw: shader_context_t, unit_index: i32, tex: bind_tex_t) { - // This function is called for samplers set using material context - let unit: any = raw._.tex_units[unit_index]; - gpu_set_texture_parameters(unit, - tex.u_addressing == null ? tex_addressing_t.REPEAT : shader_context_get_tex_addresing(tex.u_addressing), - tex.v_addressing == null ? tex_addressing_t.REPEAT : shader_context_get_tex_addresing(tex.v_addressing), - tex.min_filter == null ? tex_filter_t.LINEAR : shader_context_get_tex_filter(tex.min_filter), - tex.mag_filter == null ? tex_filter_t.LINEAR : shader_context_get_tex_filter(tex.mag_filter), - tex.mipmap_filter == null ? mip_map_filter_t.NONE : shader_context_get_mipmap_filter(tex.mipmap_filter)); -} diff --git a/base/sources/ts/iron/uniforms.ts b/base/sources/ts/iron/uniforms.ts index 51a97299..63e8b859 100644 --- a/base/sources/ts/iron/uniforms.ts +++ b/base/sources/ts/iron/uniforms.ts @@ -58,20 +58,17 @@ function uniforms_set_context_consts(context: shader_context_t, bind_params: str if (char_at(tulink, 0) == "$") { // Link to embedded data gpu_set_texture(context._.tex_units[j], map_get(scene_embedded, substring(tulink, 1, tulink.length))); - gpu_set_texture_parameters(context._.tex_units[j], tex_addressing_t.REPEAT, tex_addressing_t.REPEAT, tex_filter_t.LINEAR, tex_filter_t.LINEAR, mip_map_filter_t.NONE); } else if (tulink == "_envmap_radiance") { let w: world_data_t = scene_world; if (w != null) { gpu_set_texture(context._.tex_units[j], w._.radiance); - gpu_set_texture_parameters(context._.tex_units[j], tex_addressing_t.REPEAT, tex_addressing_t.REPEAT, tex_filter_t.LINEAR, tex_filter_t.LINEAR, mip_map_filter_t.LINEAR); } } else if (tulink == "_envmap") { let w: world_data_t = scene_world; if (w != null) { gpu_set_texture(context._.tex_units[j], w._.envmap); - gpu_set_texture_parameters(context._.tex_units[j], tex_addressing_t.REPEAT, tex_addressing_t.REPEAT, tex_filter_t.LINEAR, tex_filter_t.LINEAR, mip_map_filter_t.NONE); } } } @@ -101,7 +98,6 @@ function uniforms_set_obj_consts(context: shader_context_t, object: object_t) { ends_with(tu.link, "_depth") ? gpu_set_texture_depth(context._.tex_units[j], image) : gpu_set_texture(context._.tex_units[j], image); - gpu_set_texture_parameters(context._.tex_units[j], tex_addressing_t.REPEAT, tex_addressing_t.REPEAT, tex_filter_t.LINEAR, tex_filter_t.LINEAR, mip_map_filter_t.NONE); } } } @@ -114,41 +110,14 @@ function uniforms_bind_render_target(rt: render_target_t, context: shader_contex } let tus: tex_unit_t[] = context.texture_units; - for (let j: i32 = 0; j < tus.length; ++j) { // Set texture if (sampler_id == tus[j].name) { - if (attach_depth) { gpu_set_texture_depth(context._.tex_units[j], rt._image); // sampler2D } else { gpu_set_texture(context._.tex_units[j], rt._image); // sampler2D } - - if (rt.mipmaps) { - gpu_set_texture_parameters(context._.tex_units[j], tex_addressing_t.CLAMP, tex_addressing_t.CLAMP, tex_filter_t.LINEAR, tex_filter_t.LINEAR, mip_map_filter_t.LINEAR); - continue; - } - - if (starts_with(rt.name, "bloom")) { - // Use bilinear filter for bloom mips to get correct blur - gpu_set_texture_parameters(context._.tex_units[j], tex_addressing_t.CLAMP, tex_addressing_t.CLAMP, tex_filter_t.LINEAR, tex_filter_t.LINEAR, mip_map_filter_t.NONE); - continue; - } - - if (attach_depth) { - gpu_set_texture_parameters(context._.tex_units[j], tex_addressing_t.CLAMP, tex_addressing_t.CLAMP, tex_filter_t.POINT, tex_filter_t.POINT, mip_map_filter_t.NONE); - continue; - } - - // No filtering when sampling render targets - let oc: _shader_override_t = context._.override_context; - let allow_params: bool = oc == null || oc.shared_sampler == null || oc.shared_sampler == sampler_id; - if (allow_params) { - let addressing: tex_addressing_t = (oc != null && oc.addressing == "repeat") ? tex_addressing_t.REPEAT : tex_addressing_t.CLAMP; - let filter: tex_filter_t = (oc != null && oc.filter == "point") ? tex_filter_t.POINT : tex_filter_t.LINEAR; - gpu_set_texture_parameters(context._.tex_units[j], addressing, addressing, filter, filter, mip_map_filter_t.NONE); - } } } } @@ -592,8 +561,6 @@ function uniforms_set_material_consts(context: shader_context_t, material_contex let sname: string = context.texture_units[j].name; if (mname == sname) { gpu_set_texture(context._.tex_units[j], material_context._.textures[i]); - // After texture sampler have been assigned, set texture parameters - material_context_set_tex_params(material_context, i, context, j); break; } } diff --git a/base/sources/ts/node_shader.ts b/base/sources/ts/node_shader.ts index 085a45de..4929b733 100644 --- a/base/sources/ts/node_shader.ts +++ b/base/sources/ts/node_shader.ts @@ -4,7 +4,6 @@ type node_shader_t = { ins?: string[]; outs?: string[]; frag_out?: string; - shared_samplers?: string[]; constants?: string[]; textures?: string[]; functions?: map_t; @@ -43,7 +42,6 @@ function node_shader_create(context: node_shader_context_t): node_shader_t { raw.ins = []; raw.outs = []; raw.frag_out = "float4"; - raw.shared_samplers = []; raw.constants = []; raw.textures = []; raw.functions = map_create(); @@ -102,17 +100,6 @@ function node_shader_add_texture(raw: node_shader_t, s: string, link: string = n } } -function node_shader_add_shared_sampler(raw: node_shader_t, s: string) { - // mytex: tex2d - if (array_index_of(raw.shared_samplers, s) == -1) { - array_push(raw.shared_samplers, s); - let ar: string[] = string_split(s, ": "); - let uname: string = ar[0]; - let utype: string = ar[1]; - node_shader_context_add_texture_unit(raw.context, utype, uname, null, false); - } -} - function node_shader_add_function(raw: node_shader_t, s: string) { let fname: string = string_split(s, "(")[0]; if (map_get(raw.functions, fname) != null) { @@ -209,18 +196,11 @@ function node_shader_get(raw: node_shader_t): string { let a: string = raw.textures[i]; s += "#[set(everything)]\n"; s += "const " + a + ": tex2d;\n"; - s += "#[set(everything)]\n"; - s += "const " + a + "_sampler: sampler;\n\n"; } - for (let i: i32 = 0; i < raw.shared_samplers.length; ++i) { - let a: string = raw.shared_samplers[i]; + if (raw.textures.length > 0) { s += "#[set(everything)]\n"; - s += "const " + a + ": tex2d;\n"; - } - if (raw.shared_samplers.length > 0) { - s += "#[set(everything)]\n"; - s += "const shared_sampler: sampler;\n\n"; + s += "const sampler_linear: sampler;\n\n"; } let keys: string[] = map_keys(raw.functions); diff --git a/base/sources/ts/parser_material.ts b/base/sources/ts/parser_material.ts index 344b11f6..0f3f9735 100644 --- a/base/sources/ts/parser_material.ts +++ b/base/sources/ts/parser_material.ts @@ -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 + ", " + tex_name + "_sampler, + tex_coord + float2(" + store + "_x, " + store + "_y) * " + mask + ").rgb;"; + return "sample(" + tex_name + ", sampler_linear, + 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 + ", " + tex_name + "_sampler, tex_coord + float2(i, j) / constants." + tex_name + "_size).rgb;"); + 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, "}"); 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 + ", texpaint" + l + "_sampler, tex_coord).rgb"; + return "sample(texpaint" + l + ", sampler_linear, 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 + ", texpaint_nor" + l + "_sampler, tex_coord).rgb"; + return "sample(texpaint_nor" + l + ", sampler_linear, tex_coord).rgb"; } } else if (node.type == "MATERIAL") { @@ -1257,7 +1257,7 @@ function parser_material_parse_value(node: ui_node_t, socket: ui_node_socket_t): node_shader_add_texture(parser_material_kong, "texuvmap", "_texuvmap"); // let use_pixel_size: bool = node.buttons[0].default_value == "true"; // let pixel_size: f32 = parse_value_input(node.inputs[0]); - return "sample_lod(texuvmap, texuvmap_sampler, input.tex_coord, 0.0).r"; + return "sample_lod(texuvmap, sampler_linear, input.tex_coord, 0.0).r"; } else if (node.type == "CAMERA") { if (socket == node.outputs[1]) { // View Z Depth @@ -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 + ", texpaint" + l + "_sampler, tex_coord).a"; + return "sample(texpaint" + l + ", sampler_linear, 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 + ", texpaint_pack" + l + "_sampler, tex_coord).r"; + return "sample(texpaint_pack" + l + ", sampler_linear, 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 + ", texpaint_pack" + l + "_sampler, tex_coord).g"; + return "sample(texpaint_pack" + l + ", sampler_linear, 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 + ", texpaint_pack" + l + "_sampler, tex_coord).b"; + return "sample(texpaint_pack" + l + ", sampler_linear, 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 + ", texpaint_pack" + l + "_sampler, tex_coord).a"; + return "sample(texpaint_pack" + l + ", sampler_linear, 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 + ", texpaint" + l + "_sampler, tex_coord).r"; + return "sample(texpaint" + l + ", sampler_linear, 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 + ", " + tex_name + "_sampler, tex_coord).r;"); + parser_material_write(parser_material_kong, "var " + store + "_res: float = sample(" + tex_name + ", sampler_linear, tex_coord).r;"); return store + "_res"; } else if (node.type == "NORMAL") { @@ -1893,18 +1893,18 @@ function parser_material_texture_store(node: ui_node_t, tex: bind_tex_t, tex_nam if (parser_material_triplanar) { parser_material_write(parser_material_kong, "var " + tex_store + ": float4 = float4(0.0, 0.0, 0.0, 0.0);"); - parser_material_write(parser_material_kong, "if (tex_coord_blend.x > 0) {" + tex_store + " += sample(" + tex_name + ", " + tex_name + "_sampler, " + uv_name + ".xy) * tex_coord_blend.x; }"); - parser_material_write(parser_material_kong, "if (tex_coord_blend.y > 0) {" + tex_store + " += sample(" + tex_name + ", " + tex_name + "_sampler, " + uv_name + "1.xy) * tex_coord_blend.y; }"); - parser_material_write(parser_material_kong, "if (tex_coord_blend.z > 0) {" + tex_store + " += sample(" + tex_name + ", " + tex_name + "_sampler, " + uv_name + "2.xy) * tex_coord_blend.z; }"); + parser_material_write(parser_material_kong, "if (tex_coord_blend.x > 0) {" + tex_store + " += sample(" + tex_name + ", sampler_linear, " + uv_name + ".xy) * tex_coord_blend.x; }"); + parser_material_write(parser_material_kong, "if (tex_coord_blend.y > 0) {" + tex_store + " += sample(" + tex_name + ", sampler_linear, " + uv_name + "1.xy) * tex_coord_blend.y; }"); + parser_material_write(parser_material_kong, "if (tex_coord_blend.z > 0) {" + tex_store + " += sample(" + tex_name + ", sampler_linear, " + uv_name + "2.xy) * tex_coord_blend.z; }"); } else { if (parser_material_is_frag) { - map_set(parser_material_texture_map, tex_store, "sample(" + tex_name + ", " + tex_name + "_sampler, " + uv_name + ".xy)"); - parser_material_write(parser_material_kong, "var " + tex_store + ": float4 = sample(" + tex_name + ", " + tex_name + "_sampler, " + uv_name + ".xy);"); + map_set(parser_material_texture_map, tex_store, "sample(" + tex_name + ", sampler_linear, " + uv_name + ".xy)"); + parser_material_write(parser_material_kong, "var " + tex_store + ": float4 = sample(" + tex_name + ", sampler_linear, " + uv_name + ".xy);"); } else { - map_set(parser_material_texture_map, tex_store, "sample_lod(" + tex_name + ", " + tex_name + "_sampler, " + uv_name + ".xy, 0.0)"); - parser_material_write(parser_material_kong, "var " + tex_store + ": float4 = sample_lod(" + tex_name + ", " + tex_name + "_sampler, " + uv_name + ".xy, 0.0);"); + map_set(parser_material_texture_map, tex_store, "sample_lod(" + tex_name + ", sampler_linear, " + uv_name + ".xy, 0.0)"); + parser_material_write(parser_material_kong, "var " + tex_store + ": float4 = sample_lod(" + tex_name + ", sampler_linear, " + uv_name + ".xy, 0.0);"); } if (!ends_with(tex.file, ".jpg")) { // Pre-mult alpha parser_material_write(parser_material_kong, tex_store + ".rgb *= " + tex_store + ".a;"); @@ -2006,21 +2006,9 @@ function parser_material_make_bind_tex(tex_name: string, file: string): bind_tex name: tex_name, file: file }; - if (context_raw.texture_filter) { - tex.min_filter = "anisotropic"; - tex.mag_filter = "linear"; - tex.mipmap_filter = "linear"; tex.generate_mipmaps = true; } - else { - tex.min_filter = "point"; - tex.mag_filter = "point"; - tex.mipmap_filter = "no"; - } - - tex.u_addressing = "repeat"; - tex.v_addressing = "repeat"; return tex; } diff --git a/base/sources/ts/strings.ts b/base/sources/ts/strings.ts index 375bf60e..4c1e591e 100644 --- a/base/sources/ts/strings.ts +++ b/base/sources/ts/strings.ts @@ -65,7 +65,7 @@ fun tex_voronoi(x: float3): float4 { \ for (var i: int = -1; i <= 1; i += 1) { \ var b: float3 = float3(float(i), float(j), float(k)); \ var pb: float3 = p + b; \ - var r: float3 = float3(b) - f + sample(snoise256, snoise256_sampler, (pb.xy + float2(3.0, 1.0) * pb.z + 0.5) / 256.0).xyz; \ + var r: float3 = float3(b) - f + sample(snoise256, sampler_linear, (pb.xy + float2(3.0, 1.0) * pb.z + 0.5) / 256.0).xyz; \ var d: float = dot(r, r); \ if (d < res) { \ id = dot(p + b, float3(1.0, 57.0, 113.0)); \ @@ -362,7 +362,7 @@ fun envmap_equirect(normal: float3, angle: float): float2 { \ let str_get_pos_nor_from_depth: string = "\ fun get_pos_from_depth(uv: float2, invVP: flaot4x4): float3 { \ - var depth: float = sample_lod(gbufferD, gbufferD_sampler, float2(uv.x, 1.0 - uv.y), 0.0).r; \ + var depth: float = sample_lod(gbufferD, sampler_linear, float2(uv.x, 1.0 - uv.y), 0.0).r; \ var wpos: float4 = float4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0); \ wpos = invVP * wpos; \ return wpos.xyz / wpos.w; \ diff --git a/base/sources/ts/util_clone.ts b/base/sources/ts/util_clone.ts index 5aaa2112..e88a3b8a 100644 --- a/base/sources/ts/util_clone.ts +++ b/base/sources/ts/util_clone.ts @@ -255,11 +255,6 @@ function util_clone_bind_textures(texs: bind_tex_t[]): bind_tex_t[] { let t: bind_tex_t = {}; t.name = texs[i].name; t.file = texs[i].file; - t.u_addressing = texs[i].u_addressing; - t.v_addressing = texs[i].v_addressing; - t.min_filter = texs[i].min_filter; - t.mag_filter = texs[i].mag_filter; - t.mipmap_filter = texs[i].mipmap_filter; t.generate_mipmaps = texs[i].generate_mipmaps; t.mipmaps = util_clone_string_array(texs[i].mipmaps); array_push(r, t); diff --git a/base/tests/cube/shaders/mesh.kong b/base/tests/cube/shaders/mesh.kong index 8fdcdba2..2899b83c 100644 --- a/base/tests/cube/shaders/mesh.kong +++ b/base/tests/cube/shaders/mesh.kong @@ -3,7 +3,7 @@ const my_texture: tex2d; #[set(everything)] -const my_texture_sampler: sampler; +const sampler_linear: sampler; #[set(everything)] const constants: { @@ -28,7 +28,7 @@ fun mesh_vert(input: vert_in): vert_out { } fun mesh_frag(input: vert_out): float4 { - return sample(my_texture, my_texture_sampler, input.tex); + return sample(my_texture, sampler_linear, input.tex); } #[pipe] diff --git a/base/tests/fall/shaders/mesh.kong b/base/tests/fall/shaders/mesh.kong index 635aafa9..efe9b7fd 100644 --- a/base/tests/fall/shaders/mesh.kong +++ b/base/tests/fall/shaders/mesh.kong @@ -3,7 +3,7 @@ const my_texture: tex2d; #[set(everything)] -const my_texture_sampler: sampler; +const sampler_linear: sampler; #[set(everything)] const constants: { @@ -33,7 +33,7 @@ fun mesh_vert(input: vert_in): vert_out { fun mesh_frag(input: vert_out): float4 { var l: float3 = float3(0.5, 0.0, 0.5); - var base_color: float3 = float3(1.0, 1.0, 1.0); // sample(my_texture, my_texture_sampler, input.tex).rgb; + var base_color: float3 = float3(1.0, 1.0, 1.0); // sample(my_texture, sampler_linear, input.tex).rgb; var ambient: float3 = base_color * 0.5; var n: float3 = normalize(input.nor); var dotnl: float = max(dot(n, l), 0.0);