Film grain, contrast, vignette, cross-processing

main
Phillip Trudeau-Tavara 1 year ago
parent 75345ae684
commit 08df997396

@ -3758,6 +3758,7 @@ void flush_quad_batch()
state.bind.fs.samplers[SLOT_threedee_fs_twodee_smp] = state.sampler_linear; // NOTE that this might get FUCKED if a custom pipeline is provided with more/less sampler slots!!!
sg_apply_bindings(&state.bind);
cur_batch_params.tex_size = img_size(cur_batch_image);
cur_batch_params.screen_size = screen_size();
sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_threedee_twodee_fs_params, &SG_RANGE(cur_batch_params));
cur_batch_params.tex_size = V2(0,0); // unsure if setting the tex_size to something nonzero fucks up the batching so I'm just resetting it back here
assert(cur_batch_data_index % FLOATS_PER_VERTEX == 0);
@ -7100,6 +7101,7 @@ ISANERROR("Don't know how to do this stuff on this platform.")
Vec2 *points = d.quad.points;
threedee_twodee_fs_params_t params = {
.tint = d.tint,
.time = (float)fmod(elapsed_time, 100),
};
params.alpha_clip_threshold = d.alpha_clip_threshold;
if (d.do_clipping)

@ -381,8 +381,10 @@ uniform twodee_fs_params {
vec2 clip_lr;
float alpha_clip_threshold;
float time;
vec2 tex_size;
vec2 screen_size;
};
in vec2 uv;
@ -414,8 +416,10 @@ uniform twodee_fs_params {
vec2 clip_lr;
float alpha_clip_threshold;
float time;
vec2 tex_size;
vec2 screen_size;
};
in vec2 uv;
@ -470,8 +474,10 @@ uniform twodee_fs_params {
vec2 clip_lr;
float alpha_clip_threshold;
float time;
vec2 tex_size;
vec2 screen_size;
};
in vec2 uv;
@ -496,6 +502,24 @@ void main() {
col.rgb = acesFilm(col.rgb);
// Film grain
vec2 uv = gl_FragCoord.xy / screen_size.xy;
float x = uv.x * uv.y * time * 24 + 100.0;
vec3 noise = vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01)) * 100.0;
col.rgb += (noise - 0.5) * 0.05;
col.rgb *= 0.95;
// Hard-clip contrast levels
float min = 11; float max = 204;
col.rgb -= min/255;
col.rgb *= 255/(max-min);
// Vignette
col.rgb *= clamp(1.5 - length(gl_FragCoord.xy / screen_size.xy - vec2(0.5)), 0, 1);
// Cross-process
float cross_process_strength = 0.5;
col.rg *= (col.rg * ((-cross_process_strength) * col.rg + (-1.5 * (-cross_process_strength))) + (0.5 * (-cross_process_strength) + 1));
col.b *= (col.b * ((+cross_process_strength) * col.b + (-1.5 * (+cross_process_strength))) + (0.5 * (+cross_process_strength) + 1));
col.rgb = clamp(col.rgb, 0, 1);
frag_color = col;
}
@end

Loading…
Cancel
Save