diff --git a/armorlab/sources/make_paint.ts b/armorlab/sources/make_paint.ts index d20ff05b..9228752f 100644 --- a/armorlab/sources/make_paint.ts +++ b/armorlab/sources/make_paint.ts @@ -42,7 +42,7 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad if (context_raw.tool == workspace_tool_t.PICKER) { // Mangle vertices to form full screen triangle - node_shader_write_vert(kong, "output.pos = float4(-1.0 + float((gl_VertexID & 1) << 2), -1.0 + float((gl_VertexID & 2) << 1), 0.0, 1.0);"); + node_shader_write_vert(kong, "output.pos = float4(-1.0 + float((vertex_id() & 1) << 2), -1.0 + float((vertex_id() & 2) << 1), 0.0, 1.0);"); node_shader_add_texture(kong, "gbuffer2"); node_shader_add_constant(kong, "gbuffer_size: float2", "_gbuffer_size"); diff --git a/armorpaint/sources/make_colorid_picker.ts b/armorpaint/sources/make_colorid_picker.ts index 89539885..7ebabad1 100644 --- a/armorpaint/sources/make_colorid_picker.ts +++ b/armorpaint/sources/make_colorid_picker.ts @@ -1,7 +1,7 @@ function make_colorid_picker_run(kong: node_shader_t) { // Mangle vertices to form full screen triangle - node_shader_write_vert(kong, "output.pos = float4(-1.0 + float((gl_VertexID & 1) << 2), -1.0 + float((gl_VertexID & 2) << 1), 0.0, 1.0);"); + node_shader_write_vert(kong, "output.pos = float4(-1.0 + float((vertex_id() & 1) << 2), -1.0 + float((vertex_id() & 2) << 1), 0.0, 1.0);"); node_shader_add_texture(kong, "gbuffer2"); node_shader_add_constant(kong, "gbuffer_size: float2", "_gbuffer_size"); diff --git a/armorpaint/sources/make_mesh.ts b/armorpaint/sources/make_mesh.ts index c77c22aa..2358c3f3 100644 --- a/armorpaint/sources/make_mesh.ts +++ b/armorpaint/sources/make_mesh.ts @@ -54,7 +54,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); + 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;"); let masks: slot_layer_t[] = slot_layer_get_masks(l); if (masks != null) { diff --git a/armorsculpt/sources/make_mesh.ts b/armorsculpt/sources/make_mesh.ts index 9001239b..e3a7c25a 100644 --- a/armorsculpt/sources/make_mesh.ts +++ b/armorsculpt/sources/make_mesh.ts @@ -39,9 +39,9 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_add_constant(kong, "WVP: float4x4", "_world_view_proj_matrix"); let lid: i32 = project_layers[0].id; - node_shader_add_texture(kong, "texpaint_vert", "_texpaint_vert" + lid); + 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, int2(gl_VertexID % constants.texpaint_vert_size.x, gl_VertexID / constants.texpaint_vert_size.y), 0).xyz;"); + node_shader_write_vert(kong, "var meshpos: float3 = sample_lod(texpaint_vert, texpaint_vert_sampler, int2(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);"); @@ -52,7 +52,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_add_constant(kong, "N: float3x3", "_normal_matrix"); node_shader_add_out(kong, "wnormal: float3"); - node_shader_write_attrib_vert(kong, "var base_vertex0: int = gl_VertexID - (gl_VertexID % 3);"); + 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, int2(base_vertex0 % constants.texpaint_vert_size.x, base_vertex0 / constants.texpaint_vert_size.y), 0).xyz;"); diff --git a/base/shaders/cursor.kong b/base/shaders/cursor.kong index 633834ea..191f1055 100644 --- a/base/shaders/cursor.kong +++ b/base/shaders/cursor.kong @@ -28,7 +28,6 @@ struct vert_out { } fun get_pos(uv: float2): float3 { - // var depth: float = sample_lod(gbufferD, gbufferD_sampler, uv, 0.0).r; var depth: float = sample_lod(gbufferD, gbufferD_sampler, 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 = constants.invVP * wpos; @@ -65,16 +64,16 @@ fun cursor_vert(input: vert_in): vert_out { n_tan = normalize(constants.camera_right - n * dot(constants.camera_right, n)); n_bin = cross(n_tan, n); - if (input.pos.x < 0 && input.pos.z < 0) { // vertex_id == 0 + if (vertex_id() == 0) { wpos += normalize(-n_tan - n_bin) * 0.7 * constants.radius; } - /*else */if (input.pos.x > 0 && input.pos.z < 0) { // vertex_id == 1 + /*else */if (vertex_id() == 1) { wpos += normalize( n_tan - n_bin) * 0.7 * constants.radius; } - /*else */if (input.pos.x > 0 && input.pos.z > 0) { // vertex_id == 2 + /*else */if (vertex_id() == 2) { wpos += normalize( n_tan + n_bin) * 0.7 * constants.radius; } - /*else */if (input.pos.x < 0 && input.pos.z > 0) { // vertex_id == 3 + /*else */if (vertex_id() == 3) { wpos += normalize(-n_tan + n_bin) * 0.7 * constants.radius; } diff --git a/base/sources/ts/iron/scene.ts b/base/sources/ts/iron/scene.ts index b670eb1a..0decc726 100644 --- a/base/sources/ts/iron/scene.ts +++ b/base/sources/ts/iron/scene.ts @@ -626,6 +626,7 @@ type shader_const_t = { type tex_unit_t = { name?: string; link?: string; + vert?: bool; }; type speaker_data_t = { diff --git a/base/sources/ts/iron/shader_data.ts b/base/sources/ts/iron/shader_data.ts index 772df448..ced69873 100644 --- a/base/sources/ts/iron/shader_data.ts +++ b/base/sources/ts/iron/shader_data.ts @@ -381,7 +381,12 @@ function shader_context_add_const(raw: shader_context_t, c: shader_const_t, offs function shader_context_add_tex(raw: shader_context_t, tu: tex_unit_t, i: i32) { let unit: iron_gpu_texture_unit_t = gpu_get_texture_unit(raw._.pipe_state, tu.name); - ARRAY_ACCESS(unit.stages, IRON_GPU_SHADER_TYPE_FRAGMENT) = i; + if (tu.vert) { + ARRAY_ACCESS(unit.stages, IRON_GPU_SHADER_TYPE_VERTEX) = i; + } + else { + ARRAY_ACCESS(unit.stages, IRON_GPU_SHADER_TYPE_FRAGMENT) = i; + } array_push(raw._.tex_units, unit); } diff --git a/base/sources/ts/node_shader.ts b/base/sources/ts/node_shader.ts index 7f53d984..6d7e00c9 100644 --- a/base/sources/ts/node_shader.ts +++ b/base/sources/ts/node_shader.ts @@ -91,14 +91,14 @@ function node_shader_add_constant(raw: node_shader_t, s: string, link: string = } } -function node_shader_add_texture(raw: node_shader_t, s: string, link: string = null) { +function node_shader_add_texture(raw: node_shader_t, s: string, link: string = null, vert: bool = false) { // mytex: tex2d if (array_index_of(raw.textures, s) == -1) { let ar: string[] = string_split(s, ": "); let uname: string = ar[0]; let utype: string = ar[1]; array_push(raw.textures, s); - node_shader_context_add_texture_unit(raw.context, utype, uname, link); + node_shader_context_add_texture_unit(raw.context, utype, uname, link, vert); } } @@ -109,7 +109,7 @@ function node_shader_add_shared_sampler(raw: node_shader_t, s: string) { 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); + node_shader_context_add_texture_unit(raw.context, utype, uname, null, false); } } diff --git a/base/sources/ts/node_shader_context.ts b/base/sources/ts/node_shader_context.ts index 42e85b69..91d46ce0 100644 --- a/base/sources/ts/node_shader_context.ts +++ b/base/sources/ts/node_shader_context.ts @@ -9,8 +9,6 @@ type node_shader_context_t = { data?: shader_context_t; allow_vcols?: bool; material?: material_t; - constants?: shader_const_t[]; - tunits?: tex_unit_t[]; }; function node_shader_context_create(material: material_t, props: shader_context_t): node_shader_context_t { @@ -59,8 +57,8 @@ function node_shader_context_create(material: material_t, props: shader_context_ raw.data.color_writes_alpha = props.color_writes_alpha; } - raw.tunits = raw.data.texture_units = []; - raw.constants = raw.data.constants = []; + raw.data.texture_units = []; + raw.data.constants = []; return raw; } @@ -96,8 +94,8 @@ function node_shader_context_get_elem(raw: node_shader_context_t, name: string): } function node_shader_context_add_constant(raw: node_shader_context_t, ctype: string, name: string, link: string = null) { - for (let i: i32 = 0; i < raw.constants.length; ++i) { - let c: shader_const_t = raw.constants[i]; + for (let i: i32 = 0; i < raw.data.constants.length; ++i) { + let c: shader_const_t = raw.data.constants[i]; if (c.name == name) { return; } @@ -107,22 +105,19 @@ function node_shader_context_add_constant(raw: node_shader_context_t, ctype: str if (link != null) { c.link = link; } - array_push(raw.constants, c); + array_push(raw.data.constants, c); } -function node_shader_context_add_texture_unit(raw: node_shader_context_t, ctype: string, name: string, link: string = null) { - for (let i: i32 = 0; i < raw.tunits.length; ++i) { - let c: tex_unit_t = raw.tunits[i]; +function node_shader_context_add_texture_unit(raw: node_shader_context_t, ctype: string, name: string, link: string = null, vert: bool = false) { + for (let i: i32 = 0; i < raw.data.texture_units.length; ++i) { + let c: tex_unit_t = raw.data.texture_units[i]; if (c.name == name) { return; } } - let c: tex_unit_t = { name: name }; - if (link != null) { - c.link = link; - } - array_push(raw.tunits, c); + let c: tex_unit_t = { name: name, link: link, vert: vert }; + array_push(raw.data.texture_units, c); } function node_shader_context_make_kong(raw: node_shader_context_t): node_shader_t {