more perf work

This commit is contained in:
Tuomas Katajisto 2026-04-07 06:52:16 +03:00
parent a4a3c086e2
commit 4099fd4af1
10 changed files with 6932 additions and 4478 deletions

View File

@ -13,7 +13,7 @@ theme_ptr : GR.Overall_Theme;
current_pipeline : s32 = 0; current_pipeline : s32 = 0;
current_slot : s32 = 0; current_slot : s32 = 0;
pipeline_names : []string = .["shadowmap", "reflection", "main", "position", "normal", "ssao", "rdm_atlas (chunk)", "rdm_lookup (chunk)"]; pipeline_names : []string = .["shadowmap", "reflection", "main", "position", "normal", "ssao", "bloom", "dof", "rdm_atlas (chunk)", "rdm_lookup (chunk)"];
draw_subwindow_texture_debug :: (state: *GR.Subwindow_State, r: GR.Rect, data: *void) { draw_subwindow_texture_debug :: (state: *GR.Subwindow_State, r: GR.Rect, data: *void) {
r2 := r; r2 := r;
@ -36,8 +36,10 @@ draw_subwindow_texture_debug :: (state: *GR.Subwindow_State, r: GR.Rect, data: *
case 3; image = g_gbuf_position; case 3; image = g_gbuf_position;
case 4; image = g_gbuf_normal; case 4; image = g_gbuf_normal;
case 5; image = g_ssaobuf; case 5; image = g_ssaobuf;
case 6; #through; case 6; image = g_bloom_tex;
case 7; case 7; image = g_dof_tex;
case 8; #through;
case 9;
cw := get_current_world(); cw := get_current_world();
for chunk: cw.world.chunks { for chunk: cw.world.chunks {
if chunk.rdm_valid { if chunk.rdm_valid {

View File

@ -493,6 +493,7 @@ backend_process_command_buckets :: () {
start_frame_profiling_group("Postprocess pass"); start_frame_profiling_group("Postprocess pass");
if !bypass_postprocess { if !bypass_postprocess {
bloom_process(); bloom_process();
dof_process();
} }
end_frame_profiling_group("Postprocess pass"); end_frame_profiling_group("Postprocess pass");
@ -506,16 +507,28 @@ backend_process_command_buckets :: () {
gPipelines.postprocess.bind.images[0] = g_rendertex; gPipelines.postprocess.bind.images[0] = g_rendertex;
gPipelines.postprocess.bind.images[1] = LUT_list[g_current_lut_texture_index].image; gPipelines.postprocess.bind.images[1] = LUT_list[g_current_lut_texture_index].image;
gPipelines.postprocess.bind.images[2] = g_bloom_tex; gPipelines.postprocess.bind.images[2] = g_bloom_tex;
gPipelines.postprocess.bind.images[3] = g_dof_tex;
gPipelines.postprocess.bind.images[4] = g_gbuf_position;
sg_apply_bindings(*gPipelines.postprocess.bind); sg_apply_bindings(*gPipelines.postprocess.bind);
post_process_config_uniform : Post_Process_Config; post_process_config_uniform : Post_Process_Config;
post_process_dof_config_uniform : Dof_Config;
if bypass_postprocess { if bypass_postprocess {
neutral : Post_Process; neutral : Post_Process;
neutral.tonemap = current_post_process.tonemap; neutral.tonemap = current_post_process.tonemap;
fill_uniform_with_engine_data(*post_process_config_uniform, *neutral); fill_uniform_with_engine_data(*post_process_config_uniform, *neutral);
} else { } else {
fill_uniform_with_engine_data(*post_process_config_uniform, *current_post_process); fill_uniform_with_engine_data(*post_process_config_uniform, *current_post_process);
w,h := get_render_size();
post_process_dof_config_uniform.dof_tex_width = cast(float)w/2;
post_process_dof_config_uniform.dof_tex_height = cast(float)h/2;
post_process_dof_config_uniform.dof_point = current_post_process.dof_point;
post_process_dof_config_uniform.dof_min = current_post_process.dof_min;
post_process_dof_config_uniform.dof_max = current_post_process.dof_max;
} }
sg_apply_uniforms(UB_post_process_config, *(sg_range.{ ptr = *post_process_config_uniform, size = size_of(type_of(post_process_config_uniform)) })); sg_apply_uniforms(UB_post_process_config, *(sg_range.{ ptr = *post_process_config_uniform, size = size_of(type_of(post_process_config_uniform)) }));
sg_apply_uniforms(UB_dof_config, *(sg_range.{ ptr = *post_process_dof_config_uniform, size = size_of(type_of(post_process_dof_config_uniform)) }));
sg_draw(0, 6, 1); sg_draw(0, 6, 1);
sgl_defaults(); sgl_defaults();

View File

@ -11,44 +11,56 @@ bloom_process :: () {
} }
dof_process :: () { dof_process :: () {
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_postprocess_attach_a })); sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_dof_attach }));
sg_apply_pipeline(gPipelines.op.pipeline); sg_apply_pipeline(gPipelines.dof.pipeline);
op_uniform_dilate : Op_Fs_Params; params : Dof_Params;
op_uniform_dilate.blur_size = current_post_process.dof_blur_size; // params.dof_treshold = current_post_process.dof_treshold;
op_uniform_dilate.op=2; gPipelines.dof.bind.images[IMG_dof_src] = g_rendertex;
gPipelines.op.bind.images[0] = g_postprocess_b; sg_apply_uniforms(UB_dof_params, *(sg_range.{ ptr = *params, size = size_of(type_of(params)) }));
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.dof.bind);
sg_apply_bindings(*gPipelines.op.bind); sg_draw(0, 6, 1);
sg_draw(0, 6, 1);
sg_end_pass();
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;
op_uniform_dof_blur.separation = current_post_process.dilate_separation;
op_uniform_dof_blur.dilate_min = current_post_process.dilate_min;
op_uniform_dof_blur.dilate_max = current_post_process.dilate_max;
op_uniform_dof_blur.op=1;
gPipelines.op.bind.images[0] = g_postprocess_a;
sg_apply_uniforms(UB_op_fs_params, *(sg_range.{ ptr = *op_uniform_dof_blur, size = size_of(type_of(op_uniform_dof_blur)) }));
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_a }));
sg_apply_pipeline(gPipelines.mix.pipeline);
mix_uniform : Mix_Fs_Params;
mix_uniform.op = 0;
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_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);
sg_draw(0, 6, 1);
sg_end_pass(); 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_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_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;
// op_uniform_dof_blur.separation = current_post_process.dilate_separation;
// op_uniform_dof_blur.dilate_min = current_post_process.dilate_min;
// op_uniform_dof_blur.dilate_max = current_post_process.dilate_max;
// op_uniform_dof_blur.op=1;
// gPipelines.op.bind.images[0] = g_postprocess_a;
// sg_apply_uniforms(UB_op_fs_params, *(sg_range.{ ptr = *op_uniform_dof_blur, size = size_of(type_of(op_uniform_dof_blur)) }));
// 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_a }));
// sg_apply_pipeline(gPipelines.mix.pipeline);
// mix_uniform : Mix_Fs_Params;
// mix_uniform.op = 0;
// 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_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);
// sg_draw(0, 6, 1);
// sg_end_pass();
// }

