Jarvis, Optimise my shit
This commit is contained in:
parent
d1abde919d
commit
9424b29d0a
50 changed files with 1469 additions and 1232 deletions
|
|
@ -2,36 +2,27 @@
|
|||
|
||||
layout(constant_id = 0) const int USE_AA = 0;
|
||||
|
||||
const float GAMMA_CONST = 0.4545;
|
||||
const float Exposure = 2.0;
|
||||
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 sampler2D inputTexture;
|
||||
layout(set = 0, binding = 1) uniform sampler2D bloomImage;
|
||||
|
||||
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;
|
||||
}
|
||||
layout(push_constant) uniform PassConfig {
|
||||
int horizontal;
|
||||
float GAMMA_CONST;
|
||||
float Exposure;
|
||||
float blur_radius;
|
||||
vec2 bloomSize;
|
||||
} config;
|
||||
|
||||
// Sourced from: https://mini.gmshaders.com/p/gm-shaders-mini-fxaa
|
||||
vec4 fxaa(sampler2D tex, vec2 uv) {
|
||||
vec2 u_texel = 1.0 / screenSize.size;
|
||||
vec2 u_texel = 1.0 / vec2(textureSize(inputTexture, 0));
|
||||
|
||||
//Sample center and 4 corners
|
||||
vec3 rgbCC = texture(tex, uv).rgb;
|
||||
|
|
@ -79,36 +70,22 @@ vec4 fxaa(sampler2D tex, vec2 uv) {
|
|||
return ((lumaB < lumaMin) || (lumaB > lumaMax)) ? A : B;
|
||||
}
|
||||
|
||||
vec3 bloomAt(ivec2 pixel, ivec2 size) {
|
||||
return texelFetch(bloomImage, clamp(pixel, ivec2(0), size - 1), 0).rgb;
|
||||
}
|
||||
|
||||
vec3 upsampleBloom(vec2 uv) {
|
||||
ivec2 size = textureSize(bloomImage, 0);
|
||||
vec2 pixel = uv * vec2(size) - 0.5;
|
||||
ivec2 base = ivec2(floor(pixel));
|
||||
vec2 blend = fract(pixel);
|
||||
return mix(mix(bloomAt(base, size), bloomAt(base + ivec2(1, 0), size), blend.x),
|
||||
mix(bloomAt(base + ivec2(0, 1), size), bloomAt(base + ivec2(1, 1), size), blend.x), blend.y);
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
if(USE_AA == 1){
|
||||
outFragColor = fxaa(inputTexture, inTextCoord);
|
||||
}
|
||||
else if(USE_AA == 2){
|
||||
|
||||
outFragColor = texture(inputTexture, inTextCoord);
|
||||
}
|
||||
else if(USE_AA == 3){
|
||||
|
||||
outFragColor = texture(inputTexture, inTextCoord);
|
||||
}
|
||||
else if(USE_AA == 4){
|
||||
|
||||
outFragColor = texture(inputTexture, inTextCoord);
|
||||
}
|
||||
else {
|
||||
outFragColor = texture(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);
|
||||
vec4 sceneColor = USE_AA == 1 ? fxaa(inputTexture, inTextCoord) : texture(inputTexture, inTextCoord);
|
||||
vec3 hdrColour = max(sceneColor.rgb + upsampleBloom(inTextCoord), vec3(0.0));
|
||||
vec3 result = vec3(1.0) - exp(-hdrColour * config.Exposure);
|
||||
outFragColor = vec4(pow(result, vec3(1.0 / config.GAMMA_CONST)), sceneColor.a);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue