Fix tests
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,15 @@
|
||||
|
||||
let flags = globalThis.flags;
|
||||
flags.with_iron = true;
|
||||
flags.lite = true;
|
||||
|
||||
let project = new Project("test");
|
||||
project.add_project("../../");
|
||||
project.add_tsfiles("sources");
|
||||
project.add_cfiles("../../sources/libs/asim/asim.c");
|
||||
project.add_tsfiles("../../sources/ts/iron");
|
||||
project.add_shaders("../../shaders/draw/*.glsl");
|
||||
project.add_shaders("shaders/*.glsl");
|
||||
project.add_assets("assets/*", { destination: "data/{name}" });
|
||||
|
||||
return project;
|
||||
@@ -0,0 +1,18 @@
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
function camera_update() {
|
||||
let camera: camera_object_t = scene_camera;
|
||||
let move_forward: bool = keyboard_down("w");
|
||||
let move_backward: bool = keyboard_down("s");
|
||||
let strafe_left: bool = keyboard_down("a");
|
||||
let strafe_right: bool = keyboard_down("d");
|
||||
let strafe_up: bool = keyboard_down("e");
|
||||
let strafe_down: bool = keyboard_down("q");
|
||||
let fast: f32 = keyboard_down("shift") ? 2.0 : 1.0;
|
||||
let speed: f32 = 5.0;
|
||||
let dir: vec4_t = vec4_create();
|
||||
|
||||
if (move_forward || move_backward || strafe_right || strafe_left || strafe_up || strafe_down) {
|
||||
let clook: vec4_t = camera_object_look(camera);
|
||||
let cright: vec4_t = camera_object_right(camera);
|
||||
|
||||
if (move_forward) {
|
||||
dir = vec4_fadd(dir, clook.x, clook.y, clook.z);
|
||||
}
|
||||
if (move_backward) {
|
||||
dir = vec4_fadd(dir, -clook.x, -clook.y, -clook.z);
|
||||
}
|
||||
if (strafe_right) {
|
||||
dir = vec4_fadd(dir, cright.x, cright.y, cright.z);
|
||||
}
|
||||
if (strafe_left) {
|
||||
dir = vec4_fadd(dir, -cright.x, -cright.y, -cright.z);
|
||||
}
|
||||
if (strafe_up) {
|
||||
dir = vec4_fadd(dir, 0, 0, 1);
|
||||
}
|
||||
if (strafe_down) {
|
||||
dir = vec4_fadd(dir, 0, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
let d: f32 = time_delta() * speed * fast;
|
||||
if (d > 0.0) {
|
||||
transform_move(camera.base.transform, dir, d);
|
||||
}
|
||||
|
||||
if (mouse_down()) {
|
||||
transform_rotate(camera.base.transform, vec4_z_axis(), -mouse_movement_x / 200);
|
||||
transform_rotate(camera.base.transform, camera_object_right(camera), -mouse_movement_y / 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// ../../../make --graphics vulkan --run
|
||||
|
||||
///include "../../sources/libs/asim/asim.h"
|
||||
|
||||
function main() {
|
||||
let ops: kinc_sys_ops_t = {
|
||||
title: "Empty",
|
||||
width: 1280,
|
||||
height: 720,
|
||||
x: -1,
|
||||
y: -1,
|
||||
features: window_features_t.RESIZABLE | window_features_t.MINIMIZABLE | window_features_t.MAXIMIZABLE,
|
||||
mode: window_mode_t.WINDOWED,
|
||||
frequency: 60,
|
||||
vsync: true,
|
||||
use_depth: true
|
||||
};
|
||||
sys_start(ops);
|
||||
app_init();
|
||||
app_ready();
|
||||
}
|
||||
|
||||
function render_commands() {
|
||||
render_path_set_target("");
|
||||
render_path_clear_target(0xff6495ed, 1.0, clear_flag_t.COLOR | clear_flag_t.DEPTH);
|
||||
render_path_draw_meshes("mesh");
|
||||
}
|
||||
|
||||
function app_ready() {
|
||||
render_path_commands = render_commands;
|
||||
|
||||
let scene: scene_t = {
|
||||
name: "Scene",
|
||||
objects: [
|
||||
{
|
||||
name: "Cube",
|
||||
type: "mesh_object",
|
||||
data_ref: "cube.arm/Cube",
|
||||
material_refs: ["MyMaterial"],
|
||||
visible: true,
|
||||
spawn: true
|
||||
},
|
||||
{
|
||||
name: "Sphere",
|
||||
type: "mesh_object",
|
||||
data_ref: "sphere.arm/Sphere",
|
||||
material_refs: ["MyMaterial"],
|
||||
visible: true,
|
||||
spawn: true
|
||||
},
|
||||
{
|
||||
name: "Camera",
|
||||
type: "camera_object",
|
||||
data_ref: "MyCamera",
|
||||
visible: true,
|
||||
spawn: true
|
||||
}
|
||||
],
|
||||
camera_datas: [
|
||||
{
|
||||
name: "MyCamera",
|
||||
near_plane: 0.1,
|
||||
far_plane: 100.0,
|
||||
fov: 0.85
|
||||
}
|
||||
],
|
||||
camera_ref: "Camera",
|
||||
material_datas: [
|
||||
{
|
||||
name: "MyMaterial",
|
||||
shader: "MyShader",
|
||||
contexts: [
|
||||
{
|
||||
name: "mesh",
|
||||
bind_textures: [
|
||||
{
|
||||
name: "my_texture",
|
||||
file: "texture.k"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
shader_datas: [
|
||||
{
|
||||
name: "MyShader",
|
||||
contexts: [
|
||||
{
|
||||
name: "mesh",
|
||||
vertex_shader: "mesh.vert",
|
||||
fragment_shader: "mesh.frag",
|
||||
compare_mode: "less",
|
||||
cull_mode: "clockwise",
|
||||
depth_write: true,
|
||||
vertex_elements: [
|
||||
{
|
||||
name: "pos",
|
||||
data: "short4norm"
|
||||
},
|
||||
{
|
||||
name: "nor",
|
||||
data: "short2norm"
|
||||
},
|
||||
{
|
||||
name: "tex",
|
||||
data: "short2norm"
|
||||
}
|
||||
],
|
||||
constants: [
|
||||
{
|
||||
name: "WVP",
|
||||
type: "mat4",
|
||||
link: "_world_view_proj_matrix"
|
||||
}
|
||||
],
|
||||
texture_units: [
|
||||
{
|
||||
name: "my_texture"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
map_set(data_cached_scene_raws, scene.name, scene);
|
||||
|
||||
// Instantiate scene
|
||||
scene_create(scene);
|
||||
scene_ready();
|
||||
}
|
||||
|
||||
function scene_ready() {
|
||||
// Set camera
|
||||
let t: transform_t = scene_camera.base.transform;
|
||||
t.loc = vec4_create(0, -10, 0);
|
||||
t.rot = quat_from_to(vec4_create(0, 0, 1), vec4_create(0, -1, 0));
|
||||
transform_build_matrix(t);
|
||||
|
||||
app_notify_on_update(scene_update);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function scene_update() {
|
||||
asim_update();
|
||||
camera_update();
|
||||
|
||||
if (keyboard_started("space")) {
|
||||
asim_set_sphere(0, 0, 5);
|
||||
}
|
||||
|
||||
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();
|
||||
transform_build_matrix(t);
|
||||
}
|
||||
Reference in New Issue
Block a user