FIX: FXAA, bloom
This commit is contained in:
52
shaders/fxaa.frag
Normal file
52
shaders/fxaa.frag
Normal file
@@ -0,0 +1,52 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 inUV;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D uColor;
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float inverse_width;
|
||||
float inverse_height;
|
||||
float edge_threshold;
|
||||
float edge_threshold_min;
|
||||
} pc;
|
||||
|
||||
float luma(vec3 c)
|
||||
{
|
||||
return dot(c, vec3(0.299, 0.587, 0.114));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texel = vec2(pc.inverse_width, pc.inverse_height);
|
||||
|
||||
vec3 cM = texture(uColor, inUV).rgb;
|
||||
vec3 cN = texture(uColor, inUV + vec2(0.0, texel.y)).rgb;
|
||||
vec3 cS = texture(uColor, inUV + vec2(0.0, -texel.y)).rgb;
|
||||
vec3 cE = texture(uColor, inUV + vec2( texel.x, 0.0)).rgb;
|
||||
vec3 cW = texture(uColor, inUV + vec2(-texel.x, 0.0)).rgb;
|
||||
|
||||
float lM = luma(cM);
|
||||
float lN = luma(cN);
|
||||
float lS = luma(cS);
|
||||
float lE = luma(cE);
|
||||
float lW = luma(cW);
|
||||
|
||||
float lMin = min(lM, min(min(lN, lS), min(lE, lW)));
|
||||
float lMax = max(lM, max(max(lN, lS), max(lE, lW)));
|
||||
float lRange = lMax - lMin;
|
||||
|
||||
float threshold = max(pc.edge_threshold_min, pc.edge_threshold * lMax);
|
||||
if (lRange < threshold)
|
||||
{
|
||||
outColor = vec4(cM, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Simple 5-tap cross blur when we detect an edge.
|
||||
vec3 avg = (cM + cN + cS + cE + cW) * 0.2;
|
||||
outColor = vec4(avg, 1.0);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ layout(push_constant) uniform Push
|
||||
{
|
||||
float exposure;
|
||||
int mode;
|
||||
int bloomEnabled;
|
||||
float bloomThreshold;
|
||||
float bloomIntensity;
|
||||
} pc;
|
||||
|
||||
vec3 reinhard(vec3 x)
|
||||
@@ -32,6 +35,34 @@ void main()
|
||||
{
|
||||
vec3 hdr = texture(uHdr, inUV).rgb;
|
||||
|
||||
// Simple bloom in HDR space: gather bright neighbors and add a small blurred contribution.
|
||||
if (pc.bloomEnabled != 0)
|
||||
{
|
||||
vec2 texel = 1.0 / vec2(textureSize(uHdr, 0));
|
||||
vec3 bloom = vec3(0.0);
|
||||
int radius = 2;
|
||||
int count = 0;
|
||||
for (int x = -radius; x <= radius; ++x)
|
||||
{
|
||||
for (int y = -radius; y <= radius; ++y)
|
||||
{
|
||||
vec2 offset = vec2(x, y) * texel;
|
||||
vec3 c = texture(uHdr, clamp(inUV + offset, vec2(0.0), vec2(1.0))).rgb;
|
||||
float bright = max(max(c.r, c.g), c.b) - pc.bloomThreshold;
|
||||
if (bright > 0.0)
|
||||
{
|
||||
bloom += c * bright;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count > 0)
|
||||
{
|
||||
bloom /= float(count);
|
||||
}
|
||||
hdr += pc.bloomIntensity * bloom;
|
||||
}
|
||||
|
||||
// Simple exposure
|
||||
float exposure = max(pc.exposure, 0.0001);
|
||||
vec3 mapped = hdr * exposure;
|
||||
|
||||
Reference in New Issue
Block a user