now using deferred rendering instead of forward rendering; some little problem: grid not render, shadow not impl

This commit is contained in:
2026-03-18 14:28:02 +08:00
parent f1de5df4de
commit 57700da217
15 changed files with 731 additions and 420 deletions

View File

@ -17,13 +17,11 @@ void main()
#version 430
layout(location = 0) out vec4 o_Color;
layout(location = 1) out vec4 o_BloomTexture;
in vec2 v_TexCoord;
uniform sampler2DMS u_Texture;
uniform sampler2D u_BloomTexture;
uniform sampler2D u_HDRTexture; // 来自 LightingPass 的 HDR 颜色
uniform sampler2D u_BloomTexture; // 来自 BloomBlendPass 的 Bloom 纹理
uniform bool u_EnableAutoExposure;
uniform float u_ManualExposure;
@ -32,73 +30,36 @@ layout(std430, binding = 2) buffer Exposure
float u_Exposure;
};
uniform int u_TextureSamples;
uniform bool u_EnableBloom;
uniform float u_BloomThreshold;
const float uFar = 1.0;
vec4 SampleTexture(sampler2D tex, vec2 texCoord)
{
return texture(tex, texCoord);
}
vec4 MultiSampleTexture(sampler2DMS tex, vec2 tc)
{
ivec2 texSize = textureSize(tex);
ivec2 texCoord = ivec2(tc * texSize);
vec4 result = vec4(0.0);
for (int i = 0; i < u_TextureSamples; i++)
result += texelFetch(tex, texCoord, i);
result /= float(u_TextureSamples);
return result;
}
float MultiSampleDepth(sampler2DMS tex, vec2 tc)
{
ivec2 texSize = textureSize(tex);
ivec2 texCoord = ivec2(tc * texSize);
float result = 0.0;
for (int i = 0; i < u_TextureSamples; i++)
result += texelFetch(tex, texCoord, i).r;
result /= float(u_TextureSamples);
return result;
}
const float gamma = 2.2;
const float pureWhite = 1.0;
void main()
{
const float gamma = 2.2;
const float pureWhite = 1.0;
// Tonemapping
vec4 msColor = MultiSampleTexture(u_Texture, v_TexCoord);
vec3 color = msColor.rgb;
// 采样 HDR 颜色(单样本)
vec3 color = texture(u_HDRTexture, v_TexCoord).rgb;
// 混合 Bloom如果启用
if (u_EnableBloom)
{
vec3 bloomColor = texture(u_BloomTexture, v_TexCoord).rgb;
color += bloomColor;
color += bloomColor; // 在 HDR 空间混合
}
if(u_EnableAutoExposure)
color *= u_Exposure;
// 应用曝光
if (u_EnableAutoExposure)
color *= u_Exposure;
else
color *= u_ManualExposure;
color *= u_ManualExposure;
// Reinhard tonemapping operator.
// see: "Photographic Tone Reproduction for Digital Images", eq. 4
// Reinhard 色调映射
float luminance = dot(color, vec3(0.2126, 0.7152, 0.0722));
float mappedLuminance = (luminance * (1.0 + luminance / (pureWhite * pureWhite))) / (1.0 + luminance);
// Scale color by ratio of average luminances.
// 按亮度比例缩放颜色
vec3 mappedColor = (mappedLuminance / luminance) * color;
// Gamma correction.
// Gamma 校正
o_Color = vec4(pow(mappedColor, vec3(1.0 / gamma)), 1.0);
// Show over-exposed areas
// if (o_Color.r > 1.0 || o_Color.g > 1.0 || o_Color.b > 1.0)
// o_Color.rgb *= vec3(1.0, 0.25, 0.25);
}
}