diff --git a/bgfx/chains/hlsl.json b/bgfx/chains/hlsl.json index 985a332ed9d..2b730966a47 100644 --- a/bgfx/chains/hlsl.json +++ b/bgfx/chains/hlsl.json @@ -9,11 +9,11 @@ // name (unused): This value should contain a suitable name for the screen chain. It is not read by MAME, though it is still suggested that it be put in any user-made chains. // type: string "name": "Classic D3D HLSL CRT Simulation", - + // author (unused): This value should contain a suitable name for this chain's author. Again, it is not read by MAME, but it is still advisable to have. // type: string "author": "Ryan Holtz & ImJezze", - + // sliders (optional): The list of sliders used by all of the entries in this chain. Can be omitted if no entries use any sliders. "sliders": [ // type (required): The sliders's conceptual type. Is it a list of string selections? Is it a single floating-point value? Does it require RGB values, or XY values? @@ -54,7 +54,7 @@ // // strings (optional): A list of strings to use with the "intenum" type, to select from a list of text options instead of simply numbers. // value: An array of 2 or more entries, with one entry per possible slider setting from "min" to "max" inclusive. - + { "type": "intenum", "name": "adjustments", "text": "Enable Adjustments", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "Off", "On" ] }, { "type": "intenum", "name": "ntsc", "text": "Enable NTSC", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "Off", "On" ] }, @@ -80,7 +80,7 @@ { "type": "vec2", "name": "converge_red", "text": "Red Convergence, ", "default": [ 5, 0 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, { "type": "vec2", "name": "converge_green", "text": "Green Convergence, ", "default": [ 0, 5 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, { "type": "vec2", "name": "converge_blue", "text": "Blue Convergence, ", "default": [ 0, 0 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, - + { "type": "vec2", "name": "radial_converge_red", "text": "Red Radial Convergence, ", "default": [ 0, 0 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, { "type": "vec2", "name": "radial_converge_green", "text": "Green Radial Convergence, ", "default": [ 0, 0 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, { "type": "vec2", "name": "radial_converge_blue", "text": "Blue Radial Convergence, ", "default": [ 0, 0 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, @@ -96,22 +96,27 @@ { "type": "float", "name": "scanline_jitter_amount", "text": "Scanline Jitter Amount", "default": 0, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "scanline_height", "text": "Individual Scanline Scale", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "scanline_variation", "text": "Scanline Variation", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "shadow_alpha", "text": "Shadow Mask Amount", "default": 20, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "vec2", "name": "shadow_uv_count", "text": "Shadow Mask Pixel Count ", "default": [ 12, 12 ], "max": [ 128, 128 ], "min": [ 1, 1 ], "step": 1, "scale": 1.0, "format": "%3f", "screen": "crt" }, { "type": "vec2", "name": "shadow_uv_size", "text": "Shadow Mask UV Size ", "default": [ 500, 500 ], "max": [ 1000, 1000 ], "min": [ 0, 0 ], "step": 1, "scale": 0.001, "format": "%1.4f", "screen": "crt" }, { "type": "vec2", "name": "shadow_uv_offset", "text": "Shadow Mask UV Offset ", "default": [ 0, 0 ], "max": [ 1000, 1000 ], "min": [ 0, 0 ], "step": 1, "scale": 0.001, "format": "%1.4f", "screen": "crt" }, + { "type": "float", "name": "humbar_alpha", "text": "Hum Bar Amount", "default": 5, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "humbar_hertz_rate", "text": "Hum Bar Frequency", "default": 100, "max": 10000, "min": 0, "step": 1, "scale": 0.00001, "format": "%1.7f", "screen": "crt" }, + { "type": "color", "name": "floor", "text": "Signal Floor, ", "default": [ 5, 5, 5 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "color", "name": "power", "text": "Signal Exponent, ", "default": [ 80, 80, 80 ], "max": [ 400, 400, 400 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - - { "type": "float", "name": "curvature", "text": "Screen Curvature Amount", "default": 20, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "round_corner", "text": "Rounded Corner Amount", "default": 15, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "smooth_border", "text": "Smooth Border Amount", "default": 5, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "vignetting", "text": "Vignetting Amount", "default": 20, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "reflection", "text": "Reflection Amount", "default": 15, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" } + + { "type": "float", "name": "distortion", "text": "Screen Distortion Amount", "default": 20, "max": 200, "min": -200, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "cubic_distortion", "text": "Screen Cubic Distortion Amount", "default": 0, "max": 200, "min": -200, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "distort_corner", "text": "Distorted Corner Amount", "default": 20, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "round_corner", "text": "Rounded Corner Amount", "default": 15, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "smooth_border", "text": "Smooth Border Amount", "default": 5, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "vignetting", "text": "Vignetting Amount", "default": 20, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "reflection", "text": "Reflection Amount", "default": 15, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" } ], - + // parameters (optional): A list of procedurally-generated parameters that can be bound to entry uniforms. "parameters": [ // name (required): The internal name of the parameter that will be used when binding to an entry uniform. @@ -128,11 +133,11 @@ // // limit (required by type "time"): The range of time across which to loop. 0.0 means run indefinitely. // value: Any numeric value. - + { "name": "jitter", "type": "frame", "period": 2 }, { "name": "time", "type": "time", "limit": 0.0 } ], - + // targets (optional): A list of all render targets that will be used by the chain entries in this chain. "targets": [ // name (required): The name of the target. Will be used to bind it as a texture and as an output in chain entries. @@ -177,7 +182,7 @@ "doublebuffer": true } ], - + // passes (required): The list of individual shaders to invoke, and any dynamic input parameters they need. "passes": [ { @@ -194,7 +199,7 @@ // clearcolor (optional): An array containing an RGBA quadruplet to which to clear the output target. // value: An array of four numeric values of the range 0.0 to 1.0. "clearcolor": [ 0.0, 0.0, 0.0, 0.0 ], - + // cleardepth (optional): A numeric value containing the depth value to which to clear the output target. // value: Any numeric value. "cleardepth": 1.0, @@ -231,7 +236,7 @@ { "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 }, { "type": "slider", "condition": "equal", "combine": "or", "name": "ntsc", "value": 0 } ], - + // uniforms (optional): Non-sampler uniform bindings for this chain entry. "uniforms": [ // uniform (required): The name of the uniform, as it is referenced in the shader source code itself. @@ -247,7 +252,7 @@ // // value (optional): An array of numeric values that should be loaded into this uniform. // values: Should be an array containing anywhere from 1-16 numeric values, corresponding to the size of the uniform's type. - + { "uniform": "u_a_value", "slider": "a_value" }, { "uniform": "u_b_value", "slider": "b_value" }, { "uniform": "u_cc_value", "slider": "cc_value" }, @@ -256,7 +261,7 @@ { "uniform": "u_jitter_offset", "slider": "jitter_offset" }, { "uniform": "u_jitter_amount", "parameter": "jitter" } ], - + // inputs (optional): A list of samplers used by this entry, and their corresponding bindings. "input": [ // sampler (required): The name of the sampler, as it is referenced in the shader source code itself. @@ -278,7 +283,7 @@ // default: true { "sampler": "s_tex", "texture": "screen" } ], - + // output (required): The target to use as the output for this pass. Can be one of the named targets in "targets", or "output" // or "previous" for one of two automatically-generated targets. // value: Any valid ASCII string that names a target. @@ -468,19 +473,23 @@ { "effect": "hlsl/distortion", "name": "Distortion Pass", "disablewhen": [ - { "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "curvature", "value": 0.0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "round_corner", "value": 0.0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "smooth_border", "value": 0.0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "vignetting", "value": 0.0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "reflection", "value": 0.0 } + { "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "distortion", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "cubic_distortion", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "distort_corner", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "round_corner", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "smooth_border", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "vignetting", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "reflection", "value": 0.0 } ], "uniforms": [ - { "uniform": "u_curvature", "slider": "curvature" }, - { "uniform": "u_round_corner", "slider": "round_corner" }, - { "uniform": "u_smooth_border", "slider": "smooth_border" }, - { "uniform": "u_vignetting", "slider": "vignetting" }, - { "uniform": "u_reflection", "slider": "reflection" } + { "uniform": "u_distortion", "slider": "distortion" }, + { "uniform": "u_cubic_distortion", "slider": "cubic_distortion" }, + { "uniform": "u_distort_corner", "slider": "distort_corner" }, + { "uniform": "u_round_corner", "slider": "round_corner" }, + { "uniform": "u_smooth_border", "slider": "smooth_border" }, + { "uniform": "u_vignetting", "slider": "vignetting" }, + { "uniform": "u_reflection", "slider": "reflection" } ], "input": [ { "sampler": "s_tex", "target": "internal" } diff --git a/bgfx/effects/hlsl/distortion.json b/bgfx/effects/hlsl/distortion.json index 42a43d95c65..14a7b79891a 100644 --- a/bgfx/effects/hlsl/distortion.json +++ b/bgfx/effects/hlsl/distortion.json @@ -25,16 +25,17 @@ "vertex": "chains/hlsl/vs_distortion", "fragment": "chains/hlsl/fs_distortion", "uniforms": [ - { "name": "s_tex", "type": "int", "values": [ 0.0 ] }, - { "name": "u_swap_xy", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }, - { "name": "u_screen_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] }, - { "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] }, - { "name": "u_rotation_type", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }, - { "name": "u_prepare_vector", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }, - { "name": "u_curvature", "type": "vec4", "values": [ 0.25, 0.0, 0.0, 0.0 ] }, - { "name": "u_round_corner", "type": "vec4", "values": [ 0.2, 0.0, 0.0, 0.0 ] }, - { "name": "u_smooth_border", "type": "vec4", "values": [ 0.05, 0.0, 0.0, 0.0 ] }, - { "name": "u_vignetting", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] }, - { "name": "u_reflection", "type": "vec4", "values": [ 0.30, 0.0, 0.0, 0.0 ] } + { "name": "s_tex", "type": "int", "values": [ 0.0 ] }, + { "name": "u_swap_xy", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }, + { "name": "u_screen_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] }, + { "name": "u_target_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] }, + { "name": "u_quad_dims", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] }, + { "name": "u_distortion", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] }, + { "name": "u_cubic_distortion", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] }, + { "name": "u_distort_corner", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] }, + { "name": "u_round_corner", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] }, + { "name": "u_smooth_border", "type": "vec4", "values": [ 0.05, 0.0, 0.0, 0.0 ] }, + { "name": "u_vignetting", "type": "vec4", "values": [ 0.20, 0.0, 0.0, 0.0 ] }, + { "name": "u_reflection", "type": "vec4", "values": [ 0.30, 0.0, 0.0, 0.0 ] } ] } \ No newline at end of file diff --git a/bgfx/shaders/dx11/chains/hlsl/fs_distortion.bin b/bgfx/shaders/dx11/chains/hlsl/fs_distortion.bin index d5f7f3b16e2..2e2b1813c8a 100644 Binary files a/bgfx/shaders/dx11/chains/hlsl/fs_distortion.bin and b/bgfx/shaders/dx11/chains/hlsl/fs_distortion.bin differ diff --git a/bgfx/shaders/dx9/chains/hlsl/fs_distortion.bin b/bgfx/shaders/dx9/chains/hlsl/fs_distortion.bin index 8ee4383d303..b12b9d953cf 100644 Binary files a/bgfx/shaders/dx9/chains/hlsl/fs_distortion.bin and b/bgfx/shaders/dx9/chains/hlsl/fs_distortion.bin differ diff --git a/bgfx/shaders/gles/chains/hlsl/fs_distortion.bin b/bgfx/shaders/gles/chains/hlsl/fs_distortion.bin index b3066b53170..189ca2e97f5 100644 Binary files a/bgfx/shaders/gles/chains/hlsl/fs_distortion.bin and b/bgfx/shaders/gles/chains/hlsl/fs_distortion.bin differ diff --git a/bgfx/shaders/glsl/chains/hlsl/fs_distortion.bin b/bgfx/shaders/glsl/chains/hlsl/fs_distortion.bin index b69a3712bb9..a4d54c9c932 100644 Binary files a/bgfx/shaders/glsl/chains/hlsl/fs_distortion.bin and b/bgfx/shaders/glsl/chains/hlsl/fs_distortion.bin differ diff --git a/bgfx/shaders/metal/chains/hlsl/fs_distortion.bin b/bgfx/shaders/metal/chains/hlsl/fs_distortion.bin index 512262b52a7..22a66b575d2 100644 Binary files a/bgfx/shaders/metal/chains/hlsl/fs_distortion.bin and b/bgfx/shaders/metal/chains/hlsl/fs_distortion.bin differ diff --git a/hlsl/distortion.fx b/hlsl/distortion.fx index f683397b17a..bd78efde8c5 100644 --- a/hlsl/distortion.fx +++ b/hlsl/distortion.fx @@ -212,7 +212,7 @@ float2 GetDistortedCoords(float2 centerCoord, float amount, float amountCube) : 1.0f + r2 * (k + kcube * sqrt(r2)); // fit screen bounds - f /= 1.0f + amount * 0.25 + amountCube * 0.125f; + f /= 1.0f + amount * 0.25f + amountCube * 0.125f; // apply cubic distortion factor centerCoord *= f; @@ -237,9 +237,9 @@ float2 GetCoords(float2 coord, float distortionAmount, float cubicDistortionAmou float4 ps_main(PS_INPUT Input) : COLOR { float distortionAmount = DistortionAmount; - float cubicDistortionAmount = CubicDistortionAmount > 0 - ? CubicDistortionAmount * 1.1 // cubic distortion need to be a little higher to compensate the quartic distortion - : CubicDistortionAmount * 1.2; // negativ values even more + float cubicDistortionAmount = CubicDistortionAmount > 0.0f + ? CubicDistortionAmount * 1.1f // cubic distortion need to be a little higher to compensate the quartic distortion + : CubicDistortionAmount * 1.2f; // negativ values even more float2 TexelDims = 1.0f / TargetDims; diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp index c30139e17c4..156bc435f09 100644 --- a/src/osd/modules/render/bgfx/chainentry.cpp +++ b/src/osd/modules/render/bgfx/chainentry.cpp @@ -122,6 +122,20 @@ void bgfx_chain_entry::setup_sourcesize_uniform(render_primitive* prim) const } } +void bgfx_chain_entry::setup_targetsize_uniform(int32_t screen) const +{ + bgfx_uniform* target_dims = m_effect->uniform("u_target_dims"); + if (target_dims != nullptr) + { + bgfx_target* output = m_targets.target(screen, m_output); + if (output != nullptr) + { + float values[2] = { float(output->width()), float(output->height()) }; + target_dims->set(values, sizeof(float) * 2); + } + } +} + void bgfx_chain_entry::setup_rotationtype_uniform(uint32_t rotation_type) const { bgfx_uniform* rotation_type_uniform = m_effect->uniform("u_rotation_type"); @@ -166,6 +180,7 @@ void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manag { setup_screensize_uniforms(textures, screen_width, screen_height, screen); setup_sourcesize_uniform(prim); + setup_targetsize_uniform(screen); setup_rotationtype_uniform(rotation_type); setup_swapxy_uniform(swap_xy); setup_quaddims_uniform(prim); diff --git a/src/osd/modules/render/bgfx/chainentry.h b/src/osd/modules/render/bgfx/chainentry.h index eb102aaa059..e9e5112bf1b 100644 --- a/src/osd/modules/render/bgfx/chainentry.h +++ b/src/osd/modules/render/bgfx/chainentry.h @@ -47,6 +47,7 @@ private: void setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, int32_t screen); void setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height, int32_t screen); void setup_sourcesize_uniform(render_primitive* prim) const; + void setup_targetsize_uniform(int32_t screen) const; void setup_rotationtype_uniform(uint32_t rotation_type) const; void setup_swapxy_uniform(bool swap_xy) const; void setup_quaddims_uniform(render_primitive* prim) const; diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc index 1547324f894..d7e1acf8494 100644 --- a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_distortion.sc @@ -11,12 +11,13 @@ $input v_color0, v_texcoord0 // Autos uniform vec4 u_swap_xy; uniform vec4 u_screen_dims; +uniform vec4 u_target_dims; uniform vec4 u_quad_dims; -uniform vec4 u_rotation_type; // User-supplied -uniform vec4 u_prepare_vector; -uniform vec4 u_curvature; +uniform vec4 u_distortion; +uniform vec4 u_cubic_distortion; +uniform vec4 u_distort_corner; uniform vec4 u_round_corner; uniform vec4 u_smooth_border; uniform vec4 u_vignetting; @@ -72,36 +73,15 @@ float GetVignetteFactor(vec2 coord, float amount) float GetSpotAddend(vec2 coord, float amount) { vec2 SpotCoord = coord; - - // hack for vector screen - if (u_prepare_vector.x > 0.0) - { - // upper right quadrant - vec2 spotOffset = vec2(-0.25, 0.25); // 0 degrees - if (u_rotation_type.x == 1.0) - spotOffset = vec2(-0.25, -0.25); // 90 degrees - if (u_rotation_type.x == 2.0) - spotOffset = vec2(0.25, -0.25); // 180 degrees - if (u_rotation_type.x == 3.0) - spotOffset = vec2(0.25, 0.25); // 270 degrees - - // normalized screen canvas ratio - vec2 CanvasRatio = ((u_swap_xy.x > 0.0) ? vec2(u_quad_dims.x / u_quad_dims.y, 1.0) : vec2(1.0, u_quad_dims.y / u_quad_dims.x)); - - SpotCoord += spotOffset; - SpotCoord *= CanvasRatio; - } - else - { - // upper right quadrant - vec2 spotOffset = vec2(-0.25, 0.25); - // normalized screen canvas ratio - vec2 CanvasRatio = ((u_swap_xy.x > 0.0) ? vec2(1.0, u_quad_dims.x / u_quad_dims.y) : vec2(1.0, u_quad_dims.y / u_quad_dims.x)); - - SpotCoord += spotOffset; - SpotCoord *= CanvasRatio; - } + // upper right quadrant + vec2 spotOffset = vec2(-0.25, 0.25); + + // normalized screen canvas ratio + vec2 CanvasRatio = ((u_swap_xy.x > 0.0) ? vec2(1.0, u_quad_dims.x / u_quad_dims.y) : vec2(1.0, u_quad_dims.y / u_quad_dims.x)); + + SpotCoord += spotOffset; + SpotCoord *= CanvasRatio; float SpotBlur = amount; @@ -122,7 +102,7 @@ float GetRoundCornerFactor(vec2 coord, float radiusAmount, float smoothAmount) // reduce smooth amount down to radius amount smoothAmount = min(smoothAmount, radiusAmount); - vec2 quadDims = (u_prepare_vector.x > 0.0 && u_swap_xy.x > 0.0) ? u_quad_dims.yx : u_quad_dims.xy; + vec2 quadDims = (u_swap_xy.x > 0.0) ? u_quad_dims.yx : u_quad_dims.xy; float range = min(quadDims.x, quadDims.y) * 0.5; float radius = range * max(radiusAmount, 0.0025); @@ -141,20 +121,20 @@ float GetRoundCornerFactor(vec2 coord, float radiusAmount, float smoothAmount) } // www.francois-tarlier.com/blog/cubic-lens-distortion-shader/ -vec2 GetDistortedCoords(vec2 centerCoord, float amount) +vec2 GetDistortedCoords(vec2 centerCoord, float amount, float amountCube) { // lens distortion coefficient float k = amount; // cubic distortion value - float kcube = amount * 2.0; + float kcube = amountCube; // compute cubic distortion factor float r2 = centerCoord.x * centerCoord.x + centerCoord.y * centerCoord.y; float f = kcube == 0.0 ? 1.0 + r2 * k : 1.0 + r2 * (k + kcube * sqrt(r2)); // fit screen bounds - f /= 1.0 + amount * 0.5; + f /= 1.0 + amount * 0.25 + amountCube * 0.125; // apply cubic distortion factor centerCoord *= f; @@ -162,13 +142,13 @@ vec2 GetDistortedCoords(vec2 centerCoord, float amount) return centerCoord; } -vec2 GetCoords(vec2 coord, float distortionAmount) +vec2 GetCoords(vec2 coord, float distortionAmount, float cubicDistortionAmount) { // center coordinates coord -= 0.5; // distort coordinates - coord = GetDistortedCoords(coord, distortionAmount); + coord = GetDistortedCoords(coord, distortionAmount, cubicDistortionAmount); // un-center coordinates coord += 0.5; @@ -180,24 +160,36 @@ vec2 GetCoords(vec2 coord, float distortionAmount) void main() { + float distortionAmount = u_distortion.x; + float cubicDistortionAmount = u_cubic_distortion.x > 0.0 + ? u_cubic_distortion.x * 1.1 // cubic distortion need to be a little higher to compensate the quartic distortion + : u_cubic_distortion.x * 1.2; // negativ values even more + + vec2 TexelDims = vec2(1.0 / u_target_dims.x, 1.0 / u_target_dims.y); + // Screen Curvature - vec2 BaseCoord = GetCoords(v_texcoord0, u_curvature.x * 0.25); // reduced amount + vec2 BaseCoord = GetCoords(v_texcoord0, distortionAmount, cubicDistortionAmount); + + // Corner Curvature + vec2 CornerCoord = GetCoords(v_texcoord0, u_distort_corner.x, 0.0); vec2 BaseCoordCentered = BaseCoord; BaseCoordCentered -= 0.5; + vec2 CornerCoordCentered = CornerCoord; + CornerCoordCentered -= 0.5; // Color vec4 BaseColor = texture2D(s_tex, BaseCoord); // Clamp - if (BaseCoord.x > 1.0 || BaseCoord.y > 1.0 || BaseCoord.x < 0.0 || BaseCoord.y < 0.0) + if (BaseCoord.x > 1.0 + TexelDims.x || BaseCoord.y > 1.0 + TexelDims.y || BaseCoord.x < 0.0 - TexelDims.x || BaseCoord.y < 0.0 - TexelDims.y) { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); } else { // Vignetting Simulation - vec2 VignetteCoord = BaseCoordCentered; + vec2 VignetteCoord = CornerCoordCentered; float VignetteFactor = GetVignetteFactor(VignetteCoord, u_vignetting.x); BaseColor.rgb *= VignetteFactor; @@ -205,15 +197,15 @@ void main() // Light Reflection Simulation vec4 LightColor = vec4(1.0, 0.90, 0.80, 1.0); // color temperature 5.000 Kelvin - vec2 SpotCoord = BaseCoordCentered; - vec2 NoiseCoord = BaseCoordCentered; + vec2 SpotCoord = CornerCoordCentered; + vec2 NoiseCoord = CornerCoordCentered; float SpotAddend = GetSpotAddend(SpotCoord, u_reflection.x); float NoiseFactor = GetNoiseFactor(SpotAddend, rand(NoiseCoord)); BaseColor += SpotAddend * NoiseFactor * LightColor; // Round Corners Simulation - vec2 RoundCornerCoord = BaseCoordCentered; + vec2 RoundCornerCoord = CornerCoordCentered; float roundCornerFactor = GetRoundCornerFactor(RoundCornerCoord, u_round_corner.x, u_smooth_border.x); BaseColor.rgb *= roundCornerFactor;