Files
Prism/Editor/assets/shaders/SceneComposite.glsl

65 lines
1.4 KiB
GLSL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#type vertex
#version 430
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec2 a_TexCoord;
out vec2 v_TexCoord;
void main()
{
vec4 position = vec4(a_Position.xy, 0.0, 1.0);
v_TexCoord = a_TexCoord;
gl_Position = position;
}
#type fragment
#version 430
layout(location = 0) out vec4 o_Color;
in vec2 v_TexCoord;
uniform sampler2D u_HDRTexture; // 来自 LightingPass 的 HDR 颜色
uniform sampler2D u_BloomTexture; // 来自 BloomBlendPass 的 Bloom 纹理
uniform bool u_EnableAutoExposure;
uniform float u_ManualExposure;
layout(std430, binding = 2) buffer Exposure
{
float u_Exposure;
};
uniform bool u_EnableBloom;
const float gamma = 2.2;
const float pureWhite = 1.0;
void main()
{
// 采样 HDR 颜色(单样本)
vec3 color = texture(u_HDRTexture, v_TexCoord).rgb;
// 混合 Bloom如果启用
if (u_EnableBloom)
{
vec3 bloomColor = texture(u_BloomTexture, v_TexCoord).rgb;
color += bloomColor; // 在 HDR 空间混合
}
// 应用曝光
if (u_EnableAutoExposure)
color *= u_Exposure;
else
color *= u_ManualExposure;
// Reinhard 色调映射
float luminance = dot(color, vec3(0.2126, 0.7152, 0.0722));
float mappedLuminance = (luminance * (1.0 + luminance / (pureWhite * pureWhite))) / (1.0 + luminance);
// 按亮度比例缩放颜色
vec3 mappedColor = (mappedLuminance / luminance) * color;
// Gamma 校正
o_Color = vec4(pow(mappedColor, vec3(1.0 / gamma)), 1.0);
}