HDR, Bloom and SSR

This commit is contained in:
Halbear 2026-09-04 00:23:48 +01:00
parent 577836a03f
commit 04befce27d
44 changed files with 1377 additions and 269 deletions

View file

@ -9,6 +9,7 @@ const float REDUCE_MUL = 1.0/32.0;
layout(location = 0) in vec2 inTextCoord;
layout(location = 0) out vec4 outFragColor;
layout(location = 1) out vec4 outBloomColour;
layout(set = 0, binding = 0) uniform sampler2DMS inputTexture;
@ -19,7 +20,12 @@ layout(set = 1, binding = 0) uniform ScreenSize{
vec4 gamma(vec4 color){
return color = vec4(pow(color.rgb,vec3(GAMMA_CONST)),color.a);
}
vec3 HDR(float Gamma, float Exposure, sampler2D Texture, vec2 TexCoords){
vec3 hdrColor = texture(Texture, TexCoords).rgb;
vec3 mapped = vec3(1.0) - exp(-hdrColor * Exposure);
mapped = pow(mapped, vec3(1.0 / Gamma));
return mapped;
}
vec4 msaa(int sampleCount, sampler2DMS textureIn,vec2 TextCoord){
ivec2 pixelCoords = ivec2(TextCoord * textureSize(textureIn));
vec4 colorSum = vec4(0.0);
@ -34,6 +40,8 @@ vec4 msaa(int sampleCount, sampler2DMS textureIn,vec2 TextCoord){
void main(){
ivec2 pixelCoords = ivec2(inTextCoord * textureSize(inputTexture));
outFragColor = texelFetch(inputTexture, pixelCoords, 0);
if(USE_AA == 0){
outFragColor = texelFetch(inputTexture,pixelCoords,0);
}
@ -49,5 +57,16 @@ void main(){
if(USE_AA == 4){
outFragColor = msaa(8,inputTexture,inTextCoord);
}
outFragColor = gamma(outFragColor);
vec3 color = outFragColor.rgb;
float brightness = dot(color, vec3(0.2126, 0.7152, 0.0722));
float threshold = 1.0;
float softKnee = 0.5;
float contribution = max(brightness - threshold, 0.0);
contribution = contribution / max(contribution + softKnee, 0.0001);
outBloomColour = vec4(color * contribution, 1.0);
}