From d847884c101a2884e1e561c17a805fab87d122d7 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Sat, 25 Mar 2023 16:00:58 +0300 Subject: [PATCH] Change capture order. Fix stage specular --- src/CRE/light_param/light.cpp | 2 +- src/ReDIVA/render.cpp | 10 +- src/ReDIVA/x_pv_game.cpp | 184 +++++++++++++++++----------------- 3 files changed, 103 insertions(+), 93 deletions(-) diff --git a/src/CRE/light_param/light.cpp b/src/CRE/light_param/light.cpp index 13a0f490..954b11ad 100644 --- a/src/CRE/light_param/light.cpp +++ b/src/CRE/light_param/light.cpp @@ -340,7 +340,7 @@ void light_set::data_set(face& face, light_set_id id) { obj_scene_shader_data& obj_scene = rctx_ptr->obj_scene; lights[LIGHT_STAGE].get_diffuse(obj_scene.g_light_env_stage_diffuse); - lights[LIGHT_STAGE].get_ambient(obj_scene.g_light_env_stage_specular); + lights[LIGHT_STAGE].get_specular(obj_scene.g_light_env_stage_specular); lights[LIGHT_CHARA].get_diffuse(obj_scene.g_light_env_chara_diffuse); lights[LIGHT_CHARA].get_ambient(obj_scene.g_light_env_chara_ambient); diff --git a/src/ReDIVA/render.cpp b/src/ReDIVA/render.cpp index 8be6159a..585e492e 100644 --- a/src/ReDIVA/render.cpp +++ b/src/ReDIVA/render.cpp @@ -1089,10 +1089,16 @@ static void render_context_disp(render_context* rctx) { rctx->disp(); +#if BAKE_PNG || BAKE_VIDEO + fbo::blit(rctx->post_process.screen_texture.fbos[0], 0, + 0, 0, rctx->post_process.sprite_width, rctx->post_process.sprite_height, + 0, 0, rctx->post_process.screen_width, rctx->post_process.screen_height, GL_COLOR_BUFFER_BIT, GL_LINEAR); +#else fbo::blit(rctx->post_process.screen_texture.fbos[0], 0, 0, 0, rctx->post_process.sprite_width, rctx->post_process.sprite_height, rctx->post_process.screen_x_offset, rctx->post_process.screen_y_offset, rctx->post_process.sprite_width, rctx->post_process.sprite_height, GL_COLOR_BUFFER_BIT, GL_LINEAR); +#endif glViewport(0, 0, rctx->post_process.screen_width, rctx->post_process.screen_height); classes_process_disp(classes, classes_count); @@ -1299,11 +1305,13 @@ static void render_resize_fb(render_context* rctx, bool change_fb) { internal_res.x = (int32_t)res_width; internal_res.y = (int32_t)res_height; - internal_2d_res = vec2i::clamp(internal_res, 1, sv_max_texture_size); #if BAKE_PNG || BAKE_VIDEO + internal_2d_res.x = clamp_def(internal_res.x * 2, 1, sv_max_texture_size); + internal_2d_res.y = clamp_def(internal_res.y * 2, 1, sv_max_texture_size); internal_3d_res.x = (int32_t)roundf((float_t)(internal_res.x * 2)); internal_3d_res.y = (int32_t)roundf((float_t)(internal_res.y * 2)); #else + internal_2d_res = vec2i::clamp(internal_res, 1, sv_max_texture_size); internal_3d_res.x = (int32_t)roundf((float_t)(internal_res.x * render_scale_table[scale_index])); internal_3d_res.y = (int32_t)roundf((float_t)(internal_res.y * render_scale_table[scale_index])); #endif diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index 03ef53ba..83edf038 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -3530,7 +3530,97 @@ static void a3da_key_rev(a3da_key& k, std::vector& values_src) { } #endif +#if BAKE_PNG || BAKE_VIDEO +static int32_t frame_prev = -1; +#endif + bool x_pv_game::Ctrl() { +#if BAKE_VIDEO + if (img_write && frame_prev != frame) { + texture* tex = rctx_ptr->post_process.screen_texture.color_texture; + size_t width = tex->width; + size_t height = tex->height; + + const size_t pixel_size = 3; + + std::vector temp_pixels; + temp_pixels.resize(width * height * pixel_size); + gl_state_bind_texture_2d(tex->tex); + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, temp_pixels.data()); + gl_state_bind_texture_2d(0); + + std::vector pixels; + pixels.resize(width * height * pixel_size); + + uint8_t* src = (uint8_t*)temp_pixels.data(); + uint8_t* dst = (uint8_t*)pixels.data(); + for (size_t y = 0; y < height; y++) { + uint8_t* src1 = &src[y * width * pixel_size]; + uint8_t* dst1 = &dst[(height - y - 1) * width * pixel_size]; + memcpy(dst1, src1, width * pixel_size); + } + + temp_pixels.clear(); + temp_pixels.shrink_to_fit(); + + fwrite(pixels.data(), 1, width * height * pixel_size, pipe); + fflush(pipe); + + frame_prev = frame; + img_write = false; + } +#endif + +#if BAKE_PNG + if (img_write && frame_prev != frame) { + texture* tex = rctx_ptr->post_process.screen_texture.color_texture; + uint32_t width = tex->width; + uint32_t height = tex->height; + + std::vector temp_pixels; + temp_pixels.resize(width * height * 4 * sizeof(uint8_t)); + gl_state_bind_texture_2d(tex->tex); + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels.data()); + gl_state_bind_texture_2d(0); + + std::vector pixels; + pixels.resize(width * height * 4 * sizeof(uint8_t)); + + uint8_t* src = (uint8_t*)temp_pixels.data(); + uint8_t* dst = (uint8_t*)pixels.data(); + for (size_t y = 0; y < height; y++) { + uint8_t* src1 = &src[y * width * 4]; + uint8_t* dst1 = &dst[(height - y - 1) * width * 4]; + for (size_t x = 0; x < width; x++) { + *dst1++ = *src1++; + *dst1++ = *src1++; + *dst1++ = *src1++; + *dst1++ = *src1++; + //*dst1++ = reverse_endianness_uint16_t(*src1++); + //*dst1++ = reverse_endianness_uint16_t(*src1++); + //*dst1++ = reverse_endianness_uint16_t(*src1++); + //*dst1++ = reverse_endianness_uint16_t(*src1++); + } + } + + temp_pixels.clear(); + temp_pixels.shrink_to_fit(); + + std::vector png; + uint32_t error = lodepng::encode(png, pixels, (uint32_t)width, (uint32_t)height, LCT_RGBA, 8); + if (!error) { + char buf[0x200]; + sprintf_s(buf, sizeof(buf), "E:\\Rinku\\X\\pv%03d", pv_data[pv_index].pv_id); + CreateDirectoryA(buf, 0); + + sprintf_s(buf, sizeof(buf), "E:\\Rinku\\X\\pv%03d\\%05d.png", pv_data[pv_index].pv_id, frame); + lodepng::save_file(png, buf); + } + frame_prev = frame; + img_write = false; + } +#endif + if (state_old == 20) ctrl((float_t)((frame_float + get_delta_frame()) * (1.0 / 60.0)), get_delta_frame() * (float_t)(1.0 / 60.0)); else @@ -4162,9 +4252,9 @@ bool x_pv_game::Ctrl() { #if BAKE_VIDEO char buf[0x400]; - sprintf_s(buf, sizeof(buf), "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s %dx%d -r 60" - " -i - -c:v h264_nvenc -gpu 0 -profile:v high -qp 22 -i_qfactor 1.00 -b_qfactor 1.00" - " -bf 4 -me_range 24 -color_range 2 -colorspace bt709 -pix_fmt yuv420p" + sprintf_s(buf, sizeof(buf), "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s %dx%d -r 60 -i -" + " -c:v h264_nvenc -gpu 0 -profile:v high -b_ref_mode 1 -rc constqp -qp 21" + " -color_range pc -color_primaries bt709 -color_trc bt709 -colorspace bt709 -pix_fmt yuv420p" " H:\\C\\Videos\\ReDIVA_pv%03d.264", 3840, 2160, pv_data[pv_index].pv_id); pipe = _popen(buf, "wb"); #endif @@ -4316,10 +4406,6 @@ void x_pv_game::Disp() { } -#if BAKE_PNG || BAKE_VIDEO -static int32_t frame_prev = -1; -#endif - void x_pv_game::Basic() { if (state_old != 20) return; @@ -4415,90 +4501,6 @@ void x_pv_game::Basic() { } } #endif - -#if BAKE_VIDEO - if (img_write && frame_prev != frame) { - texture* rend_texture = rctx_ptr->post_process.rend_texture.color_texture; - size_t width = rend_texture->width; - size_t height = rend_texture->height; - - std::vector temp_pixels; - temp_pixels.resize(width * height * 3); - gl_state_bind_texture_2d(rend_texture->tex); - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, temp_pixels.data()); - gl_state_bind_texture_2d(0); - - std::vector pixels; - pixels.resize(width * height * 3); - - uint8_t* src = (uint8_t*)temp_pixels.data(); - uint8_t* dst = (uint8_t*)pixels.data(); - for (size_t y = 0; y < height; y++) { - uint8_t* src1 = &src[y * width * 3]; - uint8_t* dst1 = &dst[(height - y - 1) * width * 3]; - memcpy(dst1, src1, width * 3); - } - - temp_pixels.clear(); - temp_pixels.shrink_to_fit(); - - fwrite(pixels.data(), 1, width * height * 3, pipe); - fflush(pipe); - - frame_prev = frame; - img_write = false; - } -#endif - -#if BAKE_PNG - if (img_write && frame_prev != frame) { - texture* rend_texture = rctx_ptr->post_process.rend_texture.color_texture; - uint32_t width = rend_texture->width; - uint32_t height = rend_texture->height; - - std::vector temp_pixels; - temp_pixels.resize(width * height * 4 * sizeof(uint8_t)); - gl_state_bind_texture_2d(rend_texture->tex); - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels.data()); - gl_state_bind_texture_2d(0); - - std::vector pixels; - pixels.resize(width * height * 4 * sizeof(uint8_t)); - - uint8_t* src = (uint8_t*)temp_pixels.data(); - uint8_t* dst = (uint8_t*)pixels.data(); - for (size_t y = 0; y < height; y++) { - uint8_t* src1 = &src[y * width * 4]; - uint8_t* dst1 = &dst[(height - y - 1) * width * 4]; - for (size_t x = 0; x < width; x++) { - *dst1++ = *src1++; - *dst1++ = *src1++; - *dst1++ = *src1++; - *dst1++ = *src1++; - //*dst1++ = reverse_endianness_uint16_t(*src1++); - //*dst1++ = reverse_endianness_uint16_t(*src1++); - //*dst1++ = reverse_endianness_uint16_t(*src1++); - //*dst1++ = reverse_endianness_uint16_t(*src1++); - } - } - - temp_pixels.clear(); - temp_pixels.shrink_to_fit(); - - std::vector png; - uint32_t error = lodepng::encode(png, pixels, (uint32_t)width, (uint32_t)height, LCT_RGBA, 8); - if (!error) { - char buf[0x200]; - sprintf_s(buf, sizeof(buf), "E:\\Rinku\\X\\pv%03d", pv_data[pv_index].pv_id); - CreateDirectoryA(buf, 0); - - sprintf_s(buf, sizeof(buf), "E:\\Rinku\\X\\pv%03d\\%05d.png", pv_data[pv_index].pv_id, frame); - lodepng::save_file(png, buf); - } - frame_prev = frame; - img_write = false; - } -#endif } void x_pv_game::Window() {