From 4cec1b55e300ee3da011943901f05662d5be076d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sat, 24 Aug 2024 00:21:38 +0200 Subject: [PATCH] gfx changes --- bind/v4k.lua | 1 + engine/joint/v4k.h | 13 +++++++++++-- engine/split/v4k_render.c | 12 ++++++++++-- engine/split/v4k_render.h | 1 + engine/v4k.c | 12 ++++++++++-- engine/v4k.h | 1 + 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/bind/v4k.lua b/bind/v4k.lua index 349bf9c..aaf93a3 100644 --- a/bind/v4k.lua +++ b/bind/v4k.lua @@ -1320,6 +1320,7 @@ enum MODEL_FLAGS { MODEL_MATCAPS = 16, MODEL_RIMLIGHT = 32, MODEL_PBR = 64, + MODEL_TRANSPARENT = 128, }; enum SHADING_MODE { SHADING_NONE, diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index add77c0..6500dbb 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -17565,6 +17565,7 @@ enum MODEL_FLAGS { MODEL_MATCAPS = 16, MODEL_RIMLIGHT = 32, MODEL_PBR = 64, + MODEL_TRANSPARENT = 128, }; enum SHADING_MODE { @@ -385540,7 +385541,13 @@ void model_set_renderstates(model_t *m) { // Opaque pass renderstate_t *opaque_rs = &m->rs[RENDER_PASS_OPAQUE]; { +#if 0 // @todo: we should keep blend_enabled=0, however our transparency detection still needs work opaque_rs->blend_enabled = 0; +#else + opaque_rs->blend_enabled = 1; + opaque_rs->blend_src = GL_SRC_ALPHA; + opaque_rs->blend_dst = GL_ONE_MINUS_SRC_ALPHA; +#endif opaque_rs->cull_face_mode = GL_BACK; opaque_rs->front_face = GL_CW; } @@ -385851,7 +385858,6 @@ void shader_colormap_model_internal(const char *col_name, const char *bool_name, typedef struct drawcall_t { - model_t *m; int mesh; union { uint64_t order; @@ -385889,6 +385895,9 @@ void model_draw_call(model_t m, int shader, int pass, vec3 cam_pos, mat44 model_ required_rs[i] = rs_idx; if (required_rs[i] < RENDER_PASS_OVERRIDES_BEGIN) { + if (m.flags & MODEL_TRANSPARENT) { + required_rs[i] = RENDER_PASS_TRANSPARENT; + } if (m.materials[i].layer[0].map.color.a < 1 || (m.materials[i].layer[0].map.texture && m.materials[i].layer[0].map.texture->transparent)) { required_rs[i] = RENDER_PASS_TRANSPARENT; } @@ -385913,7 +385922,7 @@ void model_draw_call(model_t m, int shader, int pass, vec3 cam_pos, mat44 model_ drawcall_t call; call.mesh = i; call.tex = m.textures[i]; - call.distance = -1; + call.distance = 0; if (m.shading == SHADING_PBR) call.tex = m.materials[i].layer[MATERIAL_CHANNEL_ALBEDO].map.texture ? m.materials[i].layer[MATERIAL_CHANNEL_ALBEDO].map.texture->id : m.materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture ? m.materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture->id : texture_checker().id; array_push(drawcalls, call); diff --git a/engine/split/v4k_render.c b/engine/split/v4k_render.c index 78220c7..1cd2a81 100644 --- a/engine/split/v4k_render.c +++ b/engine/split/v4k_render.c @@ -3901,7 +3901,13 @@ void model_set_renderstates(model_t *m) { // Opaque pass renderstate_t *opaque_rs = &m->rs[RENDER_PASS_OPAQUE]; { +#if 0 // @todo: we should keep blend_enabled=0, however our transparency detection still needs work opaque_rs->blend_enabled = 0; +#else + opaque_rs->blend_enabled = 1; + opaque_rs->blend_src = GL_SRC_ALPHA; + opaque_rs->blend_dst = GL_ONE_MINUS_SRC_ALPHA; +#endif opaque_rs->cull_face_mode = GL_BACK; opaque_rs->front_face = GL_CW; } @@ -4212,7 +4218,6 @@ void shader_colormap_model_internal(const char *col_name, const char *bool_name, typedef struct drawcall_t { - model_t *m; int mesh; union { uint64_t order; @@ -4250,6 +4255,9 @@ void model_draw_call(model_t m, int shader, int pass, vec3 cam_pos, mat44 model_ required_rs[i] = rs_idx; if (required_rs[i] < RENDER_PASS_OVERRIDES_BEGIN) { + if (m.flags & MODEL_TRANSPARENT) { + required_rs[i] = RENDER_PASS_TRANSPARENT; + } if (m.materials[i].layer[0].map.color.a < 1 || (m.materials[i].layer[0].map.texture && m.materials[i].layer[0].map.texture->transparent)) { required_rs[i] = RENDER_PASS_TRANSPARENT; } @@ -4274,7 +4282,7 @@ void model_draw_call(model_t m, int shader, int pass, vec3 cam_pos, mat44 model_ drawcall_t call; call.mesh = i; call.tex = m.textures[i]; - call.distance = -1; + call.distance = 0; if (m.shading == SHADING_PBR) call.tex = m.materials[i].layer[MATERIAL_CHANNEL_ALBEDO].map.texture ? m.materials[i].layer[MATERIAL_CHANNEL_ALBEDO].map.texture->id : m.materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture ? m.materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture->id : texture_checker().id; array_push(drawcalls, call); diff --git a/engine/split/v4k_render.h b/engine/split/v4k_render.h index 516cde3..e450eb5 100644 --- a/engine/split/v4k_render.h +++ b/engine/split/v4k_render.h @@ -597,6 +597,7 @@ enum MODEL_FLAGS { MODEL_MATCAPS = 16, MODEL_RIMLIGHT = 32, MODEL_PBR = 64, + MODEL_TRANSPARENT = 128, }; enum SHADING_MODE { diff --git a/engine/v4k.c b/engine/v4k.c index f55b5a3..d3c91be 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -20700,7 +20700,13 @@ void model_set_renderstates(model_t *m) { // Opaque pass renderstate_t *opaque_rs = &m->rs[RENDER_PASS_OPAQUE]; { +#if 0 // @todo: we should keep blend_enabled=0, however our transparency detection still needs work opaque_rs->blend_enabled = 0; +#else + opaque_rs->blend_enabled = 1; + opaque_rs->blend_src = GL_SRC_ALPHA; + opaque_rs->blend_dst = GL_ONE_MINUS_SRC_ALPHA; +#endif opaque_rs->cull_face_mode = GL_BACK; opaque_rs->front_face = GL_CW; } @@ -21011,7 +21017,6 @@ void shader_colormap_model_internal(const char *col_name, const char *bool_name, typedef struct drawcall_t { - model_t *m; int mesh; union { uint64_t order; @@ -21049,6 +21054,9 @@ void model_draw_call(model_t m, int shader, int pass, vec3 cam_pos, mat44 model_ required_rs[i] = rs_idx; if (required_rs[i] < RENDER_PASS_OVERRIDES_BEGIN) { + if (m.flags & MODEL_TRANSPARENT) { + required_rs[i] = RENDER_PASS_TRANSPARENT; + } if (m.materials[i].layer[0].map.color.a < 1 || (m.materials[i].layer[0].map.texture && m.materials[i].layer[0].map.texture->transparent)) { required_rs[i] = RENDER_PASS_TRANSPARENT; } @@ -21073,7 +21081,7 @@ void model_draw_call(model_t m, int shader, int pass, vec3 cam_pos, mat44 model_ drawcall_t call; call.mesh = i; call.tex = m.textures[i]; - call.distance = -1; + call.distance = 0; if (m.shading == SHADING_PBR) call.tex = m.materials[i].layer[MATERIAL_CHANNEL_ALBEDO].map.texture ? m.materials[i].layer[MATERIAL_CHANNEL_ALBEDO].map.texture->id : m.materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture ? m.materials[i].layer[MATERIAL_CHANNEL_DIFFUSE].map.texture->id : texture_checker().id; array_push(drawcalls, call); diff --git a/engine/v4k.h b/engine/v4k.h index 89e58c9..b0c03c3 100644 --- a/engine/v4k.h +++ b/engine/v4k.h @@ -3632,6 +3632,7 @@ enum MODEL_FLAGS { MODEL_MATCAPS = 16, MODEL_RIMLIGHT = 32, MODEL_PBR = 64, + MODEL_TRANSPARENT = 128, }; enum SHADING_MODE {