From 9cd2960cfe2740eed6b61dd523195bc12afad3fa Mon Sep 17 00:00:00 2001 From: korenkonder Date: Mon, 6 Jan 2025 22:53:17 +0300 Subject: [PATCH] =?UTF-8?q?Synced=20changes=20for=20X=20Pack=20specific=20?= =?UTF-8?q?stuff=20between=20repos=20=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CRE/mdl/disp_manager.cpp | 110 ++++++++++++++++++----------------- src/CRE/render.cpp | 2 +- src/CRE/renderer/dof.cpp | 23 ++++---- src/CRE/renderer/dof.hpp | 9 +-- 4 files changed, 76 insertions(+), 68 deletions(-) diff --git a/src/CRE/mdl/disp_manager.cpp b/src/CRE/mdl/disp_manager.cpp index 37ec866c..18b7d1fd 100644 --- a/src/CRE/mdl/disp_manager.cpp +++ b/src/CRE/mdl/disp_manager.cpp @@ -2309,7 +2309,50 @@ namespace mdl { obj[type].push_back(data); } - static int32_t obj_axis_aligned_bounding_box_check_visibility( + static int32_t obj_bounding_sphere_check_visibility_default(const vec3& center, camera* cam, float_t radius) { + vec3 _center; + mat4_transform_point(&cam->view, ¢er, &_center); + + double_t min_depth = (double_t)_center.z - (double_t)radius; + double_t max_depth = (double_t)_center.z + (double_t)radius; + if (-cam->min_distance < min_depth || -cam->max_distance > max_depth) + return 0; + + float_t v5 = vec3::dot(cam->field_1E4, _center); + if (v5 < -radius) + return 0; + + float_t v6 = vec3::dot(cam->field_1F0, _center); + if (v6 < -radius) + return 0; + + float_t v7 = vec3::dot(cam->field_1FC, _center); + if (v7 < -radius) + return 0; + + float_t v8 = vec3::dot(cam->field_208, _center); + if (v8 < -radius) + return 0; + + if (-cam->min_distance >= max_depth && -cam->max_distance <= min_depth + && v5 >= radius && v6 >= radius && v7 >= radius && v8 >= radius) + return 1; + return 2; + } + + static int32_t obj_bounding_sphere_check_visibility(const obj_bounding_sphere& sphere, + CullingCheck* culling, camera* cam, const mat4& mat) { + if (culling->func) + return culling->func(&sphere, &cam->view); + + vec3 center; + mat4 _mat; + mat4_transpose(&mat, &_mat); + mat4_transform_point(&_mat, &sphere.center, ¢er); + return obj_bounding_sphere_check_visibility_default(center, cam, mat4_get_max_scale(&_mat) * sphere.radius); + } + + static int32_t obj_axis_aligned_bounding_box_check_visibility_default( const obj_axis_aligned_bounding_box* aabb, camera* cam, const mat4& mat) { vec3 points[8]; points[0] = aabb->center + (aabb->size ^ vec3( 0.0f, 0.0f, 0.0f)); @@ -2352,41 +2395,12 @@ namespace mdl { return 1; } - static int32_t obj_bounding_sphere_check_visibility(const obj_bounding_sphere* sphere, + static int32_t obj_axis_aligned_bounding_box_check_visibility( + const obj_axis_aligned_bounding_box* aabb, CullingCheck* culling, camera* cam, const mat4& mat) { if (culling->func) - return culling->func(sphere, &cam->view); - - vec3 center; - mat4_transform_point(&mat, &sphere->center, ¢er); - mat4_transform_point(&cam->view, ¢er, ¢er); - float_t radius = mat4_get_max_scale(&mat) * sphere->radius; - - double_t min_depth = (double_t)center.z - (double_t)radius; - double_t max_depth = (double_t)center.z + (double_t)radius; - if (-cam->min_distance < min_depth || -cam->max_distance > max_depth) - return 0; - - float_t v5 = vec3::dot(cam->field_1E4, center); - if (v5 < -radius) - return 0; - - float_t v6 = vec3::dot(cam->field_1F0, center); - if (v6 < -radius) - return 0; - - float_t v7 = vec3::dot(cam->field_1FC, center); - if (v7 < -radius) - return 0; - - float_t v8 = vec3::dot(cam->field_208, center); - if (v8 < -radius) - return 0; - - if (-cam->min_distance >= max_depth && -cam->max_distance <= min_depth - && v5 >= radius && v6 >= radius && v7 >= radius && v8 >= radius) return 1; - return 2; + return obj_axis_aligned_bounding_box_check_visibility_default(aabb, cam, mat); } bool DispManager::entry_obj(const ::obj* obj, const mat4& mat, obj_mesh_vertex_buffer* obj_vert_buf, @@ -2404,7 +2418,7 @@ namespace mdl { if (!local && object_culling && !instances_count && !bone_mat && (!obj || !obj_bounding_sphere_check_visibility( - &obj->bounding_sphere, &culling, cam, mat))) { + obj->bounding_sphere, &culling, cam, mat))) { culling.culled.objects++; return false; } @@ -2423,9 +2437,9 @@ namespace mdl { if (!local && object_culling && !instances_count && !bone_mat && !obj_bounding_sphere_check_visibility( - &mesh->bounding_sphere, &culling, cam, mat) + mesh->bounding_sphere, &culling, cam, mat) && (!mesh_morph || !obj_bounding_sphere_check_visibility( - &mesh_morph->bounding_sphere, &culling, cam, mat))) { + mesh_morph->bounding_sphere, &culling, cam, mat))) { culling.culled.meshes++; continue; } @@ -2442,15 +2456,11 @@ namespace mdl { if (!local && object_culling && !instances_count && !bone_mat) { int32_t v32 = obj_bounding_sphere_check_visibility( - &sub_mesh->bounding_sphere, &culling, cam, mat); + sub_mesh->bounding_sphere, &culling, cam, mat); if (v32 != 2 || (!mesh->attrib.m.billboard && !mesh->attrib.m.billboard_y_axis)) { - if (v32 == 2) { - if (culling.func) - v32 = 1; - else - v32 = obj_axis_aligned_bounding_box_check_visibility( - &sub_mesh->axis_aligned_bounding_box, cam, mat); - } + if (v32 == 2) + v32 = obj_axis_aligned_bounding_box_check_visibility( + &sub_mesh->axis_aligned_bounding_box, &culling, cam, mat); if (!v32) { if (!mesh_morph || j >= mesh_morph->num_submesh) { @@ -2465,14 +2475,10 @@ namespace mdl { } int32_t v32 = obj_bounding_sphere_check_visibility( - &sub_mesh_morph->bounding_sphere, &culling, cam, mat); - if (v32 == 2) { - if (culling.func) - v32 = 1; - else - v32 = obj_axis_aligned_bounding_box_check_visibility( - &sub_mesh_morph->axis_aligned_bounding_box, cam, mat); - } + sub_mesh_morph->bounding_sphere, &culling, cam, mat); + if (v32 == 2) + v32 = obj_axis_aligned_bounding_box_check_visibility( + &sub_mesh_morph->axis_aligned_bounding_box, &culling, cam, mat); if (!v32) { culling.culled.sub_meshes++; diff --git a/src/CRE/render.cpp b/src/CRE/render.cpp index 586b04ac..04da882f 100644 --- a/src/CRE/render.cpp +++ b/src/CRE/render.cpp @@ -137,7 +137,7 @@ namespace rndr { for (int32_t i = 0; i < 8; i++) gl_state_bind_sampler(i, 0); - dof->apply(&rend_texture[0]); + dof->apply(&rend_texture[0], &rctx_ptr->render_buffer); draw_lens_ghost(); diff --git a/src/CRE/renderer/dof.cpp b/src/CRE/renderer/dof.cpp index 1c3183d3..41d2ffec 100644 --- a/src/CRE/renderer/dof.cpp +++ b/src/CRE/renderer/dof.cpp @@ -60,7 +60,7 @@ namespace renderer { } - void DOF3::apply(RenderTexture* rt) { + void DOF3::apply(RenderTexture* rt, RenderTexture* buf_rt) { camera* cam = rctx_ptr->camera; bool use_dof_f2 = false; if (dof_debug_data.flags & DOF_DEBUG_USE_UI_PARAMS) { @@ -89,13 +89,13 @@ namespace renderer { } focus = max_def(focus, (float_t)cam->min_distance); - apply_physical(rt, rt->GetColorTex(), rt->GetDepthTex(), + apply_physical(rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(), cam->min_distance, cam->max_distance, focus, dof_debug_data.focal_length, cam->fov * DEG_TO_RAD_FLOAT, dof_debug_data.f_number); } else { float_t fuzzing_range = max_def(dof_debug_data.f2.fuzzing_range, 0.01f); - apply_f2(rt, rt->GetColorTex(), rt->GetDepthTex(), + apply_f2(rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(), cam->min_distance, cam->max_distance, cam->fov * DEG_TO_RAD_FLOAT, dof_debug_data.f2.focus, dof_debug_data.f2.focus_range, fuzzing_range, dof_debug_data.f2.ratio); @@ -105,7 +105,7 @@ namespace renderer { } else if (dof_pv_data.enable && dof_pv_data.f2.ratio > 0.0f) { float_t fuzzing_range = max_def(dof_pv_data.f2.fuzzing_range, 0.01f); - apply_f2(rt, rt->GetColorTex(), rt->GetDepthTex(), + apply_f2(rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(), cam->min_distance, cam->max_distance, cam->fov * DEG_TO_RAD_FLOAT, dof_pv_data.f2.focus, dof_pv_data.f2.focus_range, fuzzing_range, dof_pv_data.f2.ratio); @@ -173,7 +173,7 @@ namespace renderer { glGenVertexArrays(1, &vao); } - void DOF3::apply_f2(RenderTexture* rt, GLuint color_texture, + void DOF3::apply_f2(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture, GLuint depth_texture, float_t min_distance, float_t max_distance, float_t fov, float_t focus, float_t focus_range, float_t fuzzing_range, float_t ratio) { gl_state_begin_event("renderer::DOF3::apply_f2"); @@ -189,7 +189,7 @@ namespace renderer { render_tiles(depth_texture, true); downsample(color_texture, depth_texture, true); apply_main_filter(true); - upsample(rt, color_texture, depth_texture, true); + upsample(rt, buf_rt, color_texture, depth_texture, true); shader::unbind(); for (int32_t i = 0; i < 8; i++) { @@ -200,7 +200,7 @@ namespace renderer { gl_state_end_event(); } - void DOF3::apply_physical(RenderTexture* rt, GLuint color_texture, + void DOF3::apply_physical(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture, GLuint depth_texture, float_t min_distance, float_t max_distance, float_t focus, float_t focal_length, float_t fov, float_t f_number) { gl_state_begin_event("renderer::DOF3::apply_physical"); @@ -216,7 +216,7 @@ namespace renderer { render_tiles(depth_texture, false); downsample(color_texture, depth_texture, false); apply_main_filter(false); - upsample(rt, color_texture, depth_texture, false); + upsample(rt, buf_rt, color_texture, depth_texture, false); shader::unbind(); for (int32_t i = 0; i < 8; i++) { @@ -283,9 +283,10 @@ namespace renderer { gl_state_end_event(); } - void DOF3::upsample(RenderTexture* rt, GLuint color_texture, GLuint depth_texture, bool f2) { + void DOF3::upsample(RenderTexture* rt, RenderTexture* buf_rt, + GLuint color_texture, GLuint depth_texture, bool f2) { gl_state_begin_event("renderer::DOF3::upsample"); - rctx_ptr->render_buffer.Bind(); + buf_rt->Bind(); gl_state_set_viewport(0, 0, width, height); uniform_value[U_DOF_STAGE] = 4; shaders_ft.set(SHADER_FT_DOF); @@ -303,7 +304,7 @@ namespace renderer { shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4); glCopyImageSubData( - rctx_ptr->render_buffer.GetColorTex(), GL_TEXTURE_2D, 0, 0, 0, 0, + buf_rt->GetColorTex(), GL_TEXTURE_2D, 0, 0, 0, 0, rt->GetColorTex(), GL_TEXTURE_2D, 0, 0, 0, 0, width, height, 1); gl_state_end_event(); } diff --git a/src/CRE/renderer/dof.hpp b/src/CRE/renderer/dof.hpp index 15641931..eea81ad1 100644 --- a/src/CRE/renderer/dof.hpp +++ b/src/CRE/renderer/dof.hpp @@ -54,24 +54,25 @@ namespace renderer { DOF3(int32_t width, int32_t height); ~DOF3(); - void apply(RenderTexture* rt); + void apply(RenderTexture* rt, RenderTexture* buf_rt); void resize(int32_t width, int32_t height); private: void free(); void init(int32_t width, int32_t height); - void apply_f2(RenderTexture* rt, GLuint color_texture, + void apply_f2(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture, GLuint depth_texture, float_t min_distance, float_t max_distance, float_t fov, float_t focus, float_t focus_range, float_t fuzzing_range, float_t ratio); - void apply_physical(RenderTexture* rt, GLuint color_texture, + void apply_physical(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture, GLuint depth_texture, float_t min_distance, float_t max_distance, float_t focus, float_t focal_length, float_t fov, float_t f_number); void render_tiles(GLuint depth_texture, bool f2); void downsample(GLuint color_texture, GLuint depth_texture, bool f2); void apply_main_filter(bool f2); - void upsample(RenderTexture* rt, GLuint color_texture, GLuint depth_texture, bool f2); + void upsample(RenderTexture* rt, RenderTexture* buf_rt, + GLuint color_texture, GLuint depth_texture, bool f2); void init_textures(int32_t width, int32_t height); void update_data(float_t min_dist, float_t max_dist, float_t fov, float_t dist, float_t focal_length,