work on bloom

This commit is contained in:
Tuomas Katajisto 2025-10-24 08:10:52 +03:00
parent 2bd90b3636
commit a0845ed16f
12 changed files with 1186 additions and 733 deletions

View File

@ -1,16 +1,20 @@
{
"exposure": -0.239281,
"exposure": -0.438614,
"contrast": 1.821381,
"saturation": 0.988528,
"gamma": 2.194679,
"gamma": 1.892629,
"tonemap": 1,
"ssao": 0.823773,
"dilate_separation": 1.318038,
"dilate_size": 7,
"dilate_min": 0.142381,
"dilate_max": 0.242047,
"dilate_separation": 3.636807,
"dilate_size": 2,
"dilate_min": 0.136279,
"dilate_max": 0.45155,
"dof_blur_size": 2,
"dof_min": 2.750411,
"dof_max": 15.987307,
"dof_point": 11.471807
"dof_min": 3.234074,
"dof_max": 8.339435,
"dof_point": 5.979985,
"bloom_size": 3,
"bloom_separation": 2.562851,
"bloom_treshold": 0.732243,
"bloom_amount": 0.762753
}

File diff suppressed because one or more lines are too long

View File

@ -317,6 +317,7 @@ backend_process_command_buckets :: () {
sg_end_pass();
current_trile_offset_index = 0; // This is not optimal, but it is nice and simple.
bloom_process();
dof_process();
// Begin drawing to swapchain

View File

@ -1,16 +1,44 @@
bloom_process :: () {
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_postprocess_attach_a }));
sg_apply_pipeline(gPipelines.op.pipeline);
op_uniform_bloom : Op_Fs_Params;
op_uniform_bloom.blur_size = current_post_process.bloom_size;
op_uniform_bloom.separation = current_post_process.bloom_separation;
op_uniform_bloom.bloom_treshold = current_post_process.bloom_treshold;
op_uniform_bloom.bloom_amount = current_post_process.bloom_amount;
op_uniform_bloom.op=3;
gPipelines.op.bind.images[0] = g_rendertex;
sg_apply_uniforms(UB_op_fs_params, *(sg_range.{ ptr = *op_uniform_bloom, size = size_of(type_of(op_uniform_bloom)) }));
sg_apply_bindings(*gPipelines.op.bind);
sg_draw(0, 6, 1);
sg_end_pass();
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_postprocess_attach_b }));
sg_apply_pipeline(gPipelines.mix.pipeline);
mix_uniform : Mix_Fs_Params;
mix_uniform.op = 1;
gPipelines.mix.bind.images[0] = g_postprocess_a;
gPipelines.mix.bind.images[1] = g_rendertex;
gPipelines.mix.bind.images[2] = g_gbuf_position;
sg_apply_uniforms(UB_op_fs_params, *(sg_range.{ ptr = *mix_uniform, size = size_of(type_of(mix_uniform)) }));
sg_apply_bindings(*gPipelines.mix.bind);
sg_draw(0, 6, 1);
sg_end_pass();
}
dof_process :: () {
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_postprocess_attach_a }));
sg_apply_pipeline(gPipelines.op.pipeline);
op_uniform_dilate : Op_Fs_Params;
op_uniform_dilate.blur_size = current_post_process.dof_blur_size;
op_uniform_dilate.op=2;
gPipelines.op.bind.images[0] = g_rendertex;
gPipelines.op.bind.images[0] = g_postprocess_b;
sg_apply_uniforms(UB_op_fs_params, *(sg_range.{ ptr = *op_uniform_dilate, size = size_of(type_of(op_uniform_dilate)) }));
sg_apply_bindings(*gPipelines.op.bind);
sg_draw(0, 6, 1);
sg_end_pass();
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_postprocess_attach_b }));
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_rendertex_attachments }));
sg_apply_pipeline(gPipelines.op.pipeline);
op_uniform_dof_blur : Op_Fs_Params;
op_uniform_dof_blur.blur_size = current_post_process.dilate_size;
@ -31,8 +59,8 @@ dof_process :: () {
mix_uniform.dof_min = current_post_process.dof_min;
mix_uniform.dof_max = current_post_process.dof_max;
mix_uniform.dof_point = current_post_process.dof_point;
gPipelines.mix.bind.images[0] = g_postprocess_b;
gPipelines.mix.bind.images[1] = g_rendertex;
gPipelines.mix.bind.images[0] = g_rendertex;
gPipelines.mix.bind.images[1] = g_postprocess_b;
gPipelines.mix.bind.images[2] = g_gbuf_position;
sg_apply_uniforms(UB_op_fs_params, *(sg_range.{ ptr = *mix_uniform, size = size_of(type_of(mix_uniform)) }));
sg_apply_bindings(*gPipelines.mix.bind);

View File

@ -708,7 +708,8 @@ create_op_pipeline :: () {
enabled = true,
src_factor_rgb = .SRC_ALPHA,
dst_factor_rgb = .ONE_MINUS_SRC_ALPHA
}
},
pixel_format = .RGBA32F,
};
pipeline.depth = .{
write_enabled = true,
@ -769,7 +770,8 @@ create_mix_pipeline :: () {
enabled = true,
src_factor_rgb = .SRC_ALPHA,
dst_factor_rgb = .ONE_MINUS_SRC_ALPHA
}
},
pixel_format = .RGBA32F,
};
pipeline.depth = .{
write_enabled = true,
@ -826,6 +828,7 @@ create_ssao_images :: () {
width = w,
height = h,
render_target = true,
pixel_format = .RGBA32F
};
img_desc.sample_count = 1;
g_ssaobuf = sg_make_image(*img_desc);
@ -879,7 +882,8 @@ create_ssao_pipeline :: () {
enabled = true,
src_factor_rgb = .SRC_ALPHA,
dst_factor_rgb = .ONE_MINUS_SRC_ALPHA
}
},
pixel_format = .RGBA32F,
};
pipeline.color_count = 1;

