2023-08-10 22:14:08 +00:00
|
|
|
#include "v4k.h"
|
2023-08-04 19:39:36 +00:00
|
|
|
|
|
|
|
int SKY_DIR = 0;
|
|
|
|
const char *SKY_DIRS[] = {
|
|
|
|
"cubemaps/bridge3/",
|
|
|
|
"cubemaps/colors/",
|
|
|
|
"cubemaps/colors2/",
|
2023-09-27 06:49:59 +00:00
|
|
|
"hdr/Tokyo_BigSight_1k.hdr",
|
2023-08-04 19:39:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int OBJ_MDL = 0;
|
|
|
|
const char *OBJ_MDLS[] = {
|
|
|
|
"meshes/sphere.obj",
|
|
|
|
"meshes/suzanne.obj",
|
|
|
|
"meshes/gazebo.obj",
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
window_create(85, WINDOW_MSAA8);
|
|
|
|
|
|
|
|
camera_t cam = camera();
|
|
|
|
skybox_t sky = {0};
|
|
|
|
model_t mdl = {0};
|
|
|
|
|
|
|
|
bool initialized = 0;
|
|
|
|
bool must_reload = 0;
|
|
|
|
|
|
|
|
while( window_swap()) {
|
2023-08-22 11:29:47 +00:00
|
|
|
if (input_down(KEY_ESC)) break;
|
2023-08-04 19:39:36 +00:00
|
|
|
// reloading
|
|
|
|
if( must_reload ) {
|
|
|
|
must_reload = 0;
|
|
|
|
skybox_destroy(&sky);
|
|
|
|
model_destroy(mdl);
|
|
|
|
initialized = 0;
|
|
|
|
}
|
|
|
|
if( !initialized ) {
|
|
|
|
initialized = 1;
|
2023-09-11 08:23:02 +00:00
|
|
|
sky = skybox(flag("--mie") ? 0 : SKY_DIRS[SKY_DIR], 0);
|
2023-08-04 19:39:36 +00:00
|
|
|
mdl = model(OBJ_MDLS[OBJ_MDL], 0);
|
2023-09-17 20:56:51 +00:00
|
|
|
rotation44(mdl.pivot, 0, 1,0,0); // @fixme: -90,1,0,0 -> should we rotate SHMs as well? compensate rotation in shader?
|
2023-08-04 19:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fps camera
|
|
|
|
bool active = ui_active() || ui_hover() || gizmo_active() ? false : input(MOUSE_L) || input(MOUSE_M) || input(MOUSE_R);
|
|
|
|
window_cursor( !active );
|
|
|
|
|
|
|
|
if( active ) cam.speed = clampf(cam.speed + input_diff(MOUSE_W) / 10, 0.05f, 5.0f);
|
|
|
|
vec2 mouse = scale2(vec2(input_diff(MOUSE_X), -input_diff(MOUSE_Y)), 0.2f * active);
|
|
|
|
vec3 wasdec = scale3(vec3(input(KEY_D)-input(KEY_A),input(KEY_E)-input(KEY_C),input(KEY_W)-input(KEY_S)), cam.speed);
|
2023-10-01 06:49:08 +00:00
|
|
|
camera_moveby(&cam, wasdec);
|
2023-08-04 19:39:36 +00:00
|
|
|
camera_fps(&cam, mouse.x,mouse.y);
|
|
|
|
|
|
|
|
// render
|
|
|
|
mat44 mvp; multiply44x2(mvp, cam.proj, cam.view);
|
|
|
|
{
|
2023-09-11 13:16:16 +00:00
|
|
|
if (flag("--mie")) {
|
|
|
|
// skybox_sh_reset(&sky);
|
|
|
|
skybox_mie_calc_sh(&sky, 4.0f);
|
2023-09-27 06:49:59 +00:00
|
|
|
// float x = cosf((float)window_time())*4;
|
2023-09-11 13:16:16 +00:00
|
|
|
// skybox_sh_add_light(&sky, vec3(0.3,0.3,0.3), vec3(0,1,0), 16*absf(cosf((float)window_time()*2))+2);
|
|
|
|
// skybox_sh_add_light(&sky, vec3(0.6,0,0), vec3(x,1,0), 2);
|
|
|
|
}
|
|
|
|
|
2023-08-22 11:29:47 +00:00
|
|
|
skybox_render(&sky, cam.proj, cam.view);
|
2023-09-27 06:49:59 +00:00
|
|
|
|
2023-08-22 11:29:47 +00:00
|
|
|
shader_bind(mdl.program);
|
|
|
|
shader_vec3v("u_coefficients_sh", 9, sky.cubemap.sh);
|
|
|
|
shader_int("u_textured", false);
|
2023-09-27 06:49:59 +00:00
|
|
|
|
2023-08-04 19:39:36 +00:00
|
|
|
model_render(mdl, cam.proj, cam.view, mdl.pivot, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ui_panel("Scene", 0)) {
|
|
|
|
if( ui_list("Skybox", SKY_DIRS, countof(SKY_DIRS), &SKY_DIR) ) {
|
|
|
|
must_reload = 1;
|
|
|
|
}
|
|
|
|
if( ui_list("Model", OBJ_MDLS, countof(OBJ_MDLS), &OBJ_MDL) ) {
|
|
|
|
must_reload = 1;
|
|
|
|
}
|
|
|
|
ui_separator();
|
|
|
|
for (int i = 0; i < 9; i++) {
|
2023-11-16 13:36:39 +00:00
|
|
|
ui_color3f(va("SH Coefficient [%d]", i), &sky.cubemap.sh[i].x);
|
2023-08-04 19:39:36 +00:00
|
|
|
}
|
|
|
|
ui_panel_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|