Skip to content
Snippets Groups Projects
Commit ffad5823 authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#82] Add subtle chromatic aberration in high contrast areas

parent 8d6fbab4
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
Pipeline #26033 passed
#ifndef LUMA_INC
#define LUMA_INC
float computeLuma(vec3 c){
return dot(c, vec3(0.21, 0.72, 0.07));
}
#endif // #ifndef LUMA_INC
\ No newline at end of file
#version 450
#extension GL_ARB_texture_multisample : enable
#extension GL_GOOGLE_include_directive : enable
layout(set=0, binding=0) uniform texture2DMS srcTexture;
layout(set=0, binding=1) uniform sampler MSAASampler;
layout(set=0, binding=2, r11f_g11f_b10f) uniform image2D outImage;
#include "luma.inc"
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
float computeLuma(vec3 c){
return dot(c, vec3(0.21, 0.72, 0.07));
}
vec3 tonemap(vec3 c){
return c / (1 + computeLuma(c));
}
......
#version 440
#extension GL_GOOGLE_include_directive : enable
#include "luma.inc"
layout(set=0, binding=0) uniform texture2D inTexture;
layout(set=0, binding=1) uniform sampler textureSampler;
......@@ -78,6 +81,44 @@ vec2 computeDistortedUV(vec2 uv, float aspectRatio){
return uv + toCenter * (r2*k1 + r2*r2*k2);
}
float computeLocalContrast(vec2 uv){
float lumaMin = 100;
float lumaMax = 0;
vec2 pixelSize = vec2(1) / textureSize(sampler2D(inTexture, textureSampler), 0);
for(int x = -1; x <= 1; x++){
for(int y = -1; y <= 1; y++){
vec3 c = texture(sampler2D(inTexture, textureSampler), uv + vec2(x, y) * pixelSize).rgb;
float luma = computeLuma(c);
lumaMin = min(lumaMin, luma);
lumaMax = max(lumaMax, luma);
}
}
return lumaMax - lumaMin;
}
vec3 computeChromaticAberrationScale(vec2 uv){
float localContrast = computeLocalContrast(uv);
vec3 colorScales = vec3(-1, 0, 1);
float aberrationScale = 0.004;
vec3 maxScaleFactors = colorScales * aberrationScale;
float factor = clamp(localContrast, 0, 1);
return mix(vec3(0), maxScaleFactors, factor);
}
vec3 sampleColorChromaticAberration(vec2 uv){
vec2 toCenter = (vec2(0.5) - uv);
vec3 scaleFactors = computeChromaticAberrationScale(uv);
float r = texture(sampler2D(inTexture, textureSampler), uv + toCenter * scaleFactors.r).r;
float g = texture(sampler2D(inTexture, textureSampler), uv + toCenter * scaleFactors.g).g;
float b = texture(sampler2D(inTexture, textureSampler), uv + toCenter * scaleFactors.b).b;
return vec3(r, g, b);
}
void main(){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(outImage)))){
......@@ -88,7 +129,7 @@ void main(){
vec2 uv = vec2(coord) / textureRes;
float aspectRatio = float(textureRes.x) / textureRes.y;
uv = computeDistortedUV(uv, aspectRatio);
vec3 linearColor = texture(sampler2D(inTexture, textureSampler), uv).rgb;
vec3 linearColor = sampleColorChromaticAberration(uv);
vec3 tonemapped = ACESFilm(linearColor);
tonemapped = applyGrain(coord, tonemapped);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment