diff --git a/dl/io/dl_file.cpp b/dl/io/dl_file.cpp index 7c96cf16..19c3fd9f 100644 --- a/dl/io/dl_file.cpp +++ b/dl/io/dl_file.cpp @@ -382,11 +382,13 @@ std::ofstream Set(std::string_view path_name, { std::ofstream ret; std::filesystem::path p = MakePath(path_name); - std::ofstream::openmode mode = std::ofstream::out | std::ofstream::trunc; + std::ofstream::openmode mode = std::ofstream::out; if (is_binary) mode |= std::ofstream::binary; - if(is_app) + if (is_app) mode |= std::ofstream::app; + else + mode |= std::ofstream::trunc; ret.open(p, mode); return ret; diff --git a/dl/vk/dl_vk.cpp b/dl/vk/dl_vk.cpp index 4a55e315..3e8edc19 100644 --- a/dl/vk/dl_vk.cpp +++ b/dl/vk/dl_vk.cpp @@ -5326,10 +5326,11 @@ size_t VK::LoadSkybox(std::string_view path) } for (size_t i = 0; i < vec.size(); ++i) { - std::string_view sub = String::Range(str, '(', ')'); + std::string_view sub = String::Range(vec[i], '(', ')'); Position3 pos = String::toPosition<3>(sub); sky._sh[i] = toLonger(pos, 1.0f); } + } // env { diff --git a/project/dl_test/head.cpp b/project/dl_test/head.cpp index 85e6aabf..68b6379b 100644 --- a/project/dl_test/head.cpp +++ b/project/dl_test/head.cpp @@ -42,7 +42,7 @@ void Release() int Main() { g_log->SetLogFile("log/"); - Engine::GetParamRef()._test = true; + //Engine::GetParamRef()._test = true; Engine::Init(); Position p0; diff --git a/project/dl_test/res/skybox/1k/ibl.ktx b/project/dl_test/res/skybox/1k/ibl.ktx new file mode 100644 index 00000000..90c0064e Binary files /dev/null and b/project/dl_test/res/skybox/1k/ibl.ktx differ diff --git a/project/dl_test/res/skybox/1k/sh.txt b/project/dl_test/res/skybox/1k/sh.txt new file mode 100644 index 00000000..65640e00 --- /dev/null +++ b/project/dl_test/res/skybox/1k/sh.txt @@ -0,0 +1,9 @@ +( 0.960040628910065, 0.976856768131256, 0.991280019283295); // L00, irradiance, pre-scaled base +( 0.092061169445515, 0.108219303190708, 0.142399802803993); // L1-1, irradiance, pre-scaled base +( 0.663774013519287, 0.680283844470978, 0.702139258384705); // L10, irradiance, pre-scaled base +(-1.100530743598938, -1.131452918052673, -1.174658179283142); // L11, irradiance, pre-scaled base +(-0.215782374143600, -0.222449794411659, -0.234213143587112); // L2-2, irradiance, pre-scaled base +( 0.132715985178947, 0.138284355401993, 0.148159787058830); // L2-1, irradiance, pre-scaled base +(-0.033982470631599, -0.034430146217346, -0.034987017512321); // L20, irradiance, pre-scaled base +(-0.556232213973999, -0.572198092937469, -0.594641625881195); // L21, irradiance, pre-scaled base +( 0.180936083197594, 0.188229963183403, 0.200044557452202); // L22, irradiance, pre-scaled base diff --git a/project/dl_test/res/skybox/1k/skybox.ktx b/project/dl_test/res/skybox/1k/skybox.ktx new file mode 100644 index 00000000..6ccb3ecb Binary files /dev/null and b/project/dl_test/res/skybox/1k/skybox.ktx differ diff --git a/project/dl_test/ui_actor.cpp b/project/dl_test/ui_actor.cpp index 8c7d3858..05efa85d 100644 --- a/project/dl_test/ui_actor.cpp +++ b/project/dl_test/ui_actor.cpp @@ -55,10 +55,9 @@ UIActor::UIActor() : - g_factory->LoadSkybox("skybox/4k/"); + g_factory->LoadSkybox("skybox/1k/"); g_factory->LoadSkybox("skybox/2k/"); - - g_factory->SetSkybox(1); + g_factory->LoadSkybox("skybox/4k/"); } void UIActor::Update() @@ -103,6 +102,15 @@ void UIActor::Update() _light.SetDirection({ -1.0f, 1.0f, -1.0f }); //_light.SetStrength({ 8.0f, 8.0f, 8.0f }); + + if(g_input->KeyUp(KeyCode::KEY1)) + g_factory->SetSkybox(1); + if (g_input->KeyUp(KeyCode::KEY2)) + g_factory->SetSkybox(2); + if (g_input->KeyUp(KeyCode::KEY3)) + g_factory->SetSkybox(3); + if (g_input->KeyUp(KeyCode::KEY0)) + g_factory->SetSkybox(0); } void UIActor::Render() diff --git a/res/dl/shader/3d_bone_frag.spv b/res/dl/shader/3d_bone_frag.spv index f8578714..374ce971 100644 Binary files a/res/dl/shader/3d_bone_frag.spv and b/res/dl/shader/3d_bone_frag.spv differ diff --git a/res/dl/shader/3d_frag.spv b/res/dl/shader/3d_frag.spv index f8578714..374ce971 100644 Binary files a/res/dl/shader/3d_frag.spv and b/res/dl/shader/3d_frag.spv differ diff --git a/shader/3d.frag b/shader/3d.frag index b24ecd78..b6b66610 100644 --- a/shader/3d.frag +++ b/shader/3d.frag @@ -6,6 +6,7 @@ const float M_PI = 3.141592653589793; const float c_MinRoughness = 0.04; +#define ONLY_SH false layout (constant_id = 0) const int SHADOW_MAP_CASCADE_COUNT = 4; layout (constant_id = 1) const int enablePCF = 1; @@ -181,11 +182,11 @@ vec3 diffuse(PbrInfo pbrInputs) return pbrInputs.diffuseColor / M_PI; } +#include "include/tocubemap.glsl" // 球谐函数 vec3 irradianceFromSH(vec3 i_normal) { - // z up -> y up - vec3 normal = vec3(i_normal.y, i_normal.z, i_normal.x); + vec3 normal = tocubemap(i_normal); vec3 result = pass.sh[0].xyz + pass.sh[1].xyz * normal.y + @@ -198,8 +199,6 @@ vec3 irradianceFromSH(vec3 i_normal) pass.sh[8].xyz * (normal.x*normal.x - normal.y*normal.y); return result * 0.282095; } - -#include "include/tocubemap.glsl" // 计算IBL环境光照 vec3 getIBLContribution(PbrInfo pbrInputs, vec3 n, vec3 reflection) { @@ -218,6 +217,9 @@ vec3 getIBLContribution(PbrInfo pbrInputs, vec3 n, vec3 reflection) // 环境光强度缩放 diffuse *= pass.scaleIBLAmbient; + if(ONLY_SH) + return diffuse; + specular *= pass.scaleIBLAmbient; return diffuse + specular; @@ -402,6 +404,8 @@ void main() // 最终光照 = 漫反射 + 高光,受法线与灯光夹角影响 vec3 color = NdotL * u_LightColor * (diffuseContrib + specContrib); + if(ONLY_SH) + color = diffuseContrib; //----------------------------------阴影计算 // 返回所在级联 @@ -430,7 +434,8 @@ void main() shadow = textureProj(shadowCoord, vec2(0.0), cascadeIndex); } // 只影响直射光 - color *= shadow; + if(!ONLY_SH) + color *= shadow; // 计算ibl光照 @@ -449,7 +454,8 @@ void main() { emissive *= SRGBtoLINEAR(texture(emissiveMap, material.emissiveTextureSet == 0 ? inUV0 : inUV1)).rgb; }; - color += emissive; + if(!ONLY_SH) + color += emissive; outColor = vec4(color, baseColor.a); diff --git a/tools/cmgen/gen_cube.bat b/tools/cmgen/gen_cube.bat index d1d4d543..01c8b3b6 100644 --- a/tools/cmgen/gen_cube.bat +++ b/tools/cmgen/gen_cube.bat @@ -6,4 +6,5 @@ cmgen.exe -f ktx -format=ktx -type=ktx --size=1024 --deploy=./output/0 ./hdr/0.hdr cmgen.exe -f ktx -format=ktx -type=ktx --size=512 --deploy=./output/1 ./hdr/1.hdr cmgen.exe -f ktx -format=ktx -type=ktx --size=256 --deploy=./output/2 ./hdr/2.hdr +cmgen.exe -f ktx -format=ktx -type=ktx --size=256 --deploy=./output/3 ./hdr/3.hdr pause \ No newline at end of file diff --git a/tools/cmgen/hdr/3.hdr b/tools/cmgen/hdr/3.hdr new file mode 100644 index 00000000..5a34f8d3 Binary files /dev/null and b/tools/cmgen/hdr/3.hdr differ