View File

@ -11,8 +11,12 @@ Post_Process :: struct {
dilate_max : float = 0.3; @Slider,0,1,0.1;
dof_blur_size : s32 = 2; @Slider,0,10,1;
dof_min : float = 1.0; @Slider,0,10,1;
dof_max : float = 3.0; @Slider,0,20,1;
dof_max : float = 3.0; @Slider,0,50,1;
dof_point : float = 5.0; @Slider,0,30,1;
bloom_size : s32 = 5; @Slider,0,10,1;
bloom_separation : float = 3.0; @Slider,0,10,1;
bloom_treshold : float = 0.4; @Slider,0,1,0.1;
bloom_amount : float = 1.0; @Slider,0,5,0.1;
}
current_post_process : Post_Process;

View File

@ -109,7 +109,10 @@ vs_mix_source_glsl430 := u8.[
}
else
{
frag_color = vec4(1.0);
if (_10.op == 1)
{
frag_color = vec4(texture(mixtex_b_mixsmp, texcoord).xyz + texture(mixtex_a_mixsmp, texcoord).xyz, 1.0);
}
}
}
@ -157,9 +160,17 @@ fs_mix_source_glsl430 := u8.[
0x20,0x2b,0x20,0x5f,0x31,0x30,0x2e,0x64,0x6f,0x66,0x5f,0x70,0x6f,0x69,0x6e,0x74,
0x29,0x29,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,
0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x31,0x2e,0x30,0x29,0x3b,
0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00,
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,
0x2e,0x6f,0x70,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,
0x34,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x6d,0x69,0x78,0x74,0x65,0x78,
0x5f,0x62,0x5f,0x6d,0x69,0x78,0x73,0x6d,0x70,0x2c,0x20,0x74,0x65,0x78,0x63,0x6f,
0x6f,0x72,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,
0x72,0x65,0x28,0x6d,0x69,0x78,0x74,0x65,0x78,0x5f,0x61,0x5f,0x6d,0x69,0x78,0x73,
0x6d,0x70,0x2c,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x29,0x2e,0x78,0x79,
0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#version 300 es
@ -219,7 +230,10 @@ vs_mix_source_glsl300es := u8.[
}
else
{
frag_color = vec4(1.0);
if (_10.op == 1)
{
frag_color = vec4(texture(mixtex_b_mixsmp, texcoord).xyz + texture(mixtex_a_mixsmp, texcoord).xyz, 1.0);
}
}
}
@ -268,9 +282,17 @@ fs_mix_source_glsl300es := u8.[
0x5f,0x31,0x30,0x2e,0x64,0x6f,0x66,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x29,0x29,0x29,
0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,
0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,
0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,
0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x2e,0x6f,0x70,
0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,
0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,
0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x6d,0x69,0x78,0x74,0x65,0x78,0x5f,0x62,0x5f,
0x6d,0x69,0x78,0x73,0x6d,0x70,0x2c,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,
0x29,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,
0x6d,0x69,0x78,0x74,0x65,0x78,0x5f,0x61,0x5f,0x6d,0x69,0x78,0x73,0x6d,0x70,0x2c,
0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,
0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,
0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#include <metal_stdlib>
@ -362,7 +384,10 @@ vs_mix_source_metal_macos := u8.[
}
else
{
out.frag_color = float4(1.0);
if (_10.op == 1)
{
out.frag_color = float4(mixtex_b.sample(mixsmp, in.texcoord).xyz + mixtex_a.sample(mixsmp, in.texcoord).xyz, 1.0);
}
}
return out;
}
@ -422,10 +447,19 @@ fs_mix_source_metal_macos := u8.[
0x20,0x5f,0x31,0x30,0x2e,0x64,0x6f,0x66,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x29,0x29,
0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,
0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x66,0x72,0x61,0x67,0x5f,
0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x31,
0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,
0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x2e,0x6f,
0x70,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,
0x74,0x2e,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x28,0x6d,0x69,0x78,0x74,0x65,0x78,0x5f,0x62,0x2e,0x73,
0x61,0x6d,0x70,0x6c,0x65,0x28,0x6d,0x69,0x78,0x73,0x6d,0x70,0x2c,0x20,0x69,0x6e,
0x2e,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2b,
0x20,0x6d,0x69,0x78,0x74,0x65,0x78,0x5f,0x61,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,
0x28,0x6d,0x69,0x78,0x73,0x6d,0x70,0x2c,0x20,0x69,0x6e,0x2e,0x74,0x65,0x78,0x63,
0x6f,0x6f,0x72,0x64,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,
0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,
0x0a,0x7d,0x0a,0x0a,0x00,
];
mix_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc: sg_shader_desc;

