From b1af79b1dda20cdfb74f85aaf039ca3012bb2df0 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Fri, 12 Apr 2024 23:06:47 +0300 Subject: [PATCH] Moved Light Param data to it's file --- src/CRE/auth_3d.cpp | 1 + src/CRE/auth_3d.hpp | 1 + src/CRE/light_param.cpp | 920 ++++++++++++------- src/CRE/light_param.hpp | 40 +- src/CRE/mdl/disp_manager.cpp | 1 + src/CRE/pv_db.cpp | 1 + src/CRE/pv_expression.cpp | 1 + src/CRE/render_context.cpp | 235 ----- src/CRE/render_context.hpp | 7 - src/CRE/render_manager.cpp | 18 +- src/CRE/rob/motion.cpp | 1 + src/CRE/rob/skin_param.cpp | 1 + src/ReDIVA/classes/data_view/object.cpp | 2 + src/ReDIVA/classes/data_view/texture.cpp | 1 + src/ReDIVA/classes/graphics/post_process.cpp | 1 + src/ReDIVA/data_test/equip_test.cpp | 1 + src/ReDIVA/data_test/motion_test.cpp | 1 + src/ReDIVA/dw.cpp | 1 + src/ReDIVA/glitter_editor.hpp | 1 + src/ReDIVA/print_work.cpp | 1 + src/ReDIVA/pv_game/game_2d.cpp | 1 + src/ReDIVA/pv_game/pv_game_play_data.cpp | 1 + src/ReDIVA/render.cpp | 11 +- 23 files changed, 633 insertions(+), 616 deletions(-) diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index 8d726542..6fa90a7c 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -15,6 +15,7 @@ #include "../KKdLib/str_utils.hpp" #include "rob/rob.hpp" #include "clear_color.hpp" +#include "data.hpp" #include "effect.hpp" #include "object.hpp" #include "pv_db.hpp" diff --git a/src/CRE/auth_3d.hpp b/src/CRE/auth_3d.hpp index 6c42324d..1db8b3fe 100644 --- a/src/CRE/auth_3d.hpp +++ b/src/CRE/auth_3d.hpp @@ -8,6 +8,7 @@ #include #include #include "../KKdLib/default.hpp" +#include "../KKdLib/database/auth_3d.hpp" #include "../KKdLib/database/object.hpp" #include "../KKdLib/database/texture.hpp" #include "../KKdLib/a3da.hpp" diff --git a/src/CRE/light_param.cpp b/src/CRE/light_param.cpp index 4c286e51..d4d3e7db 100644 --- a/src/CRE/light_param.cpp +++ b/src/CRE/light_param.cpp @@ -8,62 +8,82 @@ #include "../KKdLib/str_utils.hpp" #include "render_context.hpp" -static void light_param_data_get_stage_name_string(std::string* str, int32_t stage_index); -static int32_t light_param_data_load_file(light_param_data* a1, p_file_handler* a2); -static void light_param_data_load_file_pv_cut(std::map& tree, - farc* f, light_param_data* default_light_param, int32_t pv_id); -static void light_param_data_load_pv_cut_file_names(light_param_data* light_param, int32_t cut_id, std::string* name); -static void light_param_data_load_stage_file_names(light_param_data* light_param, std::string* name); -static void light_param_data_set(light_param_data* a1, light_param_data_storage* storage, - light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); -static void light_param_storage_free_file_handlers(light_param_data_storage* a1); -static void light_param_storage_load_stages(light_param_data_storage* a1, std::vector& stage_indices); -static void light_param_storage_load_stages(light_param_data_storage* a1, - std::vector& stage_hashes, stage_database* stage_data); -static int32_t light_param_storage_load_file(light_param_data_storage* a1, bool read_now); -static void light_param_storage_reset(light_param_data_storage* a1); -static void light_param_storage_set_default_light_param(light_param_data_storage* a1, int32_t stage_index); -static void light_param_storage_set_pv_cut(light_param_data_storage* a1, - std::map::iterator* elem, int32_t cut_id, - light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); -static void light_param_storage_set_stage(light_param_data_storage* a1, - std::map::iterator* elem, int32_t stage_index, - light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); +struct light_param_data_storage; + +struct light_param_data { + std::string name; + std::string paths[6]; + std::string files[6]; + bool pv; + light_param_light light; + light_param_fog fog; + light_param_glow glow; + light_param_ibl ibl; + light_param_wind wind; + light_param_face face; + + light_param_data(); + ~light_param_data(); + + int32_t load_file(p_file_handler file_handlers[6]); + void load_pv_cut_file_names(int32_t cut_id, const std::string& name); + void load_stage_file_names(const std::string& name); + void set(light_param_data_storage* storage, + light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); + + static void load_file_pv_cut(std::map& tree, + farc* f, light_param_data* default_light_param, int32_t pv_id); + + static void set_face(light_param_face* face); + static void set_glow(light_param_glow* glow); + static void set_fog(light_param_fog* f); + static void set_ibl(light_param_ibl* ibl, light_param_data_storage* storage); + static void set_ibl_diffuse(light_param_ibl_diffuse* diffuse, int32_t level); + static void set_ibl_specular(light_param_ibl_specular* specular); + static void set_light(light_param_light* light); + static void set_wind(light_param_wind* w); +}; + +struct light_param_data_storage { + GLuint textures[5]; + int32_t state; + std::string name; + int32_t stage_index; + light_param_data default_light_param; + std::map stage; + std::map::iterator current_light_param; + std::map pv_cut; + p_file_handler file_handlers[6]; + p_file_handler farc_file_handler; + int32_t pv_id; + + light_param_data_storage(); + ~light_param_data_storage(); + + void free_file_handlers(); + void load_stages(const std::vector& stage_indices); + void load_stages(const std::vector& stage_hashes, stage_database* stage_data); + int32_t load_file(bool read_now); + void reset(); + void set_default_light_param(int32_t stage_index); + void set_pv_cut(std::map::iterator* elem, int32_t cut_id, + light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); + void set_stage(std::map::iterator* elem, int32_t stage_index, + light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); + + static void unload(); +}; + +static void light_param_data_get_stage_name_string(std::string& str, int32_t stage_index); +static void light_param_data_get_stage_name_string(std::string& str, + uint32_t stage_hash, stage_database* stage_data); light_param_data_storage* light_param_data_storage_data; extern render_context* rctx_ptr; -light_param_data::light_param_data() : pv() { - -} - -light_param_data::~light_param_data() { - -} - int32_t light_param_data_load_file() { - return light_param_storage_load_file(light_param_data_storage_data, false); -} - -light_param_data_storage::light_param_data_storage() : textures(), -state(), stage_index(), default_stage_node(), pv_id() { - -} - -light_param_data_storage::~light_param_data_storage() { - -} - -void light_param_data_storage::load(data_struct* data) { - glGenTextures(5, light_param_data_storage_data->textures); - light_param_data_storage_data_load_stage(0); - while (light_param_storage_load_file(light_param_data_storage_data, true)); - light_param_storage_set_default_light_param(light_param_data_storage_data, 0); -} - -void light_param_data_storage::unload() { - glDeleteTextures(5, light_param_data_storage_data->textures); + return light_param_data_storage_data->load_file(false); } void light_param_data_storage_data_init() { @@ -79,40 +99,56 @@ int32_t light_param_data_storage_data_get_stage_index() { } void light_param_data_storage_data_free_file_handlers() { - light_param_storage_free_file_handlers(light_param_data_storage_data); + light_param_data_storage_data->free_file_handlers(); +} + +void light_param_data_storage_data_load() { + glGenTextures(5, light_param_data_storage_data->textures); + light_param_data_storage_data_load_stage(0); + while (light_param_data_storage_data->load_file(true)); + light_param_data_storage_data->set_default_light_param(0); } int32_t light_param_data_storage_data_load_file() { - return light_param_storage_load_file(light_param_data_storage_data, false); + return light_param_data_storage_data->load_file(false); } void light_param_data_storage_data_load_stage(int32_t stage_index) { std::vector stage_indices = { stage_index }; - light_param_storage_load_stages(light_param_data_storage_data, stage_indices); + light_param_data_storage_data->load_stages(stage_indices); } void light_param_data_storage_data_load_stage( uint32_t stage_hash, stage_database* stage_data) { std::vector stage_hashes = { stage_hash }; - light_param_storage_load_stages(light_param_data_storage_data, stage_hashes, stage_data); + light_param_data_storage_data->load_stages(stage_hashes, stage_data); } void light_param_data_storage_data_load_stages(std::vector& stage_indices) { - light_param_storage_load_stages(light_param_data_storage_data, stage_indices); + light_param_data_storage_data->load_stages(stage_indices); } void light_param_data_storage_data_load_stages( std::vector& stage_hashes, stage_database* stage_data) { - light_param_storage_load_stages(light_param_data_storage_data, stage_hashes, stage_data); + light_param_data_storage_data->load_stages(stage_hashes, stage_data); } void light_param_data_storage_data_reset() { - light_param_storage_reset(light_param_data_storage_data); + light_param_data_storage_data->reset(); } void light_param_data_storage_data_set_default_light_param(light_param_data_storage_flags flags) { - light_param_data_set(&light_param_data_storage_data->default_light_param, - light_param_data_storage_data, flags); + light_param_data_storage_data->default_light_param.set(light_param_data_storage_data, flags); +} + +void light_param_data_storage_data_set_ibl() { + static const int32_t ibl_texture_index[] = { + 9, 10, 11, 12, 13 + }; + + for (int32_t i = 0; i < 5; i++) + gl_state_active_bind_texture_cube_map(ibl_texture_index[i], + light_param_data_storage_data->textures[i]); } void light_param_data_storage_data_set_pv_id(int32_t pv_id) { @@ -122,170 +158,144 @@ void light_param_data_storage_data_set_pv_id(int32_t pv_id) { void light_param_data_storage_data_set_pv_cut(int32_t cut_id, light_param_data_storage_flags flags) { std::map::iterator elem; - light_param_storage_set_pv_cut(light_param_data_storage_data, &elem, cut_id); + light_param_data_storage_data->set_pv_cut(&elem, cut_id); } void light_param_data_storage_data_set_stage(int32_t stage_id, light_param_data_storage_flags flags) { std::map::iterator elem; - light_param_storage_set_stage(light_param_data_storage_data, &elem, stage_id); + light_param_data_storage_data->set_stage(&elem, stage_id); +} + +void light_param_data_storage_data_unload() { + glDeleteTextures(5, light_param_data_storage_data->textures); } void light_param_data_storage_data_free() { delete light_param_data_storage_data; } -static int32_t light_param_storage_load_file(light_param_data_storage* a1, bool read_now) { - if (a1->state == 1) { - light_param_data* light_param = &a1->stage_light_param_iterator->second; - std::string* paths = light_param->paths; - std::string* files = light_param->files; - for (int32_t i = 0; i < 6; i++) - a1->file_handlers[i].read_file(&data_list[DATA_AFT], paths[i].c_str(), files[i].c_str()); - a1->state = 2; - return 1; - } - else if (a1->state == 2) { - for (int32_t i = 0; i < 6; ++i) - if (read_now) - a1->file_handlers[i].read_now(); - else if (a1->file_handlers[i].check_not_ready()) - return 1; +light_param_data::light_param_data() : pv() { - int32_t load_error = light_param_data_load_file(&a1->stage_light_param_iterator->second, a1->file_handlers); - - for (int32_t i = 0; i < 6; i++) - a1->file_handlers[i].reset(); - - a1->stage_light_param_iterator++; - - if (a1->stage_light_param_iterator == a1->stage.end()) - a1->state = 3; - else - a1->state = 1; - - if (load_error) { - for (int32_t i = 0; i < 6; i++) - a1->file_handlers[i].call_free_callback(); - a1->state = 0; - return 0; - } - return 1; - } - else if (a1->state == 3) { - char buf[0x100]; - sprintf_s(buf, sizeof(buf), "light_pv%03d.farc", a1->pv_id); - if (a1->farc_file_handler.read_file(&data_list[DATA_AFT], "rom/light_param/", buf)) - a1->state = 4; - else { - a1->farc_file_handler.reset(); - a1->state = 0; - return 0; - } - return 1; - } - else if (a1->state == 4) { - if (read_now) - a1->farc_file_handler.read_now(); - else if (a1->farc_file_handler.check_not_ready()) - return 1; - - farc a1a; - a1a.read(a1->farc_file_handler.get_data(), a1->farc_file_handler.get_size(), true); - if (a1a.files.size()) - light_param_data_load_file_pv_cut(a1->pv_cut, &a1a, &a1->default_light_param, a1->pv_id); - a1->state = 0; - return 0; - } - return 0; } -static void light_param_data_get_stage_name_string(std::string* str, int32_t stage_index) { - str->clear(); +light_param_data::~light_param_data() { - data_struct* aft_data = &data_list[DATA_AFT]; - stage_database* aft_stage_data = &aft_data->data_ft.stage_data; - - const char* stage_name = aft_stage_data->get_stage_name(stage_index); - if (!stage_name) - return; - - size_t length = utf8_length(stage_name); - if (length <= 3) - return; - - for (size_t i = 3; i < length; i++) - if (stage_name[i] == '_') { - length = i; - break; - } - - str->assign(stage_name + 3, length - 3); - for (char& c : *str) - if (c >= 'A' && c <= 'Z') - c += 0x20; } -static void light_param_data_get_stage_name_string(std::string* str, - uint32_t stage_hash, stage_database* stage_data) { - str->clear(); +int32_t light_param_data::load_file(p_file_handler file_handlers[6]) { + if (file_handlers[0].ptr) { + ibl = light_param_ibl(); + ibl.read(file_handlers[0].get_data(), file_handlers[0].get_size()); + } - const char* stage_name = stage_data->get_stage_name_modern(stage_hash); - if (!stage_name) - return; + if (file_handlers[1].ptr) { + light = light_param_light(); + light.read(file_handlers[1].get_data(), file_handlers[1].get_size()); + } - size_t length = utf8_length(stage_name); - if (length <= 3) - return; + if (file_handlers[2].ptr) { + fog = light_param_fog(); + fog.read(file_handlers[2].get_data(), file_handlers[2].get_size()); + } - for (size_t i = 3; i < length; i++) - if (stage_name[i] == '_') { - length = i; - break; - } + if (file_handlers[3].ptr) { + glow = light_param_glow(); + glow.read(file_handlers[3].get_data(), file_handlers[3].get_size()); + } - str->assign(stage_name + 3, length - 3); - for (char& c : *str) - if (c >= 'A' && c <= 'Z') - c += 0x20; + if (file_handlers[4].ptr) { + wind = light_param_wind(); + wind.read(file_handlers[4].get_data(), file_handlers[4].get_size()); + } + + if (file_handlers[5].ptr) { + face = light_param_face(); + face.read(file_handlers[5].get_data(), file_handlers[5].get_size()); + } + + return !(ibl.ready | light.ready | fog.ready | glow.ready | wind.ready | face.ready) ? 1 : 0; } -static int32_t light_param_data_load_file(light_param_data* a1, p_file_handler* a2) { - if (a2[0].ptr) { - a1->ibl = light_param_ibl(); - a1->ibl.read(a2[0].get_data(), a2[0].get_size()); - } +void light_param_data::load_pv_cut_file_names(int32_t cut_id, const std::string& name) { + char buf[0x100]; - if (a2[1].ptr) { - a1->light = light_param_light(); - a1->light.read(a2[1].get_data(), a2[1].get_size()); - } + sprintf_s(buf, sizeof(buf), "%s_c%03d", name.c_str(), cut_id); + this->name.assign(buf); - if (a2[2].ptr) { - a1->fog = light_param_fog(); - a1->fog.read(a2[2].get_data(), a2[2].get_size()); - } + sprintf_s(buf, sizeof(buf), "%s.ibl", this->name.c_str()); + paths[0].assign("rom/ibl/"); + files[0].assign(buf); - if (a2[3].ptr) { - a1->glow = light_param_glow(); - a1->glow.read(a2[3].get_data(), a2[3].get_size()); - } + sprintf_s(buf, sizeof(buf), "light_%s.txt", this->name.c_str()); + paths[1].assign("rom/light_param/"); + files[1].assign(buf); - if (a2[4].ptr) { - a1->wind = light_param_wind(); - a1->wind.read(a2[4].get_data(), a2[4].get_size()); - } + sprintf_s(buf, sizeof(buf), "fog_%s.txt", this->name.c_str()); + paths[2].assign("rom/light_param/"); + files[2].assign(buf); - if (a2[5].ptr) { - a1->face = light_param_face(); - a1->face.read(a2[5].get_data(), a2[5].get_size()); - } + sprintf_s(buf, sizeof(buf), "glow_%s.txt", this->name.c_str()); + paths[3].assign("rom/light_param/"); + files[3].assign(buf); - return !(a1->ibl.ready | a1->light.ready | a1->fog.ready - | a1->glow.ready | a1->wind.ready | a1->face.ready) ? 1 : 0; + sprintf_s(buf, sizeof(buf), "wind_%s.txt", this->name.c_str()); + paths[4].assign("rom/light_param/"); + files[4].assign(buf); + + sprintf_s(buf, sizeof(buf), "face_%s.txt", this->name.c_str()); + paths[5].assign("rom/light_param/"); + files[5].assign(buf); } -static void light_param_data_load_file_pv_cut(std::map& tree, +void light_param_data::load_stage_file_names(const std::string& name) { + char buf[0x100]; + + this->name.assign(name); + + sprintf_s(buf, sizeof(buf), "%s.ibl", this->name.c_str()); + paths[0].assign("rom/ibl/"); + files[0].assign(buf); + + sprintf_s(buf, sizeof(buf), "light_%s.txt", this->name.c_str()); + paths[1].assign("rom/light_param/"); + files[1].assign(buf); + + sprintf_s(buf, sizeof(buf), "fog_%s.txt", this->name.c_str()); + paths[2].assign("rom/light_param/"); + files[2].assign(buf); + + sprintf_s(buf, sizeof(buf), "glow_%s.txt", this->name.c_str()); + paths[3].assign("rom/light_param/"); + files[3].assign(buf); + + sprintf_s(buf, sizeof(buf), "wind_%s.txt", this->name.c_str()); + paths[4].assign("rom/light_param/"); + files[4].assign(buf); + + sprintf_s(buf, sizeof(buf), "face_%s.txt", this->name.c_str()); + paths[5].assign("rom/light_param/"); + files[5].assign(buf); +} + +void light_param_data::set(light_param_data_storage* storage, light_param_data_storage_flags flags) { + if ((!pv || light.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_LIGHT)) + light_param_data::set_light(&light); + if ((!pv || fog.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_FOG)) + light_param_data::set_fog(&fog); + if ((!pv || glow.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_GLOW)) + light_param_data::set_glow(&glow); + if ((!pv || ibl.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_IBL)) + light_param_data::set_ibl(&ibl, storage); + if (!pv) { + if (flags & LIGHT_PARAM_DATA_STORAGE_WIND) + light_param_data::set_wind(&wind); + if (face.ready && (flags & LIGHT_PARAM_DATA_STORAGE_FACE)) + light_param_data::set_face(&face); + } +} + +void light_param_data::load_file_pv_cut(std::map& tree, farc* f, light_param_data* default_light_param, int32_t pv_id) { char buf[0x100]; @@ -399,7 +409,7 @@ static void light_param_data_load_file_pv_cut(std::mapwind.ready = false; light_param->face.ready = false; light_param->pv = true; - light_param_data_load_pv_cut_file_names(light_param, cut_id, &pv_str); + light_param->load_pv_cut_file_names(cut_id, pv_str); } if (type == 1) { @@ -425,133 +435,294 @@ static void light_param_data_load_file_pv_cut(std::mapc_str(), cut_id); - light_param->name = buf; - - sprintf_s(buf, sizeof(buf), "%s.ibl", light_param->name.c_str()); - light_param->paths[0] = "rom/ibl/"; - light_param->files[0] = buf; - - sprintf_s(buf, sizeof(buf), "light_%s.txt", light_param->name.c_str()); - light_param->paths[1] = "rom/light_param/"; - light_param->files[1] = buf; - - sprintf_s(buf, sizeof(buf), "fog_%s.txt", light_param->name.c_str()); - light_param->paths[2] = "rom/light_param/"; - light_param->files[2] = buf; - - sprintf_s(buf, sizeof(buf), "glow_%s.txt", light_param->name.c_str()); - light_param->paths[3] = "rom/light_param/"; - light_param->files[3] = buf; - - sprintf_s(buf, sizeof(buf), "wind_%s.txt", light_param->name.c_str()); - light_param->paths[4] = "rom/light_param/"; - light_param->files[4] = buf; - - sprintf_s(buf, sizeof(buf), "face_%s.txt", light_param->name.c_str()); - light_param->paths[5] = "rom/light_param/"; - light_param->files[5] = buf; +void light_param_data::set_face(light_param_face* face) { + rctx_ptr->face.set_offset(face->offset); + rctx_ptr->face.set_scale(face->scale); + rctx_ptr->face.set_position(face->position); + rctx_ptr->face.set_direction(face->direction); } -void light_param_data_load_stage_file_names(light_param_data* light_param, std::string* name) { - char buf[0x100]; +void light_param_data::set_fog(light_param_fog* f) { + for (int32_t i = FOG_DEPTH; i < FOG_MAX; i++) { + light_param_fog_group* group = &f->group[i]; + ::fog* fog = &rctx_ptr->fog[i]; - light_param->name = *name; + if (group->has_type) + fog->set_type(group->type); - sprintf_s(buf, sizeof(buf), "%s.ibl", light_param->name.c_str()); - light_param->paths[0] = "rom/ibl/"; - light_param->files[0] = buf; + if (group->has_density) + fog->set_density(group->density); - sprintf_s(buf, sizeof(buf), "light_%s.txt", light_param->name.c_str()); - light_param->paths[1] = "rom/light_param/"; - light_param->files[1] = buf; + if (group->has_linear) { + fog->set_start(group->linear_start); + fog->set_end(group->linear_end); + } - sprintf_s(buf, sizeof(buf), "fog_%s.txt", light_param->name.c_str()); - light_param->paths[2] = "rom/light_param/"; - light_param->files[2] = buf; - - sprintf_s(buf, sizeof(buf), "glow_%s.txt", light_param->name.c_str()); - light_param->paths[3] = "rom/light_param/"; - light_param->files[3] = buf; - - sprintf_s(buf, sizeof(buf), "wind_%s.txt", light_param->name.c_str()); - light_param->paths[4] = "rom/light_param/"; - light_param->files[4] = buf; - - sprintf_s(buf, sizeof(buf), "face_%s.txt", light_param->name.c_str()); - light_param->paths[5] = "rom/light_param/"; - light_param->files[5] = buf; -} - -static void light_param_data_set(light_param_data* a1, light_param_data_storage* storage, - light_param_data_storage_flags flags) { - if ((!a1->pv || a1->light.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_LIGHT)) - rctx_ptr->light_param_data_light_set(&a1->light); - if ((!a1->pv || a1->fog.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_FOG)) - rctx_ptr->light_param_data_fog_set(&a1->fog); - if ((!a1->pv || a1->glow.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_GLOW)) - rctx_ptr->light_param_data_glow_set(&a1->glow); - if ((!a1->pv || a1->ibl.ready) && (flags & LIGHT_PARAM_DATA_STORAGE_IBL)) - rctx_ptr->light_param_data_ibl_set(&a1->ibl, storage); - if (!a1->pv) { - if (flags & LIGHT_PARAM_DATA_STORAGE_WIND) - rctx_ptr->light_param_data_wind_set(&a1->wind); - if (a1->face.ready && (flags & LIGHT_PARAM_DATA_STORAGE_FACE)) - rctx_ptr->light_param_data_face_set(&a1->face); + if (group->has_color) + fog->set_color(group->color); } } -static void light_param_storage_free_file_handlers(light_param_data_storage* a1) { - for (int32_t i = 0; i < 6; ++i) - a1->file_handlers[i].reset(); - a1->farc_file_handler.reset(); +void light_param_data::set_glow(light_param_glow* glow) { + rndr::Render* rend = &rctx_ptr->render; + + rend->set_auto_exposure(true); + rend->set_tone_map(TONE_MAP_YCC_EXPONENT); + rend->reset_saturate_coeff(0, false); + rend->reset_scene_fade(0); + rend->reset_tone_trans(0); + + if (glow->has_exposure) + rend->set_exposure(glow->exposure); + + if (glow->has_gamma) + rend->set_gamma(glow->gamma); + + if (glow->has_saturate_power) + rend->set_saturate_power(glow->saturate_power); + + if (glow->has_saturate_coef) + rend->set_saturate_coeff(glow->saturate_coef, 0, false); + + if (glow->has_flare) + rend->set_lens(glow->flare); + + if (glow->has_sigma) + rend->set_radius(glow->sigma); + + if (glow->has_intensity) + rend->set_intensity(glow->intensity); + + if (glow->has_auto_exposure) + rend->set_auto_exposure(glow->auto_exposure); + + if (glow->has_tone_map_method) + rend->set_tone_map(glow->tone_map_method); + + if (glow->has_fade_color) { + vec4 fade_color = glow->fade_color; + rend->set_scene_fade(fade_color, 0); + rend->set_scene_fade_blend_func(glow->fade_color_blend_func, 0); + } + + if (glow->has_tone_transform) + rend->set_tone_trans(glow->tone_transform_start, glow->tone_transform_end, 0); } -static void light_param_storage_load_stages(light_param_data_storage* a1, std::vector& stage_indices) { - if (a1->state) +void light_param_data::set_ibl(light_param_ibl* ibl, light_param_data_storage* storage) { + if (!ibl->ready) + return; + + for (int32_t i = 0, j = -1; i < 5; i++, j++) { + gl_state_bind_texture_cube_map(storage->textures[i]); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + if (!i) { + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 1); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + light_param_data::set_ibl_diffuse(&ibl->diffuse[0], 0); + light_param_data::set_ibl_diffuse(&ibl->diffuse[1], 1); + } + else { + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, ibl->specular[j].max_level); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_LOD_BIAS, 0.0f); + light_param_data::set_ibl_specular(&ibl->specular[j]); + } + } + gl_state_bind_texture_cube_map(0); + + ::light_set* set = &rctx_ptr->light_set[LIGHT_SET_MAIN]; + set->set_irradiance(ibl->diff_coef[1][0], ibl->diff_coef[1][1], ibl->diff_coef[1][2]); + + float_t len; + vec3 pos; + + light_data* l = &set->lights[LIGHT_CHARA]; + l->get_position(pos); + len = vec3::length(pos); + if (fabsf(len - 1.0f) < 0.02f) + l->set_position(ibl->lit_dir[0]); + + l->set_ibl_color0(ibl->lit_col[0]); + l->set_ibl_color1(ibl->lit_col[2]); + l->set_ibl_direction(ibl->lit_dir[0]); + + l = &set->lights[LIGHT_STAGE]; + l->get_position(pos); + len = vec3::length(pos); + if (fabsf(len - 1.0f) < 0.02f) + l->set_position(ibl->lit_dir[1]); + + l->set_ibl_color0(ibl->lit_col[1]); + l->set_ibl_direction(ibl->lit_dir[1]); +} + +void light_param_data::set_ibl_diffuse(light_param_ibl_diffuse* diffuse, int32_t level) { + int32_t size = diffuse->size; + size_t data_size = size; + data_size = 4 * data_size * data_size; + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 0]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 1]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 2]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 3]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 4]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 5]); +} + +void light_param_data::set_ibl_specular(light_param_ibl_specular* specular) { + int32_t size = specular->size; + int32_t max_level = specular->max_level; + for (int32_t i = 0; i <= max_level; i++, size /= 2) { + std::vector& data = specular->data[i]; + size_t data_size = size; + data_size = 4 * data_size * data_size; + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, i, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 0]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, i, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 1]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, i, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 2]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, i, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 3]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, i, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 4]); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, i, GL_RGBA16F, + size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 5]); + } +} + +void light_param_data::set_light(light_param_light* light) { + for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) { + light_param_light_group* group = &light->group[i]; + ::light_set* set = &rctx_ptr->light_set[i]; + + for (int32_t j = LIGHT_CHARA; j < LIGHT_MAX; j++) { + light_param_light_data* data = &group->data[j]; + light_data* light = &set->lights[j]; + + if (data->has_type) + light->set_type(data->type); + + if (data->has_ambient) + light->set_ambient(data->ambient); + + if (data->has_diffuse) + light->set_diffuse(data->diffuse); + + if (data->has_specular) + light->set_specular(data->specular); + + if (data->has_position) + light->set_position(data->position); + + if (data->has_spot_direction) + light->set_spot_direction(data->spot_direction); + + if (data->has_spot_exponent) + light->set_spot_exponent(data->spot_exponent); + + if (data->has_spot_cutoff) + light->set_spot_cutoff(data->spot_cutoff); + + if (data->has_attenuation) + light->set_attenuation(data->attenuation); + + light->set_clip_plane(data->clip_plane); + + if (data->has_tone_curve) + light->set_tone_curve(data->tone_curve); + } + } +} + +void light_param_data::set_wind(light_param_wind* w) { + ::wind* wind = task_wind->ptr; + if (w->has_scale) + wind->scale = w->scale; + + if (w->has_cycle) + wind->cycle = w->cycle; + + if (w->has_rot) { + wind->rot_y = w->rot_y; + wind->rot_z = w->rot_z; + } + + if (w->has_bias) + wind->bias = w->bias; + + for (int32_t i = 0; i < 16; i++) + if (w->has_spc[i]) { + wind->spc[i].cos = w->spc[i].cos; + wind->spc[i].sin = w->spc[i].sin; + } +} + +light_param_data_storage::light_param_data_storage() : textures(), state(), stage_index(), pv_id() { + +} + +light_param_data_storage::~light_param_data_storage() { + +} + +void light_param_data_storage::free_file_handlers() { + for (int32_t i = 0; i < 6; ++i) + file_handlers[i].reset(); + farc_file_handler.reset(); +} + +void light_param_data_storage::load_stages(const std::vector& stage_indices) { + if (state) for (int32_t i = 0; i < 6; ++i) - if (a1->file_handlers[i].check_not_ready()) - a1->file_handlers[i].call_free_callback(); + if (file_handlers[i].check_not_ready()) + file_handlers[i].call_free_callback(); - a1->stage_index = -1; - a1->stage.clear(); + stage_index = -1; + stage.clear(); - for (int32_t& i : stage_indices) { + for (const int32_t& i : stage_indices) { std::string name; - light_param_data_get_stage_name_string(&name, i); + light_param_data_get_stage_name_string(name, i); if (!name.size()) continue; - std::map::iterator elem = a1->stage.find(i); + std::map::iterator elem = stage.find(i); light_param_data* light_param; - if (elem != a1->stage.end()) + if (elem != stage.end()) light_param = &elem->second; else - light_param = &a1->stage.insert({ i, a1->default_light_param }).first->second; + light_param = &stage.insert({ i, default_light_param }).first->second; - light_param_data_load_stage_file_names(light_param, &name); + light_param->load_stage_file_names(name); light_param->pv = false; } - a1->stage_light_param_iterator = a1->stage.begin(); - a1->state = a1->stage.size() ? 1 : 0; + current_light_param = stage.begin(); + state = stage.size() ? 1 : 0; } -static void light_param_storage_load_stages(light_param_data_storage* a1, - std::vector& stage_hashes, stage_database* stage_data) { - if (a1->state) +void light_param_data_storage::load_stages(const std::vector& stage_hashes, stage_database* stage_data) { + if (state) for (int32_t i = 0; i < 6; ++i) - if (a1->file_handlers[i].check_not_ready()) - a1->file_handlers[i].call_free_callback(); + if (file_handlers[i].check_not_ready()) + file_handlers[i].call_free_callback(); - a1->stage_index = -1; - a1->stage.clear(); + stage_index = -1; + stage.clear(); - for (uint32_t& i : stage_hashes) { + for (const uint32_t& i : stage_hashes) { std::string name; - light_param_data_get_stage_name_string(&name, i, stage_data); + light_param_data_get_stage_name_string(name, i, stage_data); if (!name.size()) continue; @@ -559,51 +730,164 @@ static void light_param_storage_load_stages(light_param_data_storage* a1, if (!strncmp(name.c_str(), "pv0", min_def(name_len, 3))) name[2] = '8'; - std::map::iterator elem = a1->stage.find(i); + std::map::iterator elem = stage.find(i); light_param_data* light_param; - if (elem != a1->stage.end()) + if (elem != stage.end()) light_param = &elem->second; else - light_param = &a1->stage.insert({ i, a1->default_light_param }).first->second; + light_param = &stage.insert({ i, default_light_param }).first->second; - light_param_data_load_stage_file_names(light_param, &name); + light_param->load_stage_file_names(name); light_param->pv = false; } - a1->stage_light_param_iterator = a1->stage.begin(); - a1->state = a1->stage.size() ? 1 : 0; + current_light_param = stage.begin(); + state = stage.size() ? 1 : 0; } -static void light_param_storage_reset(light_param_data_storage* a1) { - a1->stage.clear(); - a1->pv_cut.clear(); - a1->pv_id = 0; - for (p_file_handler& i : a1->file_handlers) +int32_t light_param_data_storage::load_file(bool read_now) { + if (state == 1) { + light_param_data* light_param = ¤t_light_param->second; + std::string* paths = light_param->paths; + std::string* files = light_param->files; + for (int32_t i = 0; i < 6; i++) + file_handlers[i].read_file(&data_list[DATA_AFT], paths[i].c_str(), files[i].c_str()); + state = 2; + return 1; + } + else if (state == 2) { + for (int32_t i = 0; i < 6; ++i) + if (read_now) + file_handlers[i].read_now(); + else if (file_handlers[i].check_not_ready()) + return 1; + + int32_t load_error = current_light_param->second.load_file(file_handlers); + + for (int32_t i = 0; i < 6; i++) + file_handlers[i].reset(); + + current_light_param++; + + if (current_light_param == stage.end()) + state = 3; + else + state = 1; + + if (load_error) { + for (int32_t i = 0; i < 6; i++) + file_handlers[i].call_free_callback(); + state = 0; + return 0; + } + return 1; + } + else if (state == 3) { + char buf[0x100]; + sprintf_s(buf, sizeof(buf), "light_pv%03d.farc", pv_id); + if (farc_file_handler.read_file(&data_list[DATA_AFT], "rom/light_param/", buf)) + state = 4; + else { + farc_file_handler.reset(); + state = 0; + return 0; + } + return 1; + } + else if (state == 4) { + if (read_now) + farc_file_handler.read_now(); + else if (farc_file_handler.check_not_ready()) + return 1; + + farc a1a; + a1a.read(farc_file_handler.get_data(), farc_file_handler.get_size(), true); + if (a1a.files.size()) + light_param_data::load_file_pv_cut(pv_cut, &a1a, &default_light_param, pv_id); + state = 0; + return 0; + } + return 0; +} + +void light_param_data_storage::reset() { + stage.clear(); + pv_cut.clear(); + pv_id = 0; + for (p_file_handler& i : file_handlers) i.reset(); - a1->farc_file_handler.reset(); + farc_file_handler.reset(); } -static void light_param_storage_set_default_light_param(light_param_data_storage* a1, int32_t stage_index) { +void light_param_data_storage::set_default_light_param(int32_t stage_index) { std::map::iterator elem; - light_param_storage_set_stage(a1, &elem, stage_index); - if (elem != a1->stage.end()) - a1->default_light_param = elem->second; + set_stage(&elem, stage_index); + if (elem != stage.end()) + default_light_param = elem->second; } -static void light_param_storage_set_pv_cut(light_param_data_storage* a1, - std::map::iterator* elem, int32_t cut_id, +void light_param_data_storage::set_pv_cut(std::map::iterator* elem, int32_t cut_id, light_param_data_storage_flags flags) { - *elem = a1->pv_cut.find(cut_id); - if (*elem != a1->pv_cut.end()) - light_param_data_set(&(*elem)->second, a1); + *elem = pv_cut.find(cut_id); + if (*elem != pv_cut.end()) + (*elem)->second.set(this); } -static void light_param_storage_set_stage(light_param_data_storage* a1, - std::map::iterator* elem, int32_t stage_index, +void light_param_data_storage::set_stage(std::map::iterator* elem, int32_t stage_index, light_param_data_storage_flags flags) { - *elem = a1->stage.find(stage_index); - if (*elem != a1->stage.end()) { - a1->stage_index = stage_index; - a1->name = (*elem)->second.name; - light_param_data_set(&(*elem)->second, a1); + *elem = stage.find(stage_index); + if (*elem != stage.end()) { + this->stage_index = stage_index; + name = (*elem)->second.name; + (*elem)->second.set(this); } } + +static void light_param_data_get_stage_name_string(std::string& str, int32_t stage_index) { + str.clear(); + + data_struct* aft_data = &data_list[DATA_AFT]; + stage_database* aft_stage_data = &aft_data->data_ft.stage_data; + + const char* stage_name = aft_stage_data->get_stage_name(stage_index); + if (!stage_name) + return; + + size_t length = utf8_length(stage_name); + if (length <= 3) + return; + + for (size_t i = 3; i < length; i++) + if (stage_name[i] == '_') { + length = i; + break; + } + + str.assign(stage_name + 3, length - 3); + for (char& c : str) + if (c >= 'A' && c <= 'Z') + c += 0x20; +} + +static void light_param_data_get_stage_name_string(std::string& str, + uint32_t stage_hash, stage_database* stage_data) { + str.clear(); + + const char* stage_name = stage_data->get_stage_name_modern(stage_hash); + if (!stage_name) + return; + + size_t length = utf8_length(stage_name); + if (length <= 3) + return; + + for (size_t i = 3; i < length; i++) + if (stage_name[i] == '_') { + length = i; + break; + } + + str.assign(stage_name + 3, length - 3); + for (char& c : str) + if (c >= 'A' && c <= 'Z') + c += 0x20; +} diff --git a/src/CRE/light_param.hpp b/src/CRE/light_param.hpp index 8f0d07ab..41ad90a9 100644 --- a/src/CRE/light_param.hpp +++ b/src/CRE/light_param.hpp @@ -29,47 +29,11 @@ enum light_param_data_storage_flags { LIGHT_PARAM_DATA_STORAGE_ALL = 0x3F, }; -struct light_param_data { - std::string name; - std::string paths[6]; - std::string files[6]; - bool pv; - light_param_light light; - light_param_fog fog; - light_param_glow glow; - light_param_ibl ibl; - light_param_wind wind; - light_param_face face; - - light_param_data(); - ~light_param_data(); -}; - -struct light_param_data_storage { - GLuint textures[5]; - int32_t state; - std::string name; - int32_t stage_index; - light_param_data default_light_param; - std::map stage; - std::map* default_stage_node; - std::map pv_cut; - std::map::iterator stage_light_param_iterator; - p_file_handler file_handlers[6]; - p_file_handler farc_file_handler; - int32_t pv_id; - - light_param_data_storage(); - ~light_param_data_storage(); - - static void load(data_struct* data); - static void unload(); -}; - extern void light_param_data_storage_data_init(); extern void light_param_data_storage_data_free_file_handlers(); extern int32_t light_param_data_storage_data_get_pv_id(); extern int32_t light_param_data_storage_data_get_stage_index(); +extern void light_param_data_storage_data_load(); extern int32_t light_param_data_storage_data_load_file(); extern void light_param_data_storage_data_load_stage(int32_t stage_index); extern void light_param_data_storage_data_load_stage(uint32_t stage_hash, stage_database* stage_data); @@ -79,9 +43,11 @@ extern void light_param_data_storage_data_load_stages( extern void light_param_data_storage_data_reset(); extern void light_param_data_storage_data_set_default_light_param( light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); +extern void light_param_data_storage_data_set_ibl(); extern void light_param_data_storage_data_set_pv_id(int32_t pv_id); extern void light_param_data_storage_data_set_pv_cut(int32_t cut_id, light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); extern void light_param_data_storage_data_set_stage(int32_t stage_id, light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL); +extern void light_param_data_storage_data_unload(); extern void light_param_data_storage_data_free(); diff --git a/src/CRE/mdl/disp_manager.cpp b/src/CRE/mdl/disp_manager.cpp index 575be2bb..c3a68095 100644 --- a/src/CRE/mdl/disp_manager.cpp +++ b/src/CRE/mdl/disp_manager.cpp @@ -4,6 +4,7 @@ */ #include "disp_manager.hpp" +#include "../../KKdLib/database/stage.hpp" #include "../Glitter/glitter.hpp" #include "../render_context.hpp" #include "../shader_ft.hpp" diff --git a/src/CRE/pv_db.cpp b/src/CRE/pv_db.cpp index 1ba722dc..778b0753 100644 --- a/src/CRE/pv_db.cpp +++ b/src/CRE/pv_db.cpp @@ -6,6 +6,7 @@ #include "pv_db.hpp" #include "../KKdLib/hash.hpp" #include "../KKdLib/str_utils.hpp" +#include "data.hpp" #include "hand_item.hpp" #include "mdata_manager.hpp" #include "render_context.hpp" diff --git a/src/CRE/pv_expression.cpp b/src/CRE/pv_expression.cpp index a493d229..e9ba3c13 100644 --- a/src/CRE/pv_expression.cpp +++ b/src/CRE/pv_expression.cpp @@ -9,6 +9,7 @@ #include "../KKdLib/hash.hpp" #include "../KKdLib/str_utils.hpp" #include "rob/rob.hpp" +#include "data.hpp" #include "render_context.hpp" struct pv_expression_file { diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index 00ae230c..e50223b4 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -17,9 +17,6 @@ extern render_context* rctx_ptr; //extern void dw_gui_ctrl_disp(); -static void render_context_light_param_data_ibl_set_diffuse(light_param_ibl_diffuse* diffuse, int32_t level); -static void render_context_light_param_data_ibl_set_specular(light_param_ibl_specular* specular); - static const GLuint POSITION_INDEX = 0; static const GLuint BONE_WEIGHT_INDEX = 1; static const GLuint NORMAL_INDEX = 2; @@ -680,198 +677,6 @@ void render_context::init() { screen_buffer.Init(sprite_width, sprite_height, 0, GL_RGBA8, 0); } -void render_context::light_param_data_light_set(light_param_light * light) { - for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) { - light_param_light_group* group = &light->group[i]; - ::light_set* set = &light_set[i]; - - for (int32_t j = LIGHT_CHARA; j < LIGHT_MAX; j++) { - light_param_light_data* data = &group->data[j]; - light_data* light = &set->lights[j]; - - if (data->has_type) - light->set_type(data->type); - - if (data->has_ambient) - light->set_ambient(data->ambient); - - if (data->has_diffuse) - light->set_diffuse(data->diffuse); - - if (data->has_specular) - light->set_specular(data->specular); - - if (data->has_position) - light->set_position(data->position); - - if (data->has_spot_direction) - light->set_spot_direction(data->spot_direction); - - if (data->has_spot_exponent) - light->set_spot_exponent(data->spot_exponent); - - if (data->has_spot_cutoff) - light->set_spot_cutoff(data->spot_cutoff); - - if (data->has_attenuation) - light->set_attenuation(data->attenuation); - - light->set_clip_plane(data->clip_plane); - - if (data->has_tone_curve) - light->set_tone_curve(data->tone_curve); - } - } -} - -void render_context::light_param_data_fog_set(light_param_fog* f) { - for (int32_t i = FOG_DEPTH; i < FOG_MAX; i++) { - light_param_fog_group* group = &f->group[i]; - ::fog* fog = &this->fog[i]; - - if (group->has_type) - fog->set_type(group->type); - - if (group->has_density) - fog->set_density(group->density); - - if (group->has_linear) { - fog->set_start(group->linear_start); - fog->set_end(group->linear_end); - } - - if (group->has_color) - fog->set_color(group->color); - } -} - -void render_context::light_param_data_glow_set(light_param_glow* glow) { - render.set_auto_exposure(true); - render.set_tone_map(TONE_MAP_YCC_EXPONENT); - render.reset_saturate_coeff(0, false); - render.reset_scene_fade(0); - render.reset_tone_trans(0); - - if (glow->has_exposure) - render.set_exposure(glow->exposure); - - if (glow->has_gamma) - render.set_gamma(glow->gamma); - - if (glow->has_saturate_power) - render.set_saturate_power(glow->saturate_power); - - if (glow->has_saturate_coef) - render.set_saturate_coeff(glow->saturate_coef, 0, false); - - if (glow->has_flare) - render.set_lens(glow->flare); - - if (glow->has_sigma) - render.set_radius(glow->sigma); - - if (glow->has_intensity) - render.set_intensity(glow->intensity); - - if (glow->has_auto_exposure) - render.set_auto_exposure(glow->auto_exposure); - - if (glow->has_tone_map_method) - render.set_tone_map(glow->tone_map_method); - - if (glow->has_fade_color) { - vec4 fade_color = glow->fade_color; - render.set_scene_fade(fade_color, 0); - render.set_scene_fade_blend_func(glow->fade_color_blend_func, 0); - } - - if (glow->has_tone_transform) - render.set_tone_trans(glow->tone_transform_start, glow->tone_transform_end, 0); -} - -void render_context::light_param_data_ibl_set( - light_param_ibl* ibl, light_param_data_storage* storage) { - if (!ibl->ready) - return; - - for (int32_t i = 0, j = -1; i < 5; i++, j++) { - gl_state_bind_texture_cube_map(storage->textures[i]); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - if (!i) { - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 1); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - render_context_light_param_data_ibl_set_diffuse(&ibl->diffuse[0], 0); - render_context_light_param_data_ibl_set_diffuse(&ibl->diffuse[1], 1); - } - else { - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, ibl->specular[j].max_level); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_LOD_BIAS, 0.0f); - render_context_light_param_data_ibl_set_specular(&ibl->specular[j]); - } - } - gl_state_bind_texture_cube_map(0); - - ::light_set* set = &light_set[LIGHT_SET_MAIN]; - set->set_irradiance(ibl->diff_coef[1][0], ibl->diff_coef[1][1], ibl->diff_coef[1][2]); - - float_t len; - vec3 pos; - - light_data* l = &set->lights[LIGHT_CHARA]; - l->get_position(pos); - len = vec3::length(pos); - if (fabsf(len - 1.0f) < 0.02f) - l->set_position(ibl->lit_dir[0]); - - l->set_ibl_color0(ibl->lit_col[0]); - l->set_ibl_color1(ibl->lit_col[2]); - l->set_ibl_direction(ibl->lit_dir[0]); - - l = &set->lights[LIGHT_STAGE]; - l->get_position(pos); - len = vec3::length(pos); - if (fabsf(len - 1.0f) < 0.02f) - l->set_position(ibl->lit_dir[1]); - - l->set_ibl_color0(ibl->lit_col[1]); - l->set_ibl_direction(ibl->lit_dir[1]); -} - -void render_context::light_param_data_wind_set(light_param_wind* w) { - wind* wind = task_wind->ptr; - if (w->has_scale) - wind->scale = w->scale; - - if (w->has_cycle) - wind->cycle = w->cycle; - - if (w->has_rot) { - wind->rot_y = w->rot_y; - wind->rot_z = w->rot_z; - } - - if (w->has_bias) - wind->bias = w->bias; - - for (int32_t i = 0; i < 16; i++) - if (w->has_spc[i]) { - wind->spc[i].cos = w->spc[i].cos; - wind->spc[i].sin = w->spc[i].sin; - } -} - -void render_context::light_param_data_face_set(light_param_face* face) { - this->face.set_offset(face->offset); - this->face.set_scale(face->scale); - this->face.set_position(face->position); - this->face.set_direction(face->direction); -} - void render_context::resize(int32_t render_width, int32_t render_height, int32_t sprite_width, int32_t sprite_height, int32_t screen_width, int32_t screen_height) { @@ -907,43 +712,3 @@ void render_context::resize(int32_t render_width, int32_t render_height, init(); } } - -static void render_context_light_param_data_ibl_set_diffuse(light_param_ibl_diffuse* diffuse, int32_t level) { - int32_t size = diffuse->size; - size_t data_size = size; - data_size = 4 * data_size * data_size; - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 0]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 1]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 2]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 3]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 4]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &diffuse->data[data_size * 5]); -} - -static void render_context_light_param_data_ibl_set_specular(light_param_ibl_specular* specular) { - int32_t size = specular->size; - int32_t max_level = specular->max_level; - for (int32_t i = 0; i <= max_level; i++, size /= 2) { - std::vector& data = specular->data[i]; - size_t data_size = size; - data_size = 4 * data_size * data_size; - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, i, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 0]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, i, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 1]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, i, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 2]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, i, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 3]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, i, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 4]); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, i, GL_RGBA16F, - size, size, 0, GL_RGBA, GL_HALF_FLOAT, &data[data_size * 5]); - } -} diff --git a/src/CRE/render_context.hpp b/src/CRE/render_context.hpp index c00d210a..fa2ebea5 100644 --- a/src/CRE/render_context.hpp +++ b/src/CRE/render_context.hpp @@ -17,7 +17,6 @@ #include "light_param/wind.hpp" #include "mdl/disp_manager.hpp" #include "camera.hpp" -#include "light_param.hpp" #include "render.hpp" #include "render_manager.hpp" #include "render_texture.hpp" @@ -367,12 +366,6 @@ struct render_context { void disp(); void free(); void init(); - void light_param_data_light_set(light_param_light* light); - void light_param_data_fog_set(light_param_fog* f); - void light_param_data_glow_set(light_param_glow* glow); - void light_param_data_ibl_set(light_param_ibl* ibl, light_param_data_storage* storage); - void light_param_data_wind_set(light_param_wind* w); - void light_param_data_face_set(light_param_face* face); void resize(int32_t render_width, int32_t render_height, int32_t sprite_width, int32_t sprite_height, int32_t screen_width, int32_t screen_height); diff --git a/src/CRE/render_manager.cpp b/src/CRE/render_manager.cpp index d046542a..43e459ae 100644 --- a/src/CRE/render_manager.cpp +++ b/src/CRE/render_manager.cpp @@ -12,6 +12,7 @@ #include "clear_color.hpp" #include "effect.hpp" #include "gl_state.hpp" +#include "light_param.hpp" #include "render.hpp" #include "render_context.hpp" #include "render_texture.hpp" @@ -45,7 +46,6 @@ static void blur_filter_apply(render_context* rctx, RenderTexture* dst, RenderTe static void render_manager_free_render_textures(); static void render_manager_init_render_textures(int32_t multisample); -extern light_param_data_storage* light_param_data_storage_data; extern render_context* rctx_ptr; namespace rndr { @@ -262,18 +262,14 @@ namespace rndr { } void RenderManager::render_all() { - static const int32_t ibl_texture_index[] = { - 9, 10, 11, 12, 13 - }; + light_param_data_storage_data_set_ibl(); - render_context* rctx = rctx_ptr; - camera* cam = rctx->camera; + static const vec4 color_clear = 0.0f; - for (int32_t i = 0; i < 5; i++) - gl_state_active_bind_texture_cube_map(ibl_texture_index[i], - light_param_data_storage_data->textures[i]); + gl_state_bind_framebuffer(0); + glClearBufferfv(GL_COLOR, 0, (float_t*)&color_clear); - rctx->obj_scene.g_framebuffer_size = { + rctx_ptr->obj_scene.g_framebuffer_size = { 1.0f / (float_t)render->render_width[0], 1.0f / (float_t)render->render_height[0], (float_t)render->render_width[0], @@ -300,7 +296,7 @@ namespace rndr { RenderManager::render_single_pass((RenderPassID)i); gl_state_end_event(); - rctx->disp_manager->check_vertex_arrays(); + rctx_ptr->disp_manager->check_vertex_arrays(); gl_state_bind_vertex_array(0); gl_state_disable_primitive_restart(); gl_state_bind_uniform_buffer_base(0, 0); diff --git a/src/CRE/rob/motion.cpp b/src/CRE/rob/motion.cpp index c52d81b9..e5873607 100644 --- a/src/CRE/rob/motion.cpp +++ b/src/CRE/rob/motion.cpp @@ -4,6 +4,7 @@ */ #include "motion.hpp" +#include "../data.hpp" struct MotFile { const motion_set_info* mot_set_info; diff --git a/src/CRE/rob/skin_param.cpp b/src/CRE/rob/skin_param.cpp index 674b8ebb..d51024f6 100644 --- a/src/CRE/rob/skin_param.cpp +++ b/src/CRE/rob/skin_param.cpp @@ -6,6 +6,7 @@ #include "rob.hpp" #include "../../KKdLib/prj/algorithm.hpp" #include "../../KKdLib/str_utils.hpp" +#include "../data.hpp" #include "../mdata_manager.hpp" #include "skin_param.hpp" diff --git a/src/ReDIVA/classes/data_view/object.cpp b/src/ReDIVA/classes/data_view/object.cpp index 4bc2b285..8af4222b 100644 --- a/src/ReDIVA/classes/data_view/object.cpp +++ b/src/ReDIVA/classes/data_view/object.cpp @@ -4,8 +4,10 @@ */ #include "object.hpp" +#include "../../../CRE/object.hpp" #include "../../../CRE/render_context.hpp" #include "../../imgui_helper.hpp" +#include extern int32_t width; extern int32_t height; diff --git a/src/ReDIVA/classes/data_view/texture.cpp b/src/ReDIVA/classes/data_view/texture.cpp index cf0653c0..b83d30ce 100644 --- a/src/ReDIVA/classes/data_view/texture.cpp +++ b/src/ReDIVA/classes/data_view/texture.cpp @@ -6,6 +6,7 @@ #include "texture.hpp" #include "../../../CRE/render_context.hpp" #include "../../imgui_helper.hpp" +#include extern int32_t width; extern int32_t height; diff --git a/src/ReDIVA/classes/graphics/post_process.cpp b/src/ReDIVA/classes/graphics/post_process.cpp index 2b36a351..c27efde5 100644 --- a/src/ReDIVA/classes/graphics/post_process.cpp +++ b/src/ReDIVA/classes/graphics/post_process.cpp @@ -4,6 +4,7 @@ */ #include "post_process.hpp" +#include "../../../CRE/light_param.hpp" #include "../../../CRE/render_context.hpp" #include "../../../CRE/stage.hpp" #include "../../imgui_helper.hpp" diff --git a/src/ReDIVA/data_test/equip_test.cpp b/src/ReDIVA/data_test/equip_test.cpp index 725dfa47..850171c2 100644 --- a/src/ReDIVA/data_test/equip_test.cpp +++ b/src/ReDIVA/data_test/equip_test.cpp @@ -5,6 +5,7 @@ #include "equip_test.hpp" #include "../../CRE/rob/rob.hpp" +#include "../../CRE/data.hpp" #include "../dw.hpp" #include "auth_3d_test.hpp" #include "motion_test.hpp" diff --git a/src/ReDIVA/data_test/motion_test.cpp b/src/ReDIVA/data_test/motion_test.cpp index 735e1a7d..cde7acfb 100644 --- a/src/ReDIVA/data_test/motion_test.cpp +++ b/src/ReDIVA/data_test/motion_test.cpp @@ -8,6 +8,7 @@ #include "../../CRE/rob/motion.hpp" #include "../../CRE/rob/skin_param.hpp" #include "../../CRE/clear_color.hpp" +#include "../../CRE/data.hpp" #include "../../CRE/hand_item.hpp" #include "../../CRE/module_table.hpp" #include "../../CRE/pv_db.hpp" diff --git a/src/ReDIVA/dw.cpp b/src/ReDIVA/dw.cpp index cca97f9b..a495930d 100644 --- a/src/ReDIVA/dw.cpp +++ b/src/ReDIVA/dw.cpp @@ -4,6 +4,7 @@ */ #include "dw.hpp" +#include "../CRE/data.hpp" #include "input_state.hpp" #include "print_work.hpp" diff --git a/src/ReDIVA/glitter_editor.hpp b/src/ReDIVA/glitter_editor.hpp index d0fe0fcb..318244e2 100644 --- a/src/ReDIVA/glitter_editor.hpp +++ b/src/ReDIVA/glitter_editor.hpp @@ -8,6 +8,7 @@ #if defined(ReDIVA_DEV) #include "../KKdLib/default.hpp" #include "../CRE/Glitter/glitter.hpp" +#include "../CRE/data.hpp" #include "task_window.hpp" enum glitter_editor_selected_enum { diff --git a/src/ReDIVA/print_work.cpp b/src/ReDIVA/print_work.cpp index e6935eb6..bf47fbb4 100644 --- a/src/ReDIVA/print_work.cpp +++ b/src/ReDIVA/print_work.cpp @@ -5,6 +5,7 @@ #include "print_work.hpp" #include "../KKdLib/str_utils.hpp" +#include "../CRE/data.hpp" #include "../CRE/shader_ft.hpp" namespace app { diff --git a/src/ReDIVA/pv_game/game_2d.cpp b/src/ReDIVA/pv_game/game_2d.cpp index 8c5292e2..179a5475 100644 --- a/src/ReDIVA/pv_game/game_2d.cpp +++ b/src/ReDIVA/pv_game/game_2d.cpp @@ -4,6 +4,7 @@ */ #include "game_2d.hpp" +#include "../../CRE/data.hpp" #include "pv_game.hpp" const char* spr_life_bonus[] = { diff --git a/src/ReDIVA/pv_game/pv_game_play_data.cpp b/src/ReDIVA/pv_game/pv_game_play_data.cpp index 16e5b695..d94cee56 100644 --- a/src/ReDIVA/pv_game/pv_game_play_data.cpp +++ b/src/ReDIVA/pv_game/pv_game_play_data.cpp @@ -4,6 +4,7 @@ */ #include "pv_game_play_data.hpp" +#include "../../CRE/data.hpp" #include "../print_work.hpp" #include "game_2d.hpp" #include "player_data.hpp" diff --git a/src/ReDIVA/render.cpp b/src/ReDIVA/render.cpp index b1c2554b..f4f8d651 100644 --- a/src/ReDIVA/render.cpp +++ b/src/ReDIVA/render.cpp @@ -925,7 +925,8 @@ static render_context* render_context_load() { for (int32_t i = 0; i < ROB_CHARA_COUNT; i++) rob_chara_array_reset_pv_data(i); - light_param_data_storage::load(aft_data); + light_param_data_storage_data_load(); + auth_3d_data_load_auth_3d_db(aft_auth_3d_db); cmn_set_id = aft_mot_db->get_motion_set_id("CMN"); @@ -1157,12 +1158,6 @@ static void render_context_disp(render_context* rctx) { glViewport(0, 0, internal_3d_res.x, internal_3d_res.y); - rctx->render.rend_texture[0].Bind(); - gl_state_set_depth_mask(GL_TRUE); - glClearBufferfv(GL_COLOR, 0, (float_t*)&color_clear); - glClearBufferfv(GL_DEPTH, 0, &depth_clear); - gl_state_set_depth_mask(GL_FALSE); - cam->update(); rctx->disp(); @@ -1258,7 +1253,7 @@ static void render_context_dispose(render_context* rctx) { render_timer->end_of_cycle(); } - light_param_data_storage::unload(); + light_param_data_storage_data_unload(); x_pv_game_data_free(); task_data_test_glitter_particle_free();