diff --git a/MAKE.bat b/MAKE.bat index 520a579..971cdb9 100644 --- a/MAKE.bat +++ b/MAKE.bat @@ -608,7 +608,7 @@ if "!vis!"=="yes" echo !cc! engine\v4k.c !export! !args! ^&^& if "!dll!"=="dll" rem editor if "!editor!"=="yes" ( -set edit=-DCOOK_ON_DEMAND -DUI_LESSER_SPACING -DUI_ICONS_SMALL -DVFS_ALWAYS_PACK +set edit=-DCOOK_ON_DEMAND -DUI_LESSER_SPACING -DUI_ICONS_SMALL rem if "!vis!"=="yes" echo !cc! !o! editor.exe tools\editor\editor.c !edit! !import! !args! rem !echo! editor && !cc! !o! editor.exe tools\editor\editor.c !edit! !import! !args! || set rc=1 rem !echo! editor2 && !cc! !o! editor2.exe tools\editor\editor2.c !edit! !args! || set rc=1 diff --git a/demos/00-demo.c b/demos/00-demo.c index 23ca2fa..4605db4 100644 --- a/demos/00-demo.c +++ b/demos/00-demo.c @@ -180,7 +180,7 @@ int main() { } // post-fxs end here - fx_end(0); + fx_end(); // font demo do_once font_scales(FONT_FACE1, 48, 24, 18, 12, 9, 6); diff --git a/demos/01-sprite.c b/demos/01-sprite.c index d5c9b4d..121dcf4 100644 --- a/demos/01-sprite.c +++ b/demos/01-sprite.c @@ -124,7 +124,7 @@ int main() { ); // post-fxs end here - fx_end(0); + fx_end(); // ui if( ui_panel("Audio", 0)) { diff --git a/demos/02-ddraw.c b/demos/02-ddraw.c index cd616d2..51c6064 100644 --- a/demos/02-ddraw.c +++ b/demos/02-ddraw.c @@ -88,7 +88,7 @@ int main() { collide_demo(); } - fx_end(0); + fx_end(); // ui if( ui_panel("App", 0) ) { diff --git a/demos/03-anims.c b/demos/03-anims.c index b07dab6..d4a6574 100644 --- a/demos/03-anims.c +++ b/demos/03-anims.c @@ -90,7 +90,7 @@ int main() { } } - fx_end(0); + fx_end(); if( ui_panel("Animation", 0) ) { if( ui_bool("Show aabb", &do_showaabb) ); diff --git a/demos/05-scene.c b/demos/05-scene.c index a7cb8ec..ad1dc22 100644 --- a/demos/05-scene.c +++ b/demos/05-scene.c @@ -125,7 +125,7 @@ int main() { } // post-fxs end here - fx_end(0); + fx_end(); // queue ui if( ui_panel("Camera", 0)) { diff --git a/demos/06-controller.c b/demos/06-controller.c index 1f83d9a..7fd439e 100644 --- a/demos/06-controller.c +++ b/demos/06-controller.c @@ -69,7 +69,7 @@ int main() { model_render(witch, cam.proj, cam.view, witch.pivot, 0); // render end (postfx) - fx_end(0); + fx_end(); // input controllers diff --git a/demos/99-dung.c b/demos/99-dung.c index e0b21fe..b0af255 100644 --- a/demos/99-dung.c +++ b/demos/99-dung.c @@ -169,7 +169,7 @@ int main() { skybox_render(&sky, cam.proj, cam.view); draw_world(); - fx_end(0); + fx_end(); } return 0; diff --git a/demos/99-pbr.c b/demos/99-pbr.c index f4ea965..c151a28 100644 --- a/demos/99-pbr.c +++ b/demos/99-pbr.c @@ -577,7 +577,7 @@ int main( int argc, const char *argv[] ) { glDepthFunc( GL_LESS ); } - fx_end(0); + fx_end(); // --------------------------------------------------------------------- // UI diff --git a/demos/99-sponza.c b/demos/99-sponza.c index e1e41b4..f15765a 100644 --- a/demos/99-sponza.c +++ b/demos/99-sponza.c @@ -70,6 +70,6 @@ int main() { model_render(sponza, cam.proj, cam.view, M, 0); // post-fxs end here - fx_end(0); + fx_end(); } } diff --git a/demos/99-sprite.c b/demos/99-sprite.c index 7c8d922..b4aa285 100644 --- a/demos/99-sprite.c +++ b/demos/99-sprite.c @@ -191,7 +191,7 @@ int main(int argc, char **argv) { } // post-fxs end here - fx_end(0); + fx_end(); // draw pixel-art hud, 16x16 ui element, scaled and positioned in resolution-independant way { diff --git a/demos/html5/demo_collide.c b/demos/html5/demo_collide.c index 42204f7..8f8d9ab 100644 --- a/demos/html5/demo_collide.c +++ b/demos/html5/demo_collide.c @@ -584,7 +584,7 @@ void game_loop(void *userdata) { //fx_begin(); //ddraw_flush(); - //fx_end(0); + //fx_end(); if( ui_panel("Vis", 0) ) { ui_bool("Skybox render", &draw_skybox); diff --git a/engine/art/shaders/fs_32_4_model.glsl b/engine/art/shaders/fs_32_4_model.glsl index 8efc136..af08e7f 100644 --- a/engine/art/shaders/fs_32_4_model.glsl +++ b/engine/art/shaders/fs_32_4_model.glsl @@ -46,29 +46,26 @@ const int LIGHT_SPOT = 2; uniform light_t u_lights[MAX_LIGHTS]; vec3 calculate_light(light_t l, vec3 normal, vec3 fragPos, vec3 viewDir) { - vec3 lightColor = l.color; - vec3 lightDir; float attenuation = 1.0; if (l.type == LIGHT_DIRECTIONAL) { lightDir = normalize(-l.dir); } else if (l.type == LIGHT_POINT) { - vec3 toLight = fragPos - l.pos; + vec3 toLight = l.pos - fragPos; lightDir = normalize(toLight); float distance = length(toLight); - float factor = distance / l.radius; + float factor = distance / (l.radius*l.radius); attenuation = clamp(1.0 - factor, 0.0, 1.0); } float diff = max(dot(normal, lightDir), 0.0); - vec3 diffuse = diff * lightColor; // vec3 reflectDir = reflect(-lightDir, normal); // float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32); // vec3 specular = spec * lightColor; - return (diffuse /* + specular */) * l.color; + return (diff /* + specular */) * l.color; } void main() { @@ -95,9 +92,9 @@ void main() { // analytical lights (phong shading) // @todo: support more shading models (blinn-phong, ue4 brdf, ...) - // for (int i=0; imask = fx->enabled = 0; } +static __thread array(handle) last_fb; + bool postfx_begin(postfx *fx, int width, int height) { // reset clear color: needed in case transparent window is being used (alpha != 0) glClearColor(0,0,0,0); // @transparent @@ -342716,9 +342718,9 @@ bool postfx_begin(postfx *fx, int width, int height) { width += !width; height += !height; - int last_fb; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb); - fbo_bind(last_fb); + int fb; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb); + array_push(last_fb, fb); // resize if needed if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) { @@ -342743,7 +342745,8 @@ bool postfx_begin(postfx *fx, int width, int height) { uint64_t num_active_passes = popcnt64(fx->mask); bool active = fx->enabled && num_active_passes; if( !active ) { - fbo_bind(last_fb); + array_pop(last_fb); + fbo_bind(fb); return false; } @@ -342760,13 +342763,15 @@ bool postfx_begin(postfx *fx, int width, int height) { return true; } -bool postfx_end(postfx *fx, handle fb) { +bool postfx_end(postfx *fx) { uint64_t num_active_passes = popcnt64(fx->mask); bool active = fx->enabled && num_active_passes; if( !active ) { return false; } + handle fb = *array_back(last_fb); + array_pop(last_fb); fbo_bind(fb); // disable depth test in 2d rendering @@ -342829,8 +342834,6 @@ bool postfx_end(postfx *fx, handle fb) { if(is_depth_test_enabled); glEnable(GL_DEPTH_TEST); - fbo_bind(fb); - return true; } @@ -342855,8 +342858,8 @@ void fx_begin() { void fx_begin_res(int w, int h) { postfx_begin(&fx, w, h); } -void fx_end(handle fb) { - postfx_end(&fx,fb); +void fx_end() { + postfx_end(&fx); } int fx_enabled(int pass) { return postfx_enabled(&fx, pass); diff --git a/engine/split/v4k_render.c b/engine/split/v4k_render.c index 96d322a..d15ad23 100644 --- a/engine/split/v4k_render.c +++ b/engine/split/v4k_render.c @@ -2948,7 +2948,7 @@ void postfx_destroy(postfx *fx); bool postfx_load(postfx *fx, const char *name, const char *fragment); bool postfx_begin(postfx *fx, int width, int height); -bool postfx_end(postfx *fx, handle fb); +bool postfx_end(postfx *fx); bool postfx_enabled(postfx *fx, int pass_number); bool postfx_enable(postfx *fx, int pass_number, bool enabled); @@ -3099,6 +3099,8 @@ void postfx_clear(postfx *fx) { fx->mask = fx->enabled = 0; } +static __thread array(handle) last_fb; + bool postfx_begin(postfx *fx, int width, int height) { // reset clear color: needed in case transparent window is being used (alpha != 0) glClearColor(0,0,0,0); // @transparent @@ -3106,9 +3108,9 @@ bool postfx_begin(postfx *fx, int width, int height) { width += !width; height += !height; - int last_fb; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb); - fbo_bind(last_fb); + int fb; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb); + array_push(last_fb, fb); // resize if needed if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) { @@ -3133,7 +3135,8 @@ bool postfx_begin(postfx *fx, int width, int height) { uint64_t num_active_passes = popcnt64(fx->mask); bool active = fx->enabled && num_active_passes; if( !active ) { - fbo_bind(last_fb); + array_pop(last_fb); + fbo_bind(fb); return false; } @@ -3150,13 +3153,15 @@ bool postfx_begin(postfx *fx, int width, int height) { return true; } -bool postfx_end(postfx *fx, handle fb) { +bool postfx_end(postfx *fx) { uint64_t num_active_passes = popcnt64(fx->mask); bool active = fx->enabled && num_active_passes; if( !active ) { return false; } + handle fb = *array_back(last_fb); + array_pop(last_fb); fbo_bind(fb); // disable depth test in 2d rendering @@ -3219,8 +3224,6 @@ bool postfx_end(postfx *fx, handle fb) { if(is_depth_test_enabled); glEnable(GL_DEPTH_TEST); - fbo_bind(fb); - return true; } @@ -3245,8 +3248,8 @@ void fx_begin() { void fx_begin_res(int w, int h) { postfx_begin(&fx, w, h); } -void fx_end(handle fb) { - postfx_end(&fx,fb); +void fx_end() { + postfx_end(&fx); } int fx_enabled(int pass) { return postfx_enabled(&fx, pass); diff --git a/engine/split/v4k_render.h b/engine/split/v4k_render.h index 454ae33..0bc4afb 100644 --- a/engine/split/v4k_render.h +++ b/engine/split/v4k_render.h @@ -664,7 +664,7 @@ API int fx_load(const char *file); API int fx_load_from_mem(const char *nameid, const char *content); API void fx_begin(); API void fx_begin_res(int w, int h); -API void fx_end(handle fb); +API void fx_end(); API void fx_enable(int pass, int enabled); API int fx_enabled(int pass); API void fx_enable_all(int enabled); diff --git a/engine/v4k.c b/engine/v4k.c index be927d9..e7b8006 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -13212,7 +13212,7 @@ void postfx_destroy(postfx *fx); bool postfx_load(postfx *fx, const char *name, const char *fragment); bool postfx_begin(postfx *fx, int width, int height); -bool postfx_end(postfx *fx, handle fb); +bool postfx_end(postfx *fx); bool postfx_enabled(postfx *fx, int pass_number); bool postfx_enable(postfx *fx, int pass_number, bool enabled); @@ -13363,6 +13363,8 @@ void postfx_clear(postfx *fx) { fx->mask = fx->enabled = 0; } +static __thread array(handle) last_fb; + bool postfx_begin(postfx *fx, int width, int height) { // reset clear color: needed in case transparent window is being used (alpha != 0) glClearColor(0,0,0,0); // @transparent @@ -13370,9 +13372,9 @@ bool postfx_begin(postfx *fx, int width, int height) { width += !width; height += !height; - int last_fb; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &last_fb); - fbo_bind(last_fb); + int fb; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb); + array_push(last_fb, fb); // resize if needed if( fx->diffuse[0].w != width || fx->diffuse[0].h != height ) { @@ -13397,7 +13399,8 @@ bool postfx_begin(postfx *fx, int width, int height) { uint64_t num_active_passes = popcnt64(fx->mask); bool active = fx->enabled && num_active_passes; if( !active ) { - fbo_bind(last_fb); + array_pop(last_fb); + fbo_bind(fb); return false; } @@ -13414,13 +13417,15 @@ bool postfx_begin(postfx *fx, int width, int height) { return true; } -bool postfx_end(postfx *fx, handle fb) { +bool postfx_end(postfx *fx) { uint64_t num_active_passes = popcnt64(fx->mask); bool active = fx->enabled && num_active_passes; if( !active ) { return false; } + handle fb = *array_back(last_fb); + array_pop(last_fb); fbo_bind(fb); // disable depth test in 2d rendering @@ -13483,8 +13488,6 @@ bool postfx_end(postfx *fx, handle fb) { if(is_depth_test_enabled); glEnable(GL_DEPTH_TEST); - fbo_bind(fb); - return true; } @@ -13509,8 +13512,8 @@ void fx_begin() { void fx_begin_res(int w, int h) { postfx_begin(&fx, w, h); } -void fx_end(handle fb) { - postfx_end(&fx,fb); +void fx_end() { + postfx_end(&fx); } int fx_enabled(int pass) { return postfx_enabled(&fx, pass); diff --git a/engine/v4k.h b/engine/v4k.h index af12e0f..42ed38d 100644 --- a/engine/v4k.h +++ b/engine/v4k.h @@ -3097,7 +3097,7 @@ API int fx_load(const char *file); API int fx_load_from_mem(const char *nameid, const char *content); API void fx_begin(); API void fx_begin_res(int w, int h); -API void fx_end(handle fb); +API void fx_end(); API void fx_enable(int pass, int enabled); API int fx_enabled(int pass); API void fx_enable_all(int enabled); diff --git a/hello.c b/hello.c index dbecf37..ad83a44 100644 --- a/hello.c +++ b/hello.c @@ -80,7 +80,7 @@ int main() { model_render(girl, cam.proj, cam.view, girl.pivot, 0); // post-fxs end here - fx_end(0); + fx_end(); gizmo(&pos, &rot, &sca); model_render_skeleton(girl, girl.pivot); diff --git a/tools/editor/editor.c b/tools/editor/editor.c index 734de76..2f7802f 100644 --- a/tools/editor/editor.c +++ b/tools/editor/editor.c @@ -1772,7 +1772,7 @@ int main() { editor_obj_call0(obj, fn_draw); } - fx_end(0); + fx_end(); // draw gizmos, aabbs, markers, etc for each_set_ptr(editor_selection, void*, o) { diff --git a/workbench/plugins/shader_editor.c b/workbench/plugins/shader_editor.c index 7c67fb2..b586e19 100644 --- a/workbench/plugins/shader_editor.c +++ b/workbench/plugins/shader_editor.c @@ -133,7 +133,7 @@ __declspec(dllexport) int plug_tick(asset_t *f) { ddraw_grid(0); ddraw_flush(); model_render(models[s->model], cam.proj, cam.view, models[s->model].pivot, 0); - fx_end(s->fb); + fx_end(); // fbo_bind(s->fb); // fullscreen_quad_rgb(s->tex, 1.0); diff --git a/workbench/workbench.c b/workbench/workbench.c index fa78035..6c1dbeb 100644 --- a/workbench/workbench.c +++ b/workbench/workbench.c @@ -115,11 +115,11 @@ int main() { } ui_panel_end(); - static bool show_main_window = 1; - if ( ui_window("Workbench", &show_main_window) ) { - ui_label("v4.games"); - } - ui_window_end(); + // static bool show_main_window = 1; + // if ( ui_window("Workbench", &show_main_window) ) { + // ui_label("v4.games"); + // } + // ui_window_end(); for (int i=0; i