File diff suppressed because it is too large Load Diff

View File

@ -260,7 +260,7 @@ vs_plane_source_glsl430 := u8.[
_367.y = 1.0 - _367.y;
vec3 param_1 = normalize(pos.xyz);
vec3 param_2 = _146.sunPosition;
float _419 = smoothstep(950.0, 1000.0, length(pos.xz));
float _419 = smoothstep(750.0, 1000.0, length(pos.xz));
frag_color = vec4(mix((mix(((_146.waterColor * (dot(_274, _290) + ((9.9999999747524270787835121154785e-07 * float(_309.is_reflection)) * _278.shininess))) * _146.sunLightColor) * _146.sunIntensity, texture(reftex_refsmp, _367).xyz, vec3(_335)) + ((_146.sunLightColor * _146.sunIntensity) * pow(max(0.0, dot(normalize(_290 + _285), _274)), 32.0))) * 1.0, sky(param_1, param_2) * _146.skyIntensity, vec3(_419)), mix(mix(0.300000011920928955078125, 0.5, _335), 1.0, _419));
}
else
@ -470,7 +470,7 @@ fs_plane_source_glsl430 := u8.[
0x3d,0x20,0x5f,0x31,0x34,0x36,0x2e,0x73,0x75,0x6e,0x50,0x6f,0x73,0x69,0x74,0x69,
0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
0x74,0x20,0x5f,0x34,0x31,0x39,0x20,0x3d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,
0x74,0x65,0x70,0x28,0x39,0x35,0x30,0x2e,0x30,0x2c,0x20,0x31,0x30,0x30,0x30,0x2e,
0x74,0x65,0x70,0x28,0x37,0x35,0x30,0x2e,0x30,0x2c,0x20,0x31,0x30,0x30,0x30,0x2e,
0x30,0x2c,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x70,0x6f,0x73,0x2e,0x78,0x7a,
0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,
0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x6d,0x69,
@ -684,7 +684,7 @@ vs_plane_source_glsl300es := u8.[
_367.y = 1.0 - _367.y;
highp vec3 param_1 = normalize(pos.xyz);
highp vec3 param_2 = _146.sunPosition;
highp float _419 = smoothstep(950.0, 1000.0, length(pos.xz));
highp float _419 = smoothstep(750.0, 1000.0, length(pos.xz));
frag_color = vec4(mix((mix(((_146.waterColor * (dot(_274, _290) + ((9.9999999747524270787835121154785e-07 * float(_309.is_reflection)) * _278.shininess))) * _146.sunLightColor) * _146.sunIntensity, texture(reftex_refsmp, _367).xyz, vec3(_335)) + ((_146.sunLightColor * _146.sunIntensity) * pow(max(0.0, dot(normalize(_290 + _285), _274)), 32.0))) * 1.0, sky(param_1, param_2) * _146.skyIntensity, vec3(_419)), mix(mix(0.300000011920928955078125, 0.5, _335), 1.0, _419));
}
else
@ -911,7 +911,7 @@ fs_plane_source_glsl300es := u8.[
0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,
0x31,0x39,0x20,0x3d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,
0x39,0x35,0x30,0x2e,0x30,0x2c,0x20,0x31,0x30,0x30,0x30,0x2e,0x30,0x2c,0x20,0x6c,
0x37,0x35,0x30,0x2e,0x30,0x2c,0x20,0x31,0x30,0x30,0x30,0x2e,0x30,0x2c,0x20,0x6c,
0x65,0x6e,0x67,0x74,0x68,0x28,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x29,0x29,0x3b,0x0a,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,
0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x6d,0x69,0x78,0x28,0x28,0x6d,
@ -1172,7 +1172,7 @@ vs_plane_source_metal_macos := u8.[
_367.y = 1.0 - _367.y;
float3 param_1 = fast::normalize(in.pos.xyz);
float3 param_2 = float3(_146.sunPosition);
float _419 = smoothstep(950.0, 1000.0, length(in.pos.xz));
float _419 = smoothstep(750.0, 1000.0, length(in.pos.xz));
out.frag_color = float4(mix((mix(((_146.waterColor * (dot(_274, _290) + ((9.9999999747524270787835121154785e-07 * float(_309.is_reflection)) * _278.shininess))) * _146.sunLightColor) * _146.sunIntensity, reftex.sample(refsmp, _367).xyz, float3(_335)) + ((_146.sunLightColor * _146.sunIntensity) * powr(fast::max(0.0, dot(fast::normalize(_290 + _285), _274)), 32.0))) * 1.0, sky(param_1, param_2, _146) * _146.skyIntensity, float3(_419)), mix(mix(0.300000011920928955078125, 0.5, _335), 1.0, _419));
}
else
@ -1435,7 +1435,7 @@ fs_plane_source_metal_macos := u8.[
0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x34,0x36,0x2e,0x73,0x75,0x6e,0x50,0x6f,0x73,
0x69,0x74,0x69,0x6f,0x6e,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x31,0x39,0x20,0x3d,0x20,0x73,0x6d,0x6f,
0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x39,0x35,0x30,0x2e,0x30,0x2c,0x20,0x31,
0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x37,0x35,0x30,0x2e,0x30,0x2c,0x20,0x31,
0x30,0x30,0x30,0x2e,0x30,0x2c,0x20,0x6c,0x65,0x6e,0x67,0x74,0x68,0x28,0x69,0x6e,
0x2e,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,

View File

@ -21,9 +21,8 @@ layout(binding=1) uniform mix_fs_params {
float dof_point;
/*
List of mixs:
0. blur for ssao
1. dilate.
2. normal blur
0. DOF
1. Add
*/
};
@ -40,8 +39,10 @@ void main() {
vec4 position = texture(sampler2D(mixtex_c, mixsmp), texcoord);
float blur = smoothstep(dof_min, dof_max, abs(position.z + dof_point));
frag_color = vec4(mix(in_focus, out_focus, blur), 1.0);
} else {
frag_color = vec4(1.0);
} else if(op == 1) {
vec3 a = texture(sampler2D(mixtex_b, mixsmp), texcoord).rgb;
vec3 b = texture(sampler2D(mixtex_a, mixsmp), texcoord).rgb;
frag_color = vec4(a+b, 1.0);
}
}
@end

View File

@ -15,24 +15,53 @@ in vec2 texcoord;
out vec4 frag_color;
layout(binding=1) uniform op_fs_params {
int blur_size;
int op;
float separation;
float dilate_min;
float dilate_max;
/*
List of ops:
0. blur for ssao
1. dilate.
2. normal blur
3. bloom
*/
int op;
// Common
int blur_size;
float separation;
// DOF
float dilate_min;
float dilate_max;
// Bloom
float bloom_amount;
float bloom_treshold;
};
layout(binding = 0) uniform texture2D optex;
layout(binding = 0) uniform sampler opsmp;
void main() {
if(op == 2) {
if(op == 3) {
vec2 texSize = vec2(textureSize(sampler2D(optex, opsmp), 0));
float value = 0.0;
float count = 0.0;
vec4 result = vec4(0.0);
vec4 color = vec4(0.0);
for(int i = -blur_size ; i <= blur_size; ++i) {
for(int j = -blur_size; j <= blur_size; ++j) {
color = texture(sampler2D(optex, opsmp), (gl_FragCoord.xy + vec2(i,j) * separation) / texSize);
value = max(color.r, max(color.g, color.b));
if(value < bloom_treshold) { color = vec4(0); }
result += color;
count += 1.0;
}
}
result /= count;
frag_color = vec4(result.xyz * bloom_amount, 1.0);
} else if(op == 2) {
vec2 texelSize = 1.0 / vec2(textureSize(sampler2D(optex, opsmp), 0));
vec3 result = vec3(0.0);
for (int x = -blur_size; x < blur_size; ++x)

View File

@ -148,7 +148,7 @@ void main() {
float alpha = mix(refraction_alpha, reflection_alpha, fresnel);
vec3 fog = skyIntensity * sky(normalize(pos.xyz), sunPosition);
float fogFactor = smoothstep(950.0, 1000.0, length(pos.xz));
float fogFactor = smoothstep(750.0, 1000.0, length(pos.xz));
frag_color = vec4(mix(final_color, fog, fogFactor), mix(alpha, 1.0, fogFactor));