View File

@ -39,6 +39,9 @@ g_postprocess_attach_b : sg_attachments;
g_bloom_tex : sg_image; g_bloom_tex : sg_image;
g_bloom_attach : sg_attachments; g_bloom_attach : sg_attachments;
g_dof_tex : sg_image;
g_dof_attach : sg_attachments;
gPipelines : struct { gPipelines : struct {
@ -73,6 +76,7 @@ gPipelines : struct {
mix : Pipeline_Binding; mix : Pipeline_Binding;
bloom : Pipeline_Binding; bloom : Pipeline_Binding;
dof: Pipeline_Binding;
billboard : Pipeline_Binding; billboard : Pipeline_Binding;
@ -160,6 +164,7 @@ create_pipelines :: () {
create_op_pipeline(); create_op_pipeline();
create_mix_pipeline(); create_mix_pipeline();
create_bloom_pipeline(); create_bloom_pipeline();
create_dof_pipeline();
create_billboard_pipeline(); create_billboard_pipeline();
create_gbuffer_billboard_pipeline(); create_gbuffer_billboard_pipeline();
create_particle_pipeline(); create_particle_pipeline();
@ -753,6 +758,13 @@ create_postprocess_pipeline :: () {
mag_filter = .LINEAR, mag_filter = .LINEAR,
})); }));
gPipelines.postprocess.bind.samplers[3] = sg_make_sampler(*(sg_sampler_desc.{
wrap_u = .CLAMP_TO_EDGE,
wrap_v = .CLAMP_TO_EDGE,
min_filter = .LINEAR,
mag_filter = .LINEAR,
}));
} }
// Takes in a texture, manipulates it and outputs it. // Takes in a texture, manipulates it and outputs it.
@ -1038,6 +1050,52 @@ create_bloom_pipeline :: () {
})); }));
} }
create_dof_pipeline :: () {
platconf := get_plat_conf();
pipeline: sg_pipeline_desc;
shader_desc := dof_shader_desc(sg_query_backend());
pipeline.shader = sg_make_shader(*shader_desc);
pipeline.layout.attrs[ATTR_dof_position] = .{ format = .FLOAT2 };
pipeline.layout.attrs[ATTR_dof_uv] = .{ format = .FLOAT2 };
pipeline.index_type = .UINT16;
pipeline.color_count = 1;
pipeline.colors[0] = .{ pixel_format = .RGBA32F };
gPipelines.dof.pipeline = sg_make_pipeline(*pipeline);
quad_vertices : [16]float = .[
-1.0, 1.0, 0.0, flip_if_plat(1.0),
-1.0, -1.0, 0.0, flip_if_plat(0.0),
1.0, -1.0, 1.0, flip_if_plat(0.0),
1.0, 1.0, 1.0, flip_if_plat(1.0),
];
quad_indices : [6]u16 = .[
0, 1, 2, 0, 2, 3
];
vbuffer := sg_buffer_desc.{ size = size_of(float) * 16, data = .{
ptr = quad_vertices.data,
size = 16 * 4
}};
ibuffer := sg_buffer_desc.{ size = size_of(u16) * 6, data = .{
ptr = quad_indices.data,
size = 6 * 2
},
type = .INDEXBUFFER,
};
gPipelines.dof.bind.vertex_buffers[0] = sg_make_buffer(*vbuffer);
gPipelines.dof.bind.index_buffer = sg_make_buffer(*ibuffer);
gPipelines.dof.bind.samplers[0] = sg_make_sampler(*(sg_sampler_desc.{
wrap_u = .CLAMP_TO_EDGE,
wrap_v = .CLAMP_TO_EDGE,
min_filter = .NEAREST,
mag_filter = .NEAREST,
}));
}
create_ssao_images :: () { create_ssao_images :: () {
if g_ssaobuf.id != INVALID_ID then sg_destroy_image(g_ssaobuf); if g_ssaobuf.id != INVALID_ID then sg_destroy_image(g_ssaobuf);
if g_ssaobuf_depth.id != INVALID_ID then sg_destroy_image(g_ssaobuf_depth); if g_ssaobuf_depth.id != INVALID_ID then sg_destroy_image(g_ssaobuf_depth);
@ -1103,6 +1161,21 @@ create_ssao_images :: () {
}; };
sg_destroy_attachments(g_bloom_attach); sg_destroy_attachments(g_bloom_attach);
g_bloom_attach = sg_make_attachments(*bloom_attach_desc); g_bloom_attach = sg_make_attachments(*bloom_attach_desc);
if g_dof_tex.id != INVALID_ID then sg_destroy_image(g_dof_tex);
dof_img_desc := sg_image_desc.{
width = cast(s32)((cast(float)w)/1.5),
height = cast(s32)((cast(float)h)/1.5),
pixel_format = .RGBA32F,
render_target = true,
sample_count = 1,
};
g_dof_tex = sg_make_image(*dof_img_desc);
dof_attach_desc := sg_attachments_desc.{
colors[0].image = g_dof_tex,
};
sg_destroy_attachments(g_dof_attach);
g_dof_attach = sg_make_attachments(*dof_attach_desc);
} }
create_ssao_pipeline :: () { create_ssao_pipeline :: () {

View File

@ -0,0 +1,420 @@
/*
#version:1# (machine generated, don't edit!)
Generated by sokol-shdc (https://github.com/floooh/sokol-tools)
Cmdline:
sokol-shdc -i shader_dof.glsl -o ./jai/shader_dof.jai -l glsl430:glsl300es:metal_macos -f sokol_jai
Overview:
=========
Shader program: 'dof':
Get shader desc: dof_shader_desc(sg_query_backend())
Vertex Shader: vs_dof
Fragment Shader: fs_dof
Attributes:
ATTR_dof_position => 0
ATTR_dof_uv => 1
Bindings:
Uniform block 'dof_params':
Jai struct: Dof_Params
Bind slot: UB_dof_params => 0
Image 'dof_src':
Image type: ._2D
Sample type: .FLOAT
Multisampled: false
Bind slot: IMG_dof_src => 0
Sampler 'dof_src_smp':
Type: .FILTERING
Bind slot: SMP_dof_src_smp => 0
*/
ATTR_dof_position :: 0;
ATTR_dof_uv :: 1;
UB_dof_params :: 0;
IMG_dof_src :: 0;
SMP_dof_src_smp :: 0;
Dof_Params :: struct {
dof_treshold: float;
_: [12]u8;
};
/*
#version 430
layout(location = 0) in vec2 position;
layout(location = 0) out vec2 texcoord;
layout(location = 1) in vec2 uv;
void main()
{
gl_Position = vec4(position, 0.5, 1.0);
texcoord = uv;
}
*/
vs_dof_source_glsl430 := u8.[
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61,
0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x69,0x74,
0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,
0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x6c,0x61,0x79,
0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,
0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,
0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,
0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,
0x65,0x63,0x34,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x30,0x2e,
0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x65,0x78,
0x63,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#version 430
uniform vec4 dof_params[1];
layout(binding = 16) uniform sampler2D dof_src_dof_src_smp;
layout(location = 0) in vec2 texcoord;
layout(location = 0) out vec4 frag_color;
void main()
{
vec4 _24 = texture(dof_src_dof_src_smp, texcoord);
vec4 color = _24;
if (max(_24.x, max(_24.y, _24.z)) < dof_params[0].x)
{
color = vec4(0.0, 0.0, 0.0, 1.0);
}
frag_color = vec4(color.xyz, 1.0);
}
*/
fs_dof_source_glsl430 := u8.[
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e,
0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x64,0x6f,0x66,0x5f,0x70,
0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,
0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x36,0x29,0x20,0x75,
0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,
0x20,0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,0x5f,0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,
0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,
0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,
0x65,0x63,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x6c,0x61,
0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,
0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,
0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,
0x5f,0x32,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x64,0x6f,
0x66,0x5f,0x73,0x72,0x63,0x5f,0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,0x5f,0x73,0x6d,
0x70,0x2c,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x29,0x3b,0x0a,0x20,0x20,
0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,
0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x6d,0x61,0x78,0x28,
0x5f,0x32,0x34,0x2e,0x78,0x2c,0x20,0x6d,0x61,0x78,0x28,0x5f,0x32,0x34,0x2e,0x79,
0x2c,0x20,0x5f,0x32,0x34,0x2e,0x7a,0x29,0x29,0x20,0x3c,0x20,0x64,0x6f,0x66,0x5f,
0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,
0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,
0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,
0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,
0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,
0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,
0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#version 300 es
layout(location = 0) in vec2 position;
out vec2 texcoord;
layout(location = 1) in vec2 uv;
void main()
{
gl_Position = vec4(position, 0.5, 1.0);
texcoord = uv;
}
*/
vs_dof_source_glsl300es := u8.[
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a,
0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,
0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,
0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,
0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,
0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,
0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,
0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,
0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,
0x34,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x30,0x2e,0x35,0x2c,
0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x65,0x78,0x63,0x6f,
0x6f,0x72,0x64,0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#version 300 es
precision mediump float;
precision highp int;
uniform highp vec4 dof_params[1];
uniform highp sampler2D dof_src_dof_src_smp;
in highp vec2 texcoord;
layout(location = 0) out highp vec4 frag_color;
void main()
{
highp vec4 _24 = texture(dof_src_dof_src_smp, texcoord);
highp vec4 color = _24;
if (max(_24.x, max(_24.y, _24.z)) < dof_params[0].x)
{
color = vec4(0.0, 0.0, 0.0, 1.0);
}
frag_color = vec4(color.xyz, 1.0);
}
*/
fs_dof_source_glsl300es := u8.[
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a,
0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d,
0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69,
0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x75,
0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,
0x34,0x20,0x64,0x6f,0x66,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,
0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,
0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,
0x5f,0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x69,
0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78,
0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,
0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,
0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,
0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,
0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,
0x76,0x65,0x63,0x34,0x20,0x5f,0x32,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,
0x72,0x65,0x28,0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,0x5f,0x64,0x6f,0x66,0x5f,0x73,
0x72,0x63,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,
0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,
0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x32,0x34,0x3b,0x0a,0x20,
0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x6d,0x61,0x78,0x28,0x5f,0x32,0x34,0x2e,0x78,
0x2c,0x20,0x6d,0x61,0x78,0x28,0x5f,0x32,0x34,0x2e,0x79,0x2c,0x20,0x5f,0x32,0x34,
0x2e,0x7a,0x29,0x29,0x20,0x3c,0x20,0x64,0x6f,0x66,0x5f,0x70,0x61,0x72,0x61,0x6d,
0x73,0x5b,0x30,0x5d,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,
0x63,0x34,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,
0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,
0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,
0x65,0x63,0x34,0x28,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,
0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_out
{
float2 texcoord [[user(locn0)]];
float4 gl_Position [[position]];
};
struct main0_in
{
float2 position [[attribute(0)]];
float2 uv [[attribute(1)]];
};
vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.gl_Position = float4(in.position, 0.5, 1.0);
out.texcoord = in.uv;
return out;
}
*/
vs_dof_source_metal_macos := u8.[
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,
0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x20,0x5b,
0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,
0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,
0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,
0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,
0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,
0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x20,0x5b,
0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b,
0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,
0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,
0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,
0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,
0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,
0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,
0x69,0x6f,0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,
0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x2c,0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,
0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x74,0x65,0x78,
0x63,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x75,0x76,0x3b,0x0a,0x20,
0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,
0x0a,0x0a,0x00,
];
/*
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct dof_params
{
float dof_treshold;
};
struct main0_out
{
float4 frag_color [[color(0)]];
};
struct main0_in
{
float2 texcoord [[user(locn0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], constant dof_params& _42 [[buffer(0)]], texture2d<float> dof_src [[texture(0)]], sampler dof_src_smp [[sampler(0)]])
{
main0_out out = {};
float4 _24 = dof_src.sample(dof_src_smp, in.texcoord);
float4 color = _24;
if (fast::max(_24.x, fast::max(_24.y, _24.z)) < _42.dof_treshold)
{
color = float4(0.0, 0.0, 0.0, 1.0);
}
out.frag_color = float4(color.xyz, 1.0);
return out;
}
*/
fs_dof_source_metal_macos := u8.[
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x64,
0x6f,0x66,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,
0x66,0x6c,0x6f,0x61,0x74,0x20,0x64,0x6f,0x66,0x5f,0x74,0x72,0x65,0x73,0x68,0x6f,
0x6c,0x64,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,
0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,
0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,
0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,
0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,
0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,
0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,
0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,
0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,
0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x64,0x6f,0x66,0x5f,0x70,0x61,
0x72,0x61,0x6d,0x73,0x26,0x20,0x5f,0x34,0x32,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,
0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,
0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x64,0x6f,0x66,0x5f,0x73,0x72,
0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,
0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x64,0x6f,0x66,0x5f,0x73,0x72,
0x63,0x5f,0x73,0x6d,0x70,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,
0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,
0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x34,0x20,0x3d,
0x20,0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,
0x64,0x6f,0x66,0x5f,0x73,0x72,0x63,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x69,0x6e,0x2e,
0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x32,
0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x66,0x61,0x73,0x74,0x3a,
0x3a,0x6d,0x61,0x78,0x28,0x5f,0x32,0x34,0x2e,0x78,0x2c,0x20,0x66,0x61,0x73,0x74,
0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x32,0x34,0x2e,0x79,0x2c,0x20,0x5f,0x32,0x34,
0x2e,0x7a,0x29,0x29,0x20,0x3c,0x20,0x5f,0x34,0x32,0x2e,0x64,0x6f,0x66,0x5f,0x74,
0x72,0x65,0x73,0x68,0x6f,0x6c,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,
0x6c,0x6f,0x61,0x74,0x34,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,
0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,
0x0a,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,0x63,0x6f,0x6c,
0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,
0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,
0x0a,0x00,
];
dof_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc: sg_shader_desc;
desc.label = "dof_shader";
if backend == {
case .GLCORE;
desc.vertex_func.source = xx *vs_dof_source_glsl430;
desc.vertex_func.entry = "main";
desc.fragment_func.source = xx *fs_dof_source_glsl430;
desc.fragment_func.entry = "main";
desc.attrs[0].base_type = .FLOAT;
desc.attrs[0].glsl_name = "position";
desc.attrs[1].base_type = .FLOAT;
desc.attrs[1].glsl_name = "uv";
desc.uniform_blocks[0].stage = .FRAGMENT;
desc.uniform_blocks[0].layout = .STD140;
desc.uniform_blocks[0].size = 16;
desc.uniform_blocks[0].glsl_uniforms[0].type = .FLOAT4;
desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1;
desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "dof_params";
desc.images[0].stage = .FRAGMENT;
desc.images[0].multisampled = false;
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 0;
desc.image_sampler_pairs[0].sampler_slot = 0;
desc.image_sampler_pairs[0].glsl_name = "dof_src_dof_src_smp";
case .GLES3;
desc.vertex_func.source = xx *vs_dof_source_glsl300es;
desc.vertex_func.entry = "main";
desc.fragment_func.source = xx *fs_dof_source_glsl300es;
desc.fragment_func.entry = "main";
desc.attrs[0].base_type = .FLOAT;
desc.attrs[0].glsl_name = "position";
desc.attrs[1].base_type = .FLOAT;
desc.attrs[1].glsl_name = "uv";
desc.uniform_blocks[0].stage = .FRAGMENT;
desc.uniform_blocks[0].layout = .STD140;
desc.uniform_blocks[0].size = 16;
desc.uniform_blocks[0].glsl_uniforms[0].type = .FLOAT4;
desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1;
desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "dof_params";
desc.images[0].stage = .FRAGMENT;
desc.images[0].multisampled = false;
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 0;
desc.image_sampler_pairs[0].sampler_slot = 0;
desc.image_sampler_pairs[0].glsl_name = "dof_src_dof_src_smp";
case .METAL_MACOS;
desc.vertex_func.source = xx *vs_dof_source_metal_macos;
desc.vertex_func.entry = "main0";
desc.fragment_func.source = xx *fs_dof_source_metal_macos;
desc.fragment_func.entry = "main0";
desc.attrs[0].base_type = .FLOAT;
desc.attrs[1].base_type = .FLOAT;
desc.uniform_blocks[0].stage = .FRAGMENT;
desc.uniform_blocks[0].layout = .STD140;
desc.uniform_blocks[0].size = 16;
desc.uniform_blocks[0].msl_buffer_n = 0;
desc.images[0].stage = .FRAGMENT;
desc.images[0].multisampled = false;
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.images[0].msl_texture_n = 0;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.samplers[0].msl_sampler_n = 0;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 0;
desc.image_sampler_pairs[0].sampler_slot = 0;
}
return desc;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
@vs vs_dof
in vec2 position;
in vec2 uv;
out vec2 texcoord;
void main() {
gl_Position = vec4(position, 0.5, 1.0);
texcoord = uv;
}
@end
@fs fs_dof
in vec2 texcoord;
out vec4 frag_color;
layout(binding=0) uniform dof_params {
float dof_treshold;
};
layout(binding = 0) uniform texture2D dof_src;
layout(binding = 0) uniform sampler dof_src_smp;
void main() {
vec4 color = texture(sampler2D(dof_src, dof_src_smp), texcoord);
float value = max(color.r, max(color.g, color.b));
if(value < dof_treshold) { color = vec4(0.0, 0.0, 0.0, 1.0); }
frag_color = vec4(color.rgb, 1.0);
}
@end
@program dof vs_dof fs_dof

View File

@ -20,6 +20,10 @@ layout(binding = 1) uniform texture2D lut;
layout(binding = 1) uniform sampler lut_linear; layout(binding = 1) uniform sampler lut_linear;
layout(binding = 2) uniform texture2D bloom_tex; layout(binding = 2) uniform texture2D bloom_tex;
layout(binding = 2) uniform sampler bloom_smp; layout(binding = 2) uniform sampler bloom_smp;
layout(binding = 3) uniform texture2D dof_tex;
layout(binding = 3) uniform sampler dof_smp;
layout(binding = 4) uniform texture2D pos_buf;
layout(binding = 4) uniform sampler pos_smp;
layout(binding=0) uniform post_process_config { layout(binding=0) uniform post_process_config {
float exposure; float exposure;
@ -39,6 +43,14 @@ layout(binding=0) uniform post_process_config {
float bloom_amount; float bloom_amount;
}; };
layout(binding=1) uniform dof_config {
float dof_min;
float dof_max;
float dof_point;
float dof_tex_width;
float dof_tex_height;
};
vec3 aces(vec3 x) { vec3 aces(vec3 x) {
const float a = 2.51; const float a = 2.51;
const float b = 0.03; const float b = 0.03;
@ -69,6 +81,35 @@ float bayer8(vec2 pos) {
return (float(bayer[index]) / 64.0) - 0.5; return (float(bayer[index]) / 64.0) - 0.5;
} }
vec3 texture_bicubic(texture2D tex, sampler smp, vec2 uv, vec2 tex_size) {
vec2 pixel = uv * tex_size - 0.5;
vec2 f = fract(pixel);
vec2 pixel_floor = (floor(pixel) + 0.5) / tex_size;
vec2 w0 = f * (-0.5 + f * (1.0 - 0.5 * f));
vec2 w1 = 1.0 + f * f * (-2.5 + 1.5 * f);
vec2 w2 = f * (0.5 + f * (2.0 - 1.5 * f));
vec2 w3 = f * f * (-0.5 + 0.5 * f);
vec2 w12 = w1 + w2;
vec2 offset0 = -1.0 / tex_size;
vec2 offset12 = (w2 / w12) / tex_size;
vec2 offset3 = 2.0 / tex_size;
vec3 result =
texture(sampler2D(tex, smp), pixel_floor + vec2(offset0.x, offset0.y)).rgb * w0.x * w0.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset12.x, offset0.y)).rgb * w12.x * w0.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset3.x, offset0.y)).rgb * w3.x * w0.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset0.x, offset12.y)).rgb * w0.x * w12.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset12.x, offset12.y)).rgb * w12.x * w12.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset3.x, offset12.y)).rgb * w3.x * w12.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset0.x, offset3.y)).rgb * w0.x * w3.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset12.x, offset3.y)).rgb * w12.x * w3.y +
texture(sampler2D(tex, smp), pixel_floor + vec2(offset3.x, offset3.y)).rgb * w3.x * w3.y;
return result;
}
void main() { void main() {
vec2 distorted_texcoord = texcoord; vec2 distorted_texcoord = texcoord;
float barrel_dist = length(texcoord - 0.5); float barrel_dist = length(texcoord - 0.5);
@ -86,7 +127,12 @@ void main() {
float r = texture(sampler2D(pptex, ppsmp), distorted_texcoord + vec2(chromatic_aberration_intensity, 0.0)).r; float r = texture(sampler2D(pptex, ppsmp), distorted_texcoord + vec2(chromatic_aberration_intensity, 0.0)).r;
float g = texture(sampler2D(pptex, ppsmp), distorted_texcoord).g; float g = texture(sampler2D(pptex, ppsmp), distorted_texcoord).g;
float b = texture(sampler2D(pptex, ppsmp), distorted_texcoord - vec2(chromatic_aberration_intensity, 0.0)).b; float b = texture(sampler2D(pptex, ppsmp), distorted_texcoord - vec2(chromatic_aberration_intensity, 0.0)).b;
vec3 sampled_color_hdr = vec4(r, g, b, 1.0).rgb;
vec3 out_focus = texture_bicubic(dof_tex, dof_smp, distorted_texcoord, vec2(dof_tex_width, dof_tex_height)).xyz;
vec3 in_focus = vec3(r, g, b);
vec4 position = texture(sampler2D(pos_buf, dof_smp), distorted_texcoord);
float blur = smoothstep(dof_min, dof_max, abs(position.z + dof_point));
vec3 sampled_color_hdr = mix(in_focus, out_focus, blur);
vec3 bloom_color = texture(sampler2D(bloom_tex, bloom_smp), distorted_texcoord).rgb; vec3 bloom_color = texture(sampler2D(bloom_tex, bloom_smp), distorted_texcoord).rgb;
vec3 color_hdr = (sampled_color_hdr + bloom_color * bloom_amount) * exposure; vec3 color_hdr = (sampled_color_hdr + bloom_color * bloom_amount) * exposure;

View File

@ -340,7 +340,7 @@ vec3 hsv2rgb(vec3 c) {
void main() { void main() {
if (vpos.y < planeHeight - 0.01 && is_reflection == 1) discard; if (vpos.y < planeHeight - 0.01 && is_reflection == 1) discard;
Get trixel material. // Get trixel material.
vec3 sample_pos = ipos - orig_normal * 0.02; vec3 sample_pos = ipos - orig_normal * 0.02;
vec4 trixel_material; vec4 trixel_material;
int maxSteps = is_reflection == 1 ? 1 : 3; int maxSteps = is_reflection == 1 ? 1 : 3;
@ -355,12 +355,12 @@ void main() {
sample_pos += to_center * 0.1; sample_pos += to_center * 0.1;
} }
vec3 albedo = vec3(1.0, 1.0, 1.0); vec3 albedo = trixel_material.xyz;
int packed = int(round(trixel_material.w * 255.0)); int packed = int(round(trixel_material.w * 255.0));
float emittance = 0.0; float emittance = 0.0;
int roughnessInt = 7; int roughnessInt = 0;
float roughness = 1.0; float roughness = 0.0;
float metallic = 0.0; float metallic = 0.0;
if ((packed & 0x1) != 0) { if ((packed & 0x1) != 0) {
@ -418,7 +418,7 @@ void main() {
vec3 emissive = albedo * emittance * emissive_scale; vec3 emissive = albedo * emittance * emissive_scale;
if (rdm_enabled == 100 && atlas_rect.z > 0.0) { if (rdm_enabled == 1 && atlas_rect.z > 0.0) {
vec3 Frough = FresnelSchlickRoughness(NdotV, F0, roughness); vec3 Frough = FresnelSchlickRoughness(NdotV, F0, roughness);
vec3 hemispherePos = trileCenter + N * 0.49; vec3 hemispherePos = trileCenter + N * 0.49;
vec3 diff = vpos - hemispherePos; vec3 diff = vpos - hemispherePos;