Post processing tunables; Remove webgl1 matrix inverse

main
Phillip Trudeau-Tavara 8 months ago
parent b925dd70fe
commit 2fdddcd677

@ -3459,7 +3459,7 @@ void init(void)
// .mipmap_filter = SG_FILTER_LINEAR,
.wrap_u = SG_WRAP_CLAMP_TO_EDGE,
.wrap_v = SG_WRAP_CLAMP_TO_EDGE,
// .max_anisotropy = 16,
.max_anisotropy = 16,
.label = "sampler-linear",
});
@ -3469,6 +3469,7 @@ void init(void)
.wrap_u = SG_WRAP_CLAMP_TO_BORDER,
.wrap_v = SG_WRAP_CLAMP_TO_BORDER,
.border_color = SG_BORDERCOLOR_OPAQUE_WHITE,
.max_anisotropy = 16,
.label = "sampler-linear-border",
});

@ -5,58 +5,13 @@
@ctype vec3 Vec3
@ctype vec2 Vec2
@block inverse_functions
// Webgl 1 doesn't have inverse() but we need it, pulled from https://github.com/glslify/glsl-inverse/blob/master/index.glsl
mat4 my_inverse(mat4 m) {
float
a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3],
a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3],
a20 = m[2][0], a21 = m[2][1], a22 = m[2][2], a23 = m[2][3],
a30 = m[3][0], a31 = m[3][1], a32 = m[3][2], a33 = m[3][3],
b00 = a00 * a11 - a01 * a10,
b01 = a00 * a12 - a02 * a10,
b02 = a00 * a13 - a03 * a10,
b03 = a01 * a12 - a02 * a11,
b04 = a01 * a13 - a03 * a11,
b05 = a02 * a13 - a03 * a12,
b06 = a20 * a31 - a21 * a30,
b07 = a20 * a32 - a22 * a30,
b08 = a20 * a33 - a23 * a30,
b09 = a21 * a32 - a22 * a31,
b10 = a21 * a33 - a23 * a31,
b11 = a22 * a33 - a23 * a32,
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
return mat4(
a11 * b11 - a12 * b10 + a13 * b09,
a02 * b10 - a01 * b11 - a03 * b09,
a31 * b05 - a32 * b04 + a33 * b03,
a22 * b04 - a21 * b05 - a23 * b03,
a12 * b08 - a10 * b11 - a13 * b07,
a00 * b11 - a02 * b08 + a03 * b07,
a32 * b02 - a30 * b05 - a33 * b01,
a20 * b05 - a22 * b02 + a23 * b01,
a10 * b10 - a11 * b08 + a13 * b06,
a01 * b08 - a00 * b10 - a03 * b06,
a30 * b04 - a31 * b02 + a33 * b00,
a21 * b02 - a20 * b04 - a23 * b00,
a11 * b07 - a10 * b09 - a12 * b06,
a00 * b09 - a01 * b07 + a02 * b06,
a31 * b01 - a30 * b03 - a32 * b00,
a20 * b03 - a21 * b01 + a22 * b00) / det;
}
@end
// for this block, define a variable called `model_space_pos` to be used as an input
@block vs_compute_light_output
world_space_frag_pos = model * vec4(model_space_pos, 1.0);
vec4 frag_pos = view * world_space_frag_pos;
//@Speed I think we can just take the third row here and be fine.
light_dir = normalize(my_inverse(directional_light_space_matrix) * vec4(0.0, 0.0, -1.0, 0.0)).xyz;
light_dir = normalize(inverse(directional_light_space_matrix) * vec4(0.0, 0.0, -1.0, 0.0)).xyz;
light_space_fragment_position = directional_light_space_matrix * vec4(world_space_frag_pos.xyz, 1.0);
@ -92,8 +47,6 @@ float decode_normalized_float32(vec4 v)
return sign * (v.z*255.0 + v.y);
}
@include_block inverse_functions
void main() {
vec4 total_position = vec4(0.0f);
@ -151,8 +104,6 @@ uniform vs_params {
vec3 wobble_world_source;
};
@include_block inverse_functions
void main() {
//vec3 transformed_pos = vec3(pos_in.x, pos_in.y + sin(pos_in.x * 5.0 + pos_in.y * 9.0 + time*1.9)*0.045, pos_in.z);
@ -498,6 +449,8 @@ vec3 acesFilm(const vec3 x) {
return clamp((x * (a * x + b)) / (x * (c * x + d ) + e), 0.0, 1.0);
}
@include tuning.h
void main() {
// clip space is from [-1,1] [left, right]of screen on X, and [-1,1] [bottom, top] of screen on Y
if(pos.x < clip_ul.x || pos.x > clip_lr.x || pos.y < clip_lr.y || pos.y > clip_ul.y) discard;
@ -510,23 +463,36 @@ void main() {
col.rgb = acesFilm(col.rgb);
// Film grain
vec2 grain_uv = gl_FragCoord.xy / screen_size.xy;
float x = grain_uv.x * grain_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);
#if (FILM_GRAIN_STRENGTH > 0)
{ // Film grain
vec2 grain_uv = gl_FragCoord.xy / screen_size.xy;
float x = grain_uv.x * grain_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) * (FILM_GRAIN_STRENGTH * 0.01);
col.rgb *= (1 - FILM_GRAIN_STRENGTH * 0.01);
}
#endif
#if (CONTRAST_BOOST_MIN > 0 || CONTRAST_BOOST_MAX < 255)
{ // Hard-clip contrast levels
float min = CONTRAST_BOOST_MIN;
float max = CONTRAST_BOOST_MAX;
col.rgb -= min/255;
col.rgb *= 255/(max-min);
}
#endif
#if (VIGNETTE_STRENGTH > 0)
{ // Vignette
col.rgb *= clamp((2 - VIGNETTE_STRENGTH * 0.01) - length(gl_FragCoord.xy / screen_size.xy - vec2(0.5)), 0, 1);
}
#endif
#if (CROSS_PROCESS_STRENGTH > 0)
{ // Cross-process
float cross_process_strength = CROSS_PROCESS_STRENGTH * 0.01;
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));
}
#endif
// col.rgb = clamp(col.rgb, 0, 1);
frag_color = col;
}

@ -1,4 +1,5 @@
#pragma once
#ifndef TUNING_H // #pragma once isn't supported by sokol-shdc yet
#define TUNING_H
#define LEVEL_TILES 150 // width and height of level tiles array
#define LAYERS 3
@ -71,3 +72,20 @@
#define NEAR_PLANE_DISTANCE (0.01f)
#define FAR_PLANE_DISTANCE (45.0f)
#define SHADOW_MAP_DIMENSION (2048)
// Post-processing
#if 0 // use this to completely disable
#define FILM_GRAIN_STRENGTH 0 // 0 to 100
#define CONTRAST_BOOST_MIN 0 // 0 to 255
#define CONTRAST_BOOST_MAX 255 // 0 to 255
#define VIGNETTE_STRENGTH 0 // 0 to 100
#define CROSS_PROCESS_STRENGTH 0 // 0 to 100
#else
#define FILM_GRAIN_STRENGTH 0 // 0 to 100
#define CONTRAST_BOOST_MIN 11 // 0 to 255
#define CONTRAST_BOOST_MAX 204 // 0 to 255
#define VIGNETTE_STRENGTH 50 // 0 to 100
#define CROSS_PROCESS_STRENGTH 50 // 0 to 100
#endif
#endif // TUNING_H

Loading…
Cancel
Save