* 球谐环境光加载修正

This commit is contained in:
2026-05-27 15:06:50 +08:00
parent b9e5a107f0
commit 9012dccf12
12 changed files with 40 additions and 13 deletions
+4 -2
View File
@@ -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;
+2 -1
View File
@@ -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
{
+1 -1
View File
@@ -42,7 +42,7 @@ void Release()
int Main()
{
g_log->SetLogFile("log/");
Engine::GetParamRef()._test = true;
//Engine::GetParamRef()._test = true;
Engine::Init();
Position p0;
Binary file not shown.
+9
View File
@@ -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
Binary file not shown.
+11 -3
View File
@@ -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()
Binary file not shown.
Binary file not shown.
+12 -6
View File
@@ -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);
+1
View File
@@ -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
Binary file not shown.