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

Merge branch '77-lens-flares' into 'develop'

Resolve "Lens Flares"

Closes #77

See merge request !62
parents 09fd98e2 87c3435b
No related branches found
No related tags found
1 merge request!62Resolve "Lens Flares"
Pipeline #26061 failed
Showing
with 351 additions and 0 deletions
projects/bloom/resources/Sponza/sponza_fabric_blue_diff.png

132 B

projects/bloom/resources/Sponza/sponza_fabric_diff.png

132 B

projects/bloom/resources/Sponza/sponza_fabric_green_diff.png

132 B

projects/bloom/resources/Sponza/sponza_flagpole_diff.png

132 B

projects/bloom/resources/Sponza/sponza_floor_a_diff.png

132 B

projects/bloom/resources/Sponza/sponza_roof_diff.png

132 B

projects/bloom/resources/Sponza/sponza_thorn_diff.png

131 B

projects/bloom/resources/Sponza/vase_dif.png

132 B

projects/bloom/resources/Sponza/vase_hanging.png

132 B

projects/bloom/resources/Sponza/vase_plant.png

131 B

projects/bloom/resources/Sponza/vase_round.png

132 B

File added
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(set=0, binding=0) uniform texture2D blurImage;
layout(set=0, binding=1) uniform texture2D lensImage;
layout(set=0, binding=2) uniform sampler linearSampler;
layout(set=0, binding=3, r11f_g11f_b10f) uniform image2D colorBuffer;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main()
{
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(colorBuffer)))){
return;
}
ivec2 pixel_coord = ivec2(gl_GlobalInvocationID.xy);
vec2 pixel_size = vec2(1.0f) / textureSize(sampler2D(blurImage, linearSampler), 0);
vec2 UV = pixel_coord.xy * pixel_size;
vec4 composite_color = vec4(0.0f);
vec3 blur_color = texture(sampler2D(blurImage, linearSampler), UV).rgb;
vec3 lens_color = texture(sampler2D(lensImage, linearSampler), UV).rgb;
vec3 main_color = imageLoad(colorBuffer, pixel_coord).rgb;
// composite blur and lens features
float bloom_weight = 0.25f;
float lens_weight = 0.25f;
float main_weight = 1 - (bloom_weight + lens_weight);
composite_color.rgb = blur_color * bloom_weight +
lens_color * lens_weight +
main_color * main_weight;
imageStore(colorBuffer, pixel_coord, composite_color);
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(set=0, binding=0) uniform texture2D inBlurImage;
layout(set=0, binding=1) uniform sampler inImageSampler;
layout(set=0, binding=2, r11f_g11f_b10f) uniform writeonly image2D outBlurImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main()
{
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(outBlurImage)))){
return;
}
ivec2 pixel_coord = ivec2(gl_GlobalInvocationID.xy);
vec2 pixel_size = vec2(1.0f) / imageSize(outBlurImage);
vec2 UV = pixel_coord.xy * pixel_size;
vec2 UV_offset = UV + 0.5f * pixel_size;
vec2 color_fetches[13] = {
// center neighbourhood (RED)
vec2(-1, 1), // LT
vec2(-1, -1), // LB
vec2( 1, -1), // RB
vec2( 1, 1), // RT
vec2(-2, 2), // LT
vec2( 0, 2), // CT
vec2( 2, 2), // RT
vec2(0 ,-2), // LC
vec2(0 , 0), // CC
vec2(2, 0), // CR
vec2(-2, -2), // LB
vec2(0 , -2), // CB
vec2(2 , -2) // RB
};
float color_weights[13] = {
// 0.5f
1.f/8.f,
1.f/8.f,
1.f/8.f,
1.f/8.f,
// 0.125f
1.f/32.f,
1.f/16.f,
1.f/32.f,
// 0.25f
1.f/16.f,
1.f/8.f,
1.f/16.f,
// 0.125f
1.f/32.f,
1.f/16.f,
1.f/32.f
};
vec3 sampled_color = vec3(0.0f);
for(uint i = 0; i < 13; i++)
{
vec2 color_fetch = UV_offset + color_fetches[i] * pixel_size;
vec3 color = texture(sampler2D(inBlurImage, inImageSampler), color_fetch).rgb;
color *= color_weights[i];
sampled_color += color;
}
imageStore(outBlurImage, pixel_coord, vec4(sampled_color, 1.f));
}
\ No newline at end of file
#version 440
layout(set=0, binding=0, r11f_g11f_b10f) uniform image2D inImage;
layout(set=0, binding=1, rgba8) uniform image2D outImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main(){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(inImage)))){
return;
}
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec3 linearColor = imageLoad(inImage, uv).rgb;
// cheap Reinhard tone mapping
linearColor = linearColor/(linearColor + 1.0f);
vec3 gammaCorrected = pow(linearColor, vec3(1.f / 2.2f));
imageStore(outImage, uv, vec4(gammaCorrected, 0.f));
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(set=0, binding=0) uniform texture2D blurBuffer;
layout(set=0, binding=1) uniform sampler linearSampler;
layout(set=0, binding=2, r11f_g11f_b10f) uniform image2D lensBuffer;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
vec3 sampleColorChromaticAberration(vec2 _uv)
{
vec2 toCenter = (vec2(0.5) - _uv);
vec3 colorScales = vec3(-1, 0, 1);
float aberrationScale = 0.1;
vec3 scaleFactors = colorScales * aberrationScale;
float r = texture(sampler2D(blurBuffer, linearSampler), _uv + toCenter * scaleFactors.r).r;
float g = texture(sampler2D(blurBuffer, linearSampler), _uv + toCenter * scaleFactors.g).g;
float b = texture(sampler2D(blurBuffer, linearSampler), _uv + toCenter * scaleFactors.b).b;
return vec3(r, g, b);
}
// _uv assumed to be flipped UV coordinates!
vec3 ghost_vectors(vec2 _uv)
{
vec2 ghost_vec = (vec2(0.5f) - _uv);
const uint c_ghost_count = 64;
const float c_ghost_spacing = length(ghost_vec) / c_ghost_count;
ghost_vec *= c_ghost_spacing;
vec3 ret_color = vec3(0.0f);
for (uint i = 0; i < c_ghost_count; ++i)
{
// sample scene color
vec2 s_uv = fract(_uv + ghost_vec * vec2(i));
vec3 s = sampleColorChromaticAberration(s_uv);
// tint/weight
float d = distance(s_uv, vec2(0.5));
float weight = 1.0f - smoothstep(0.0f, 0.75f, d);
s *= weight;
ret_color += s;
}
ret_color /= c_ghost_count;
return ret_color;
}
vec3 halo(vec2 _uv)
{
const float c_aspect_ratio = float(imageSize(lensBuffer).x) / float(imageSize(lensBuffer).y);
const float c_radius = 0.6f;
const float c_halo_thickness = 0.1f;
vec2 halo_vec = vec2(0.5) - _uv;
//halo_vec.x /= c_aspect_ratio;
halo_vec = normalize(halo_vec);
//halo_vec.x *= c_aspect_ratio;
//vec2 w_uv = (_uv - vec2(0.5, 0.0)) * vec2(c_aspect_ratio, 1.0) + vec2(0.5, 0.0);
vec2 w_uv = _uv;
float d = distance(w_uv, vec2(0.5)); // distance to center
float distance_to_halo = abs(d - c_radius);
float halo_weight = 0.0f;
if(abs(d - c_radius) <= c_halo_thickness)
{
float distance_to_border = c_halo_thickness - distance_to_halo;
halo_weight = distance_to_border / c_halo_thickness;
//halo_weight = clamp((halo_weight / 0.4f), 0.0f, 1.0f);
halo_weight = pow(halo_weight, 2.0f);
//halo_weight = 1.0f;
}
return sampleColorChromaticAberration(_uv + halo_vec) * halo_weight;
}
void main()
{
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(lensBuffer)))){
return;
}
ivec2 pixel_coord = ivec2(gl_GlobalInvocationID.xy);
vec2 pixel_size = vec2(1.0f) / imageSize(lensBuffer);
vec2 UV = pixel_coord.xy * pixel_size;
vec2 flipped_UV = vec2(1.0f) - UV;
vec3 color = vec3(0.0f);
color += ghost_vectors(flipped_UV);
color += halo(UV);
color *= 0.5f;
imageStore(lensBuffer, pixel_coord, vec4(color, 0.0f));
}
\ No newline at end of file
layout(set=1, binding=0) uniform texture2D albedoTexture;
layout(set=1, binding=1) uniform sampler textureSampler;
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_GOOGLE_include_directive : enable
#include "perMeshResources.inc"
layout(location = 0) in vec3 passNormal;
layout(location = 1) in vec2 passUV;
layout(location = 2) in vec3 passPos;
layout(location = 0) out vec3 outColor;
layout(set=0, binding=0) uniform sunBuffer {
vec3 L; float padding;
mat4 lightMatrix;
};
layout(set=0, binding=1) uniform texture2D shadowMap;
layout(set=0, binding=2) uniform sampler shadowMapSampler;
float shadowTest(vec3 worldPos){
vec4 lightPos = lightMatrix * vec4(worldPos, 1);
lightPos /= lightPos.w;
lightPos.xy = lightPos.xy * 0.5 + 0.5;
if(any(lessThan(lightPos.xy, vec2(0))) || any(greaterThan(lightPos.xy, vec2(1)))){
return 1;
}
lightPos.z = clamp(lightPos.z, 0, 1);
float shadowMapSample = texture(sampler2D(shadowMap, shadowMapSampler), lightPos.xy).r;
float bias = 0.01f;
shadowMapSample += bias;
return shadowMapSample < lightPos.z ? 0 : 1;
}
void main() {
vec3 N = normalize(passNormal);
vec3 sunColor = vec3(10);
vec3 sun = sunColor * clamp(dot(N, L), 0, 1);
sun *= shadowTest(passPos);
vec3 ambient = vec3(0.05);
vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb;
outColor = albedo * (sun + ambient);
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inUV;
layout(location = 0) out vec3 passNormal;
layout(location = 1) out vec2 passUV;
layout(location = 2) out vec3 passPos;
layout( push_constant ) uniform constants{
mat4 mvp;
mat4 model;
};
void main() {
gl_Position = mvp * vec4(inPosition, 1.0);
passNormal = mat3(model) * inNormal; // assuming no weird stuff like shearing or non-uniform scaling
passUV = inUV;
passPos = (model * vec4(inPosition, 1)).xyz;
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
void main() {
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment