diff --git a/base/tests/cube/project.js b/base/tests/cube/project.js index 3a3a30d4..ba613cc9 100644 --- a/base/tests/cube/project.js +++ b/base/tests/cube/project.js @@ -7,8 +7,8 @@ let project = new Project("test"); project.add_project("../../"); project.add_tsfiles("sources"); project.add_tsfiles("../../sources/ts/iron"); -project.add_shaders("../../shaders/draw/*.glsl"); -project.add_shaders("shaders/*.glsl"); +project.add_shaders("../../shaders/draw/*.kong"); +project.add_shaders("shaders/*.kong"); project.add_assets("assets/*", { destination: "data/{name}" }); return project; diff --git a/base/tests/cube/shaders/mesh.frag.glsl b/base/tests/cube/shaders/mesh.frag.glsl deleted file mode 100644 index ae6a5846..00000000 --- a/base/tests/cube/shaders/mesh.frag.glsl +++ /dev/null @@ -1,11 +0,0 @@ -#version 450 - -in vec2 tex_coord; - -out vec4 frag_color; - -uniform sampler2D my_texture; - -void main() { - frag_color = texture(my_texture, tex_coord); -} diff --git a/base/tests/cube/shaders/mesh.kong b/base/tests/cube/shaders/mesh.kong new file mode 100644 index 00000000..8fdcdba2 --- /dev/null +++ b/base/tests/cube/shaders/mesh.kong @@ -0,0 +1,38 @@ + +#[set(everything)] +const my_texture: tex2d; + +#[set(everything)] +const my_texture_sampler: sampler; + +#[set(everything)] +const constants: { + WVP: float4x4; +}; + +struct vert_in { + pos: float4; + tex: float2; +} + +struct vert_out { + pos: float4; + tex: float2; +} + +fun mesh_vert(input: vert_in): vert_out { + var output: vert_out; + output.tex = input.tex; + output.pos = constants.WVP * float4(input.pos.xyz, 1.0); + return output; +} + +fun mesh_frag(input: vert_out): float4 { + return sample(my_texture, my_texture_sampler, input.tex); +} + +#[pipe] +struct pipe { + vertex = mesh_vert; + fragment = mesh_frag; +} diff --git a/base/tests/cube/shaders/mesh.vert.glsl b/base/tests/cube/shaders/mesh.vert.glsl deleted file mode 100644 index 6da40d5c..00000000 --- a/base/tests/cube/shaders/mesh.vert.glsl +++ /dev/null @@ -1,13 +0,0 @@ -#version 450 - -in vec4 pos; -in vec2 tex; - -out vec2 tex_coord; - -uniform mat4 WVP; - -void main() { - tex_coord = tex; - gl_Position = WVP * vec4(pos.xyz, 1.0); -} diff --git a/base/tests/cube/sources/main.ts b/base/tests/cube/sources/main.ts index 286e8783..6ec1858a 100644 --- a/base/tests/cube/sources/main.ts +++ b/base/tests/cube/sources/main.ts @@ -1,4 +1,4 @@ -// ../../../make --graphics vulkan --run +// ../../make --run function main() { let ops: iron_window_options_t = { @@ -10,7 +10,8 @@ function main() { features: window_features_t.RESIZABLE | window_features_t.MINIMIZABLE | window_features_t.MAXIMIZABLE, mode: window_mode_t.WINDOWED, frequency: 60, - vsync: true + vsync: true, + use_depth: false }; sys_start(ops); sys_init(); @@ -77,8 +78,8 @@ function ready() { contexts: [ { name: "mesh", - vertex_shader: "mesh.vert", - fragment_shader: "mesh.frag", + vertex_shader: "_mesh.vert", + fragment_shader: "_mesh.frag", compare_mode: "less", cull_mode: "clockwise", depth_write: true, diff --git a/base/tests/fall/project.js b/base/tests/fall/project.js index 7f3bf8a2..c576cec7 100644 --- a/base/tests/fall/project.js +++ b/base/tests/fall/project.js @@ -8,8 +8,8 @@ project.add_project("../../"); project.add_tsfiles("sources"); project.add_cfiles("../../sources/libs/asim.c"); project.add_tsfiles("../../sources/ts/iron"); -project.add_shaders("../../shaders/draw/*.glsl"); -project.add_shaders("shaders/*.glsl"); +project.add_shaders("../../shaders/draw/*.kong"); +project.add_shaders("shaders/*.kong"); project.add_assets("assets/*", { destination: "data/{name}" }); return project; diff --git a/base/tests/fall/shaders/mesh.frag.glsl b/base/tests/fall/shaders/mesh.frag.glsl deleted file mode 100644 index f2a1f5f9..00000000 --- a/base/tests/fall/shaders/mesh.frag.glsl +++ /dev/null @@ -1,18 +0,0 @@ -#version 450 - -in vec2 tex_coord; -in vec3 normal; - -out vec4 frag_color; - -uniform sampler2D my_texture; - -void main() { - vec3 l = vec3(0.5, 0.0, 0.5); - vec3 base_color = vec3(1.0, 1.0, 1.0); // texture(my_texture, tex_coord).rgb; - vec3 ambient = base_color * 0.5; - vec3 n = normalize(normal); - float dotnl = max(dot(n, l), 0.0); - vec3 diffuse = dotnl * base_color; - frag_color = vec4(ambient + diffuse, 1.0); -} diff --git a/base/tests/fall/shaders/mesh.kong b/base/tests/fall/shaders/mesh.kong new file mode 100644 index 00000000..635aafa9 --- /dev/null +++ b/base/tests/fall/shaders/mesh.kong @@ -0,0 +1,48 @@ + +#[set(everything)] +const my_texture: tex2d; + +#[set(everything)] +const my_texture_sampler: sampler; + +#[set(everything)] +const constants: { + WVP: float4x4; +}; + +struct vert_in { + pos: float4; + nor: float2; + tex: float2; +} + +struct vert_out { + pos: float4; + nor: float3; + tex: float2; +} + + +fun mesh_vert(input: vert_in): vert_out { + var output: vert_out; + output.nor = float3(input.nor.xy, input.pos.w); + output.tex = input.tex; + output.pos = constants.WVP * float4(input.pos.xyz, 1.0); + return output; +} + +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 ambient: float3 = base_color * 0.5; + var n: float3 = normalize(input.nor); + var dotnl: float = max(dot(n, l), 0.0); + var diffuse: float3 = dotnl * base_color; + return float4(ambient + diffuse, 1.0); +} + +#[pipe] +struct pipe { + vertex = mesh_vert; + fragment = mesh_frag; +} diff --git a/base/tests/fall/shaders/mesh.vert.glsl b/base/tests/fall/shaders/mesh.vert.glsl deleted file mode 100644 index d7de2b2a..00000000 --- a/base/tests/fall/shaders/mesh.vert.glsl +++ /dev/null @@ -1,16 +0,0 @@ -#version 450 - -in vec4 pos; -in vec2 nor; -in vec2 tex; - -out vec3 normal; -out vec2 tex_coord; - -uniform mat4 WVP; - -void main() { - normal = vec3(nor.xy, pos.w); - tex_coord = tex; - gl_Position = WVP * vec4(pos.xyz, 1.0); -} diff --git a/base/tests/fall/sources/main.ts b/base/tests/fall/sources/main.ts index ab973e48..33710575 100644 --- a/base/tests/fall/sources/main.ts +++ b/base/tests/fall/sources/main.ts @@ -1,7 +1,9 @@ -// ../../../make --graphics vulkan --run +// ../../make --run ///include "../../sources/libs/asim.h" +let body: any; + function main() { let ops: iron_window_options_t = { title: "Empty", @@ -88,8 +90,8 @@ function ready() { contexts: [ { name: "mesh", - vertex_shader: "mesh.vert", - fragment_shader: "mesh.frag", + vertex_shader: "_mesh.vert", + fragment_shader: "_mesh.frag", compare_mode: "less", cull_mode: "clockwise", depth_write: true, @@ -143,21 +145,21 @@ function scene_ready() { let cube: object_t = scene_get_child("Cube"); let mesh: mesh_object_t = cube.ext; - asim_init(mesh.data.vertex_arrays[0].values, mesh.data.index_arrays[0].values, mesh.data.scale_pos); + asim_world_create(); + body = asim_body_create(1, 1, 1, 1, 1, 0, 0, 5, null, null, 1); + asim_body_create(0, 1, 1, 1, 1, 0, 0, 0, mesh.data.vertex_arrays[0].values, mesh.data.index_arrays[0].values, mesh.data.scale_pos); } function scene_update() { - asim_update(); + asim_world_update(); camera_update(); if (keyboard_started("space")) { - asim_set_sphere(0, 0, 5); + asim_body_sync_transform(body, vec4_create(0, 0, 5), quat_create(0, 0, 0, 1)); } let sphere: object_t = scene_get_child("Sphere"); let t: transform_t = sphere.transform; - t.loc.x = asim_get_sphere_x(); - t.loc.y = asim_get_sphere_y(); - t.loc.z = asim_get_sphere_z(); + asim_body_get_pos(body, ADDRESS(t.loc)); transform_build_matrix(t); } diff --git a/base/tests/triangle/main.ts b/base/tests/triangle/main.ts index 5f5b180f..8876a1d2 100644 --- a/base/tests/triangle/main.ts +++ b/base/tests/triangle/main.ts @@ -1,6 +1,6 @@ // Red triangle test -// ../../../make --graphics vulkan --run +// ../../make --run let pipeline: iron_gpu_pipeline_t; let vb: any; @@ -8,60 +8,39 @@ let ib: any; function render() { _gpu_begin(null, null); - - let flags: i32 = 0; - flags |= 1; // Color - flags |= 2; // Depth - iron_gpu_clear(0xff000000, 1.0, flags); - + iron_gpu_clear(0xff000000, 1.0, clear_flag_t.COLOR | clear_flag_t.DEPTH); iron_gpu_set_pipeline(pipeline); gpu_set_vertex_buffer(vb); gpu_set_index_buffer(ib); gpu_draw_indexed_vertices(0, -1); - _gpu_end(); } function main() { - let resizable: i32 = 1; - let minimizable: i32 = 2; - let maximizable: i32 = 4; - _iron_init("Iron", 640, 480, true, 0, resizable | minimizable | maximizable, -1, -1, 60); + let ops: iron_window_options_t = { + title: "Iron", + width: 640, + height: 480, + x: -1, + y: -1, + mode: window_mode_t.WINDOWED, + features: window_features_t.RESIZABLE | window_features_t.MINIMIZABLE | window_features_t.MAXIMIZABLE, + vsync: true, + frequency: 60, + use_depth: true + }; + _iron_init(ops); pipeline = gpu_create_pipeline(); - let f32_3x: vertex_data_t = vertex_data_t.F32_3X; - let elem: iron_gpu_vertex_element_t = { name: "pos", data: f32_3x }; - let elems: iron_gpu_vertex_element_t[] = [elem]; - - let structure0: iron_gpu_vertex_structure_t = { elements: elems }; - - let vs_buffer: buffer_t = iron_load_blob("./data/test.vert.spirv"); - let fs_buffer: buffer_t = iron_load_blob("./data/test.frag.spirv"); - + let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + let vs_buffer: buffer_t = iron_load_blob("./data/test.vert" + sys_shader_ext()); + let fs_buffer: buffer_t = iron_load_blob("./data/test.frag" + sys_shader_ext()); let vert: any = gpu_create_shader(vs_buffer, shader_type_t.VERTEX); let frag: any = gpu_create_shader(fs_buffer, shader_type_t.FRAGMENT); - - let masks: bool[] = [true, true, true, true, true, true, true, true]; - let attachments: i32[] = [0]; - - pipeline.cull_mode = 0; - pipeline.depth_write = false; - pipeline.depth_mode = 0; - pipeline.blend_source = 0; - pipeline.blend_destination = 0; - pipeline.alpha_blend_source = 0; - pipeline.alpha_blend_destination = 0; - pipeline.color_write_mask_red = masks; - pipeline.color_write_mask_green = masks; - pipeline.color_write_mask_blue = masks; - pipeline.color_write_mask_alpha = masks; - pipeline.color_attachment_count = 1; - pipeline.color_attachment = attachments; - pipeline.depth_attachment_bits = 0; pipeline.vertex_shader = vert; pipeline.fragment_shader = frag; - pipeline.input_layout = structure0; - + pipeline.input_layout = vs; gpu_compile_pipeline(pipeline); let vertices: f32[] = [ @@ -71,7 +50,7 @@ function main() { ]; let indices: i32[] = [0, 1, 2]; - vb = gpu_create_vertex_buffer(vertices.length / 3, structure0.elements, 0); + vb = gpu_create_vertex_buffer(vertices.length / 3, vs.elements, 0); let vb_data: buffer_t = gpu_lock_vertex_buffer(vb); for (let i: i32 = 0; i < vertices.length; i++) { buffer_set_f32(vb_data, i * 4, vertices[i]); diff --git a/base/tests/triangle/project.js b/base/tests/triangle/project.js index 09abc2f0..fb51fbfa 100644 --- a/base/tests/triangle/project.js +++ b/base/tests/triangle/project.js @@ -7,5 +7,5 @@ let project = new Project("test"); project.add_project("../../"); project.add_tsfiles("./"); project.add_tsfiles("../../sources/ts/iron"); -project.add_shaders("./*.glsl"); +project.add_shaders("./*.kong"); return project; diff --git a/base/tests/triangle/test.frag.glsl b/base/tests/triangle/test.frag.glsl deleted file mode 100644 index 8e15f792..00000000 --- a/base/tests/triangle/test.frag.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#version 450 - -out vec4 frag_color; - -void main() { - frag_color = vec4(1.0, 0.0, 0.0, 1.0); -} diff --git a/base/tests/triangle/test.kong b/base/tests/triangle/test.kong new file mode 100644 index 00000000..28b2b233 --- /dev/null +++ b/base/tests/triangle/test.kong @@ -0,0 +1,24 @@ + +struct vert_in { + pos: float3; +} + +struct vert_out { + pos: float4; +} + +fun test_vert(input: vert_in): vert_out { + var output: vert_out; + output.pos = float4(input.pos, 1.0); + return output; +} + +fun test_frag(input: vert_out): float4 { + return float4(1.0, 0.0, 0.0, 1.0); +} + +#[pipe] +struct pipe { + vertex = test_vert; + fragment = test_frag; +} diff --git a/base/tests/triangle/test.vert.glsl b/base/tests/triangle/test.vert.glsl deleted file mode 100644 index d94b0b01..00000000 --- a/base/tests/triangle/test.vert.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#version 450 - -in vec3 pos; - -void main() { - gl_Position = vec4(pos, 1.0); -}