72 lines
No EOL
2 KiB
GLSL
72 lines
No EOL
2 KiB
GLSL
#version 450
|
|
|
|
layout(constant_id = 0) const int USE_AA = 0;
|
|
|
|
const float GAMMA_CONST = 0.4545;
|
|
const float SPAN_MAX = 8.0;
|
|
const float REDUCE_MIN = 1.0/128.0;
|
|
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;
|
|
|
|
layout(set = 1, binding = 0) uniform ScreenSize{
|
|
vec2 size;
|
|
} 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);
|
|
|
|
for(int i = 0; i < sampleCount; ++i) {
|
|
vec4 sampleColor = texelFetch(textureIn, pixelCoords, i);
|
|
colorSum += sampleColor;
|
|
}
|
|
return colorSum / float(sampleCount);
|
|
}
|
|
|
|
void main(){
|
|
ivec2 pixelCoords = ivec2(inTextCoord * textureSize(inputTexture));
|
|
|
|
outFragColor = texelFetch(inputTexture, pixelCoords, 0);
|
|
|
|
if(USE_AA == 0){
|
|
outFragColor = texelFetch(inputTexture,pixelCoords,0);
|
|
}
|
|
if(USE_AA == 1){
|
|
outFragColor = texelFetch(inputTexture,pixelCoords,0);
|
|
}
|
|
if(USE_AA == 2){
|
|
outFragColor = msaa(2,inputTexture,inTextCoord);
|
|
}
|
|
if(USE_AA == 3){
|
|
outFragColor = msaa(4,inputTexture,inTextCoord);
|
|
}
|
|
if(USE_AA == 4){
|
|
outFragColor = msaa(8,inputTexture,inTextCoord);
|
|
}
|
|
|
|
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);
|
|
} |