From 08786c7c1589fe5254e84a0f93526bfacff8460f Mon Sep 17 00:00:00 2001 From: korenkonder Date: Sat, 8 Jul 2023 00:13:33 +0300 Subject: [PATCH] Fix rendering of transparent objects in Umiyuri --- src/CRE/object.cpp | 3 +++ src/CRE/render_context.cpp | 17 ++++++++++++++--- src/CRE/shader_ft.cpp | 35 +++++++++++++++-------------------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 7d4fce27..d4b781c1 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -938,10 +938,13 @@ void object_material_msgpack_read(const char* path, const char* set_name, if (attrib) { msgpack* recieve_shadow = attrib->read("recieve_shadow"); msgpack* cast_shadow = attrib->read("cast_shadow"); + msgpack* transparent = attrib->read("transparent"); if (recieve_shadow) sub_mesh.attrib.m.recieve_shadow = recieve_shadow->read_bool(); if (cast_shadow) sub_mesh.attrib.m.cast_shadow = cast_shadow->read_bool(); + if (transparent) + sub_mesh.attrib.m.transparent = transparent->read_bool(); } } break; diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index 97d2f3d0..18ba87e3 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -1841,6 +1841,7 @@ namespace mdl { int32_t alpha_test = 0; float_t min_alpha = 1.0f; + float_t alpha_threshold = 0.0f; bool reflect = uniform_value[U_REFLECT] == 1; void(*func)(render_context * rctx, const ObjSubMeshArgs * args) = draw_sub_mesh_default; @@ -1864,19 +1865,21 @@ namespace mdl { func = draw_sub_mesh_translucent; else gl_state_set_depth_mask(GL_FALSE); + alpha_test = 1; min_alpha = 0.0f; + alpha_threshold = 0.0f; break; case OBJ_TYPE_TRANSPARENT: case OBJ_TYPE_TRANSPARENT_LOCAL: alpha_test = 1; min_alpha = 0.1f; + alpha_threshold = 0.5f; break; case OBJ_TYPE_SHADOW_CHARA: case OBJ_TYPE_SHADOW_STAGE: case OBJ_TYPE_SHADOW_OBJECT_CHARA: case OBJ_TYPE_SHADOW_OBJECT_STAGE: func = draw_sub_mesh_shadow; - min_alpha = 0.5f; break; case OBJ_TYPE_TYPE_6: func = draw_sub_mesh_translucent; @@ -1889,6 +1892,7 @@ namespace mdl { rctx_ptr->draw_state.shader_index = SHADER_FT_SIL; alpha_test = 1; min_alpha = 0.0f; + alpha_threshold = 0.99999994f; break; case OBJ_TYPE_REFLECT_CHARA_OPAQUE: gl_state_set_cull_face_mode(GL_FRONT); @@ -1913,6 +1917,7 @@ namespace mdl { func = draw_sub_mesh_reflect_reflect_map; alpha_test = 1; min_alpha = 0.1f; + alpha_threshold = 0.5f; break; case OBJ_TYPE_REFLECT_OPAQUE: alpha_test = 1; @@ -1923,11 +1928,13 @@ namespace mdl { case OBJ_TYPE_REFRACT_TRANSLUCENT: gl_state_set_depth_mask(GL_FALSE); min_alpha = 0.0f; + alpha_threshold = 0.0f; break; case OBJ_TYPE_REFLECT_TRANSPARENT: case OBJ_TYPE_REFRACT_TRANSPARENT: alpha_test = 1; min_alpha = 0.1f; + alpha_threshold = 0.0f; break; case OBJ_TYPE_SSS: func = draw_sub_mesh_sss; @@ -1938,7 +1945,7 @@ namespace mdl { default: break; } - rctx_ptr->obj_batch.g_max_alpha = { 0.0f, 0.0f, 0.0f, min_alpha }; + rctx_ptr->obj_batch.g_max_alpha = { 0.0f, 0.0f, alpha_threshold, min_alpha }; uniform_value[U_ALPHA_TEST] = alpha_test; for (ObjData*& i : obj[type]) { @@ -1995,6 +2002,7 @@ namespace mdl { int32_t alpha_test = 0; float_t min_alpha = 1.0f; + float_t alpha_threshold = 0.0f; bool reflect = uniform_value[U_REFLECT] == 1; void(*func)(render_context * rctx, const ObjSubMeshArgs * args) = draw_sub_mesh_default; @@ -2016,7 +2024,9 @@ namespace mdl { case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_3: case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_2_LOCAL: gl_state_set_depth_mask(GL_FALSE); + alpha_test = 1; min_alpha = 0.0f; + alpha_threshold = 0.0f; break; case OBJ_TYPE_TRANSPARENT_ALPHA_ORDER_1: case OBJ_TYPE_TRANSPARENT_ALPHA_ORDER_2: @@ -2024,11 +2034,12 @@ namespace mdl { case OBJ_TYPE_TRANSPARENT_ALPHA_ORDER_2_LOCAL: alpha_test = 1; min_alpha = 0.1f; + alpha_threshold = 0.5f; break; default: break; } - rctx_ptr->obj_batch.g_max_alpha = { 0.0f, 0.0f, 0.0f, min_alpha }; + rctx_ptr->obj_batch.g_max_alpha = { 0.0f, 0.0f, alpha_threshold, min_alpha }; uniform_value[U_ALPHA_TEST] = alpha_test; for (ObjData*& i : obj[type]) { diff --git a/src/CRE/shader_ft.cpp b/src/CRE/shader_ft.cpp index 08584cee..f0a2b8e1 100644 --- a/src/CRE/shader_ft.cpp +++ b/src/CRE/shader_ft.cpp @@ -405,13 +405,13 @@ static const int32_t lit_proj_fpt_unival_max[] = { }; static const int32_t simple_vpt_unival_max[] = { - //1, 1, 0, 0, 1, 0, 0, // 6th added - 1, 0, 0, // 0th removed, 3rd removed, 4th removed, 5th removed, 6th added + //1, 1, 0, 0, 1, 0, + 1, 0, // 0th removed, 3rd removed, 4th removed, 5th removed }; static const int32_t simple_fpt_unival_max[] = { - //0, 0, 2, 0, 0, 3, 1, // 6th added - 0, 2, 1, // 0th removed, 3rd removed, 4th removed, 5th removed, 6th added + //0, 0, 2, 0, 0, 3, + 0, 2, // 0th removed, 3rd removed, 4th removed, 5th removed }; static const int32_t silhouette_vpt_unival_max[] = { @@ -725,11 +725,11 @@ static const int32_t fade_fpt_unival_max[] = { };*/ static const int32_t water01_vpt_unival_max[] = { - 1, 1, 0, 0, 0, 0, 0, 1, 0, // 8th added + 1, 1, 0, 0, 0, 0, 0, 1, }; static const int32_t water01_fpt_unival_max[] = { - 0, 0, 2, 1, 1, 1, 1, 1, 1, // 8th added + 0, 0, 2, 1, 1, 1, 1, 1, }; /*static const int32_t water02_vpt_unival_max[] = { @@ -749,11 +749,11 @@ static const int32_t water_ring_fpt_unival_max[] = { };*/ static const int32_t water_particle_vpt_unival_max[] = { - 0, // 0th added + -1, }; static const int32_t water_particle_fpt_unival_max[] = { - 0, // 0th added + -1, }; /*static const int32_t snow_particle_vpt_unival_max[] = { @@ -927,11 +927,11 @@ static const int32_t fog_ptcl_fpt_unival_max[] = { }; static const int32_t particle_vpt_unival_max[] = { - 0, // 0th added + -1, }; static const int32_t particle_fpt_unival_max[] = { - 1, // 0th added + -1, }; static const int32_t glitter_particle_vpt_unival_max[] = { @@ -2107,8 +2107,7 @@ static const uniform_name STAGE_uniform[] = { U_FOG_HEIGHT, U_LIGHT_1, U12, - U_ALPHA_TEST, // 11th added - U_TEXTURE_BLEND, // 12th added + U_ALPHA_TEST, // 11th added }; static const uniform_name SKIN_uniform[] = { @@ -2268,7 +2267,6 @@ static const uniform_name SIMPLE_uniform[] = { //U_NORMAL, // 3rd removed //U_INSTANCE, // 4th removed //U2E, // 5th removed - U_ALPHA_TEST, // 6th added }; static const uniform_name SIL_uniform[] = { @@ -2374,7 +2372,6 @@ static const uniform_name WATER01_uniform[] = { U_ENV_MAP, U_SPECULAR, U_FOG_HEIGHT, - U_ALPHA_TEST, // 8th added }; /*static const uniform_name WATER02_uniform[] = { @@ -2387,7 +2384,7 @@ static const uniform_name WATER01_uniform[] = { };*/ static const uniform_name W_PTCL_uniform[] = { - U_ALPHA_TEST, // 0th added + U_INVALID, }; static const uniform_name SNOW_PT_uniform[] = { @@ -2485,7 +2482,7 @@ static const uniform_name FOGPTCL_uniform[] = { }; static const uniform_name PARTICL_uniform[] = { - U_ALPHA_TEST, // 0th added + U_INVALID, }; static const uniform_name GLITTER_PT_uniform[] = { @@ -2744,7 +2741,6 @@ static const bool SIMPLE_permut[] = { //false, // 3rd removed //false, // 4th removed //false, // 5th removed - false, // 6th added }; static const bool SIL_permut[] = { @@ -2850,7 +2846,6 @@ static const bool WATER01_permut[] = { false, false, false, - false, // 8th added }; static const bool WATER02_permut[] = { @@ -2863,7 +2858,7 @@ static const bool WATER02_permut[] = { };*/ static const bool W_PTCL_permut[] = { - false, // 0th added + false, }; static const bool SNOW_PT_permut[] = { @@ -2961,7 +2956,7 @@ static const bool FOGPTCL_permut[] = { }; static const bool PARTICL_permut[] = { - false, // 0th added + false, }; static const bool GLITTER_PT_permut[] = {