From b5a54b761c94c543ce950dee0bc4aa0610ba8cba Mon Sep 17 00:00:00 2001 From: "Westley M. Martinez" Date: Sun, 7 Oct 2018 08:42:30 -0700 Subject: [PATCH] HLSL Color Transforms and 3D LUT (#4043) * Remove broken scanline uniform from post_pass * Add 3D LUT to HLSL * Allow individual LUTs for screen and UI * WIP: Port 3D LUT to BGFX * Finish porting LUT to BGFX * Add individual phosphor color conversion for HLSL new file: hlsl/chroma.fx Shader for converting xyY3 to sRGB modified: hlsl/phosphor.fx Minor changes to emphasize idea that phosphors are color agnostic modified: hlsl/post.fx Conversion from signal RGB to xyY3 modified: src/osd/modules/render/d3d/d3dhlsl.cpp modified: src/osd/modules/render/d3d/d3dhlsl.h modified: src/osd/windows/winmain.cpp modified: src/osd/windows/winmain.h * Add phosphor examples and update presets * Port phosphor color shaders to BGFX * Fix missing newlines at EOF --- bgfx/chains/hlsl.json | 183 ++++++++++++------ bgfx/chains/lut.json | 36 ++++ bgfx/effects/hlsl/chroma.json | 33 ++++ bgfx/effects/hlsl/post.json | 6 +- bgfx/effects/misc/lut.json | 32 +++ bgfx/shaders/dx11/chains/hlsl/fs_chroma.bin | Bin 0 -> 1556 bytes bgfx/shaders/dx11/chains/hlsl/fs_post.bin | Bin 2411 -> 2635 bytes bgfx/shaders/dx11/chains/hlsl/vs_chroma.bin | Bin 0 -> 577 bytes bgfx/shaders/dx11/chains/misc/fs_lut.bin | Bin 0 -> 756 bytes bgfx/shaders/dx11/chains/misc/vs_lut.bin | Bin 0 -> 577 bytes bgfx/shaders/dx9/chains/hlsl/fs_chroma.bin | Bin 0 -> 1029 bytes bgfx/shaders/dx9/chains/hlsl/fs_post.bin | Bin 2112 -> 2368 bytes bgfx/shaders/dx9/chains/hlsl/vs_chroma.bin | Bin 0 -> 320 bytes bgfx/shaders/dx9/chains/misc/fs_lut.bin | Bin 0 -> 501 bytes bgfx/shaders/dx9/chains/misc/vs_lut.bin | Bin 0 -> 320 bytes bgfx/shaders/essl/chains/hlsl/fs_chroma.bin | Bin 0 -> 1693 bytes bgfx/shaders/essl/chains/hlsl/fs_post.bin | Bin 3516 -> 3987 bytes bgfx/shaders/essl/chains/hlsl/vs_chroma.bin | Bin 0 -> 419 bytes bgfx/shaders/essl/chains/misc/fs_lut.bin | Bin 0 -> 828 bytes bgfx/shaders/essl/chains/misc/vs_lut.bin | Bin 0 -> 419 bytes bgfx/shaders/glsl/chains/hlsl/fs_chroma.bin | Bin 0 -> 1612 bytes bgfx/shaders/glsl/chains/hlsl/fs_post.bin | Bin 3333 -> 3792 bytes bgfx/shaders/glsl/chains/hlsl/vs_chroma.bin | Bin 0 -> 377 bytes bgfx/shaders/glsl/chains/misc/fs_lut.bin | Bin 0 -> 786 bytes bgfx/shaders/glsl/chains/misc/vs_lut.bin | Bin 0 -> 377 bytes bgfx/shaders/metal/chains/hlsl/fs_chroma.bin | Bin 0 -> 2245 bytes bgfx/shaders/metal/chains/hlsl/fs_post.bin | Bin 4020 -> 4499 bytes bgfx/shaders/metal/chains/hlsl/vs_chroma.bin | Bin 0 -> 778 bytes bgfx/shaders/metal/chains/misc/fs_lut.bin | Bin 0 -> 1300 bytes bgfx/shaders/metal/chains/misc/vs_lut.bin | Bin 0 -> 778 bytes hlsl/chroma.fx | 122 ++++++++++++ hlsl/phosphor.fx | 39 ++-- hlsl/post.fx | 122 ++++++------ hlsl/primary.fx | 51 ++++- ini/examples/bt601-525.ini | 21 ++ ini/examples/bt601-625.ini | 21 ++ ini/examples/bt709.ini | 16 ++ ini/examples/ntscj.ini | 16 ++ ini/examples/p1.ini | 12 ++ ini/examples/p14.ini | 15 ++ ini/examples/p2.ini | 12 ++ ini/examples/p3.ini | 12 ++ ini/examples/p35.ini | 12 ++ ini/examples/p4.ini | 19 ++ ini/examples/p55.ini | 13 ++ ini/examples/p7.ini | 15 ++ ini/presets/raster.ini | 5 + ini/presets/vector-mono.ini | 4 + ini/presets/vector.ini | 5 + src/osd/modules/lib/osdobj_common.cpp | 1 + src/osd/modules/lib/osdobj_common.h | 2 + .../modules/render/bgfx/chainentryreader.cpp | 11 +- .../bgfx/shaders/chains/hlsl/fs_chroma.sc | 38 ++++ .../bgfx/shaders/chains/hlsl/fs_post.sc | 31 ++- .../bgfx/shaders/chains/hlsl/vs_chroma.sc | 14 ++ .../render/bgfx/shaders/chains/misc/fs_lut.sc | 29 +++ .../render/bgfx/shaders/chains/misc/vs_lut.sc | 14 ++ src/osd/modules/render/d3d/d3dhlsl.cpp | 177 +++++++++++++++-- src/osd/modules/render/d3d/d3dhlsl.h | 26 +++ src/osd/windows/winmain.cpp | 11 +- src/osd/windows/winmain.h | 20 ++ 61 files changed, 1025 insertions(+), 171 deletions(-) create mode 100644 bgfx/chains/lut.json create mode 100644 bgfx/effects/hlsl/chroma.json create mode 100644 bgfx/effects/misc/lut.json create mode 100644 bgfx/shaders/dx11/chains/hlsl/fs_chroma.bin create mode 100644 bgfx/shaders/dx11/chains/hlsl/vs_chroma.bin create mode 100644 bgfx/shaders/dx11/chains/misc/fs_lut.bin create mode 100644 bgfx/shaders/dx11/chains/misc/vs_lut.bin create mode 100644 bgfx/shaders/dx9/chains/hlsl/fs_chroma.bin create mode 100644 bgfx/shaders/dx9/chains/hlsl/vs_chroma.bin create mode 100644 bgfx/shaders/dx9/chains/misc/fs_lut.bin create mode 100644 bgfx/shaders/dx9/chains/misc/vs_lut.bin create mode 100644 bgfx/shaders/essl/chains/hlsl/fs_chroma.bin create mode 100644 bgfx/shaders/essl/chains/hlsl/vs_chroma.bin create mode 100644 bgfx/shaders/essl/chains/misc/fs_lut.bin create mode 100644 bgfx/shaders/essl/chains/misc/vs_lut.bin create mode 100644 bgfx/shaders/glsl/chains/hlsl/fs_chroma.bin create mode 100644 bgfx/shaders/glsl/chains/hlsl/vs_chroma.bin create mode 100644 bgfx/shaders/glsl/chains/misc/fs_lut.bin create mode 100644 bgfx/shaders/glsl/chains/misc/vs_lut.bin create mode 100644 bgfx/shaders/metal/chains/hlsl/fs_chroma.bin create mode 100644 bgfx/shaders/metal/chains/hlsl/vs_chroma.bin create mode 100644 bgfx/shaders/metal/chains/misc/fs_lut.bin create mode 100644 bgfx/shaders/metal/chains/misc/vs_lut.bin create mode 100644 hlsl/chroma.fx create mode 100644 ini/examples/bt601-525.ini create mode 100644 ini/examples/bt601-625.ini create mode 100644 ini/examples/bt709.ini create mode 100644 ini/examples/ntscj.ini create mode 100644 ini/examples/p1.ini create mode 100644 ini/examples/p14.ini create mode 100644 ini/examples/p2.ini create mode 100644 ini/examples/p3.ini create mode 100644 ini/examples/p35.ini create mode 100644 ini/examples/p4.ini create mode 100644 ini/examples/p55.ini create mode 100644 ini/examples/p7.ini create mode 100644 src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc create mode 100644 src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_chroma.sc create mode 100644 src/osd/modules/render/bgfx/shaders/chains/misc/fs_lut.sc create mode 100644 src/osd/modules/render/bgfx/shaders/chains/misc/vs_lut.sc diff --git a/bgfx/chains/hlsl.json b/bgfx/chains/hlsl.json index 378102444fe..ee76366efaa 100644 --- a/bgfx/chains/hlsl.json +++ b/bgfx/chains/hlsl.json @@ -21,13 +21,13 @@ "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? // values: "intenum", "int", "float", "vec2", "color" - // + // // name (required): The internal name of the slider, used to attach it to entry uniforms. // value: Any valid ASCII string. - // + // // text (required): The description of the slider, to which "X" or "Y" is appended for the "vec2" type, and to which "Red", "Green" or "Blue" will be appended for the "color" type. // value: Any valid user-understandable ASCII string. - // + // // default (required): The value that this slider should have upon creation. // type: Either a single integer value or an array of integer values corresponding to the size of the slider type: // "intenum": Single integer value @@ -35,23 +35,23 @@ // "float": Single integer value // "vec2": Array of two integer values // "color": Array of three integer values - // + // // max (required): The upper limit to which the slider can be adjusted by a user. // type: See type for "default" - // + // // min (required): The lower limit to which the slider can be adjusted by a user. // type: See type for "default" - // + // // step (required): How much does a single left/right adjustment adjust the slider? // type: Integer value - // + // // format (required): A C-style formatting string to use when displaying the slider's value. // type: Any standard C-style formatting string (%s, %d, %1.2f, and so on) - // + // // screen (required): The type of screens for which we should populate this slider [NOT YET IMPLEMENTED] // values: "none", "raster", "vector", "crt", "vectorraster", "lcd", "nonvector", "lcdraster", "lcdvector", "any", "all" // "crt", "nonvector", and "all" are provided as aliases for "vectorraster", "lcdraster", and "any" - // + // // 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. @@ -86,8 +86,6 @@ { "type": "vec2", "name": "defocus", "text": "Defocus, ", "default": [ 0.5, 0.5 ], "max": [ 2.0, 2.0 ], "min": [ 0.0, 0.0 ], "step": 0.1, "format": "%1.1f", "screen": "crt" }, - { "type": "color", "name": "phosphor", "text": "Phosphor Persistence, ", "default": [ 0.45, 0.45, 0.45 ], "max": [ 1.00, 1.00, 1.00 ], "min": [ 0.00, 0.00, 0.00 ], "step": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_alpha", "text": "Scanline Amount", "default": 0.50, "max": 1.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "scanline_scale", "text": "Overall Scanline Scale", "default": 1.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "scanline_height", "text": "Individual Scanline Scale", "default": 1.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" }, @@ -96,7 +94,7 @@ { "type": "float", "name": "scanline_bright_offset", "text": "Scanline Brightness Offset", "default": 1.50, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "scanline_jitter_amount", "text": "Scanline Jitter Amount", "default": 0.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "scanline_variation", "text": "Scanline Variation", "default": 1.00, "max": 4.00, "min": 0.0, "step": 0.01, "format": "%1.2f", "screen": "crt" }, - + { "type": "intenum", "name": "shadow_tile_mode", "text": "Shadow Mask Tile Mode", "default": 0, "max": 1, "min": 0, "step": 1, "format": "%s", "screen": "any", "strings": [ "Screen", "Source" ] }, { "type": "float", "name": "shadow_alpha", "text": "Shadow Mask Amount", "default": 0.50, "max": 1.00, "min": 0.00, "step": 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, "format": "%3f", "screen": "crt" }, @@ -109,29 +107,40 @@ { "type": "color", "name": "floor", "text": "Signal Floor, ", "default": [ 0.05, 0.05, 0.05 ], "max": [ 1.00, 1.00, 1.00 ], "min": [ 0.00, 0.00, 0.00 ], "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "color", "name": "power", "text": "Signal Exponent, ", "default": [ 1.00, 1.00, 1.00 ], "max": [ 4.00, 4.00, 4.00 ], "min": [ 0.00, 0.00, 0.00 ], "step": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "intenum", "name": "chroma_mode", "text": "Color Mode", "default": 3, "max": 3, "min": 1, "step": 1, "format": "%s", "screen": "any", "strings": [ " ", "Monochrome", "Dichrome", "Trichrome" ] }, + { "type": "color", "name": "chroma_conversion_gain", "text": "Chroma Conversion Gain, ", "default": [ 0.299, 0.587, 0.114 ], "max": [ 1.0, 1.0, 1.0 ], "min": [ 0.0, 0.0, 0.0 ], "step": 0.0001, "format": "%1.4f", "screen": "any" }, + { "type": "vec2", "name": "chroma_a", "text": "Phosphor A Chromaticity ", "default": [ 0.630, 0.340 ], "max": [ 1.0, 1.0 ], "min": [ 0.0, 0.0 ], "step": 0.001, "format": "%1.3f", "screen": "any" }, + { "type": "vec2", "name": "chroma_b", "text": "Phosphor B Chromaticity ", "default": [ 0.310, 0.595 ], "max": [ 1.0, 1.0 ], "min": [ 0.0, 0.0 ], "step": 0.001, "format": "%1.3f", "screen": "any" }, + { "type": "vec2", "name": "chroma_c", "text": "Phosphor C Chromaticity ", "default": [ 0.155, 0.070 ], "max": [ 1.0, 1.0 ], "min": [ 0.0, 0.0 ], "step": 0.001, "format": "%1.3f", "screen": "any" }, + { "type": "color", "name": "chroma_y_gain", "text": "Phosphor Gain, ", "default": [ 0.2124, 0.7011, 0.0866 ], "max": [ 1.0, 1.0, 1.0 ], "min": [ 0.0, 0.0, 0.0 ], "step": 0.0001, "format": "%1.4f", "screen": "any" }, + + { "type": "color", "name": "phosphor", "text": "Phosphor Persistence, ", "default": [ 0.45, 0.45, 0.45 ], "max": [ 1.00, 1.00, 1.00 ], "min": [ 0.00, 0.00, 0.00 ], "step": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "distortion", "text": "Quadric Distortion Amount", "default": 0.05, "max": 2.00, "min": -2.00, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "cubic_distortion", "text": "Cubic Distortion Amount", "default": 0.00, "max": 2.00, "min": -2.00, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "distort_corner", "text": "Distorted Corner Amount", "default": 0.05, "max": 2.00, "min": 0.00, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "round_corner", "text": "Rounded Corner Amount", "default": 0.05, "max": 2.00, "min": 0.00, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "smooth_border", "text": "Smooth Border Amount", "default": 0.03, "max": 2.00, "min": 0.00, "step": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "vignetting", "text": "Vignetting Amount", "default": 0.08, "max": 2.00, "min": 0.00, "step": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "reflection", "text": "Reflection Amount", "default": 0.05, "max": 2.00, "min": 0.00, "step": 0.01, "format": "%1.2f", "screen": "crt" } + { "type": "float", "name": "reflection", "text": "Reflection Amount", "default": 0.05, "max": 2.00, "min": 0.00, "step": 0.01, "format": "%1.2f", "screen": "crt" }, + + { "type": "intenum", "name": "lut_enable", "text": "3D LUT", "default": 0, "max": 1, "min": 0, "step": 1, "format": "%s", "screen": "any", "strings": [ "Off", "On" ] } ], // 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. // value: Any valid ASCII string. - // + // // type (required): The type of the parameter. // values: // "frame": Increment by 1 for each rendered frame. Limited to a given value range. Can be use for A/B field jitter and such. // "window": Contains the index of the window to which this screen belongs. // "time": The current time, in milliseconds. Can be limited to a given value range. - // + // // period (required by type "frame"): The range of frames across which to count. A value of 20 will make the value loop from 0-19. // value: Any integer value. - // + // // limit (required by type "time"): The range of time across which to loop. 0.0 means run indefinitely. // value: Any numeric value. @@ -143,21 +152,21 @@ "targets": [ // name (required): The name of the target. Will be used to bind it as a texture and as an output in chain entries. // value: Any valid ASCII string. - // + // // mode (required): The mode of the target. Can be used for different implicit and explicit sizing options. // values: // "guest": Use the size of the emulated screen that is being processed (e.g. 256x256 when running "targ") // "native": Use the size of the displayed screen inside the window that is being displayed (the same size as the window size, for single-screen games with no artwork) // "custom": Use a custom size. - // + // // bilinear (optional): Whether or not to apply bilinear filtering to this render target. // values: true, false // default: true - // + // // doublebuffer (optional): Whether or not this render target will be needed as a source texture. If you don't know what this means, omit it or set it to true. // values: true, false // default: true - // + // // scale (optional): Multiply the internal size of this render target by this amount. Certain effects benefit from operating at a higher internal resolution. If you're not sure, omit it. // values: Any integer value // default: 1 @@ -225,19 +234,19 @@ "disablewhen": [ // type (optional): Reserved for future expansion. Currently only "slider" is supported. // value: "slider" - // + // // condition (optional): The disabler is active when the named slider is either equal or not equal to the reference value. // values: "equal", "notequal" // default: "equal" - // + // // combine (optional): All "and" conditions are ANDed together, all "or" conditions are OR'd together, then these two // values are OR'd together to finally determine whether this pass should run or not. // values: "or", "and" // default: "or" - // + // // name (required): The name of the slider to use for this condition. // value: Any valid ASCII string. - // + // // value (required): The value against which we are comparing to determine whether this disabler is active. // type: Either a single integer value or an array of integer values corresponding to the size of the slider's type: // "intenum": Single integer value @@ -253,15 +262,15 @@ "uniforms": [ // uniform (required): The name of the uniform, as it is referenced in the shader source code itself. // value: Any valid ASCII string. - // + // // The remaining options can be one of either "slider", "parameter", or "value": - // + // // slider (optional): The name of the slider to bind to this uniform. // value: Any valid ASCII string that corresponds to the name of a slider. // // parameter (optional): The name of the dynamic parameter to bind to this uniform. // value: Any valid ASCII string that corresponds to the name of a parameter. - // + // // 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. @@ -278,28 +287,28 @@ "input": [ // sampler (required): The name of the sampler, as it is referenced in the shader source code itself. // value: Any valid ASCII string. - // + // // The remaining options can be one of either "texture", "target", or "option". - // + // // texture (optional): Either "screen" for the texture that MAME provided for this chain's screen, or the name of a texture file in the artwork directory. // value: Any valid ASCII string. - // + // // target (optioanl): Any target from the "targets" list, or "previous" or "output" for two native-sized automatically-generated targets. // value: Any valid ASCII string that names a target. - // + // // option (optional): The name of any MAME option, which will have its value fetched and used as the name of a PNG to load from the artwork directory. // value: Any valid MAME INI option name. - // + // // bilinear (optional, texture and target only): Whether to apply bilinear filtering to the sampler. // values: true, false // default: true - // + // // selection (optional, option and texture only): Determines the name of the selection and alowes to select other textures in the same directory as the specified texture file. // values: Any valid ASCII string. { "sampler": "s_tex", "target": "ntsc" } ], - // output (required): The target to use as the output for this pass. Can be one of the named targets in "targets", or "output" + // 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. "output": "ntsc" @@ -427,6 +436,36 @@ ], "output": "internal" }, + { "effect": "hlsl/post", + "name": "Non-Bloom Post Pass", + "disablewhen": [ + { "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "shadow_alpha", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "humbar_alpha", "value": 0.0 }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "floor", "value": [ 0, 0, 0 ] }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "power", "value": [ 0, 0, 0 ] }, + { "type": "slider", "condition": "equal", "combine": "and", "name": "chroma_mode", "value": 3 } + ], + "uniforms": [ + { "uniform": "u_shadow_tile_mode", "slider": "shadow_tile_mode" }, + { "uniform": "u_shadow_alpha", "slider": "shadow_alpha" }, + { "uniform": "u_shadow_count", "slider": "shadow_uv_count" }, + { "uniform": "u_shadow_uv", "slider": "shadow_uv_size" }, + { "uniform": "u_shadow_uv_offset", "slider": "shadow_uv_offset" }, + { "uniform": "u_humbar_alpha", "slider": "humbar_alpha" }, + { "uniform": "u_humbar_hertz_rate", "slider": "humbar_hertz_rate" }, + { "uniform": "u_floor", "slider": "floor" }, + { "uniform": "u_power", "slider": "power" }, + { "uniform": "u_chroma_mode", "slider": "chroma_mode" }, + { "uniform": "u_conversion_gain", "slider": "chroma_conversion_gain" }, + { "uniform": "u_time", "parameter": "time" } + ], + "input": [ + { "sampler": "s_tex", "target": "internal" }, + { "sampler": "s_shadow", "option": "bgfx_shadow_mask", "selection": "Shadow Mask" } + ], + "output": "internal" + }, { "effect": "hlsl/phosphor", "name": "Phosphor Decay", "disablewhen": [ @@ -459,32 +498,22 @@ ], "output": "previous" }, - { "effect": "hlsl/post", - "name": "Non-Bloom Post Pass", - "disablewhen": [ - { "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "shadow_alpha", "value": 0.0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "humbar_alpha", "value": 0.0 }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "floor", "value": [ 0, 0, 0 ] }, - { "type": "slider", "condition": "equal", "combine": "and", "name": "power", "value": [ 0, 0, 0 ] } - ], - "uniforms": [ - { "uniform": "u_shadow_tile_mode", "slider": "shadow_tile_mode" }, - { "uniform": "u_shadow_alpha", "slider": "shadow_alpha" }, - { "uniform": "u_shadow_count", "slider": "shadow_uv_count" }, - { "uniform": "u_shadow_uv", "slider": "shadow_uv_size" }, - { "uniform": "u_shadow_uv_offset", "slider": "shadow_uv_offset" }, - { "uniform": "u_humbar_alpha", "slider": "humbar_alpha" }, - { "uniform": "u_humbar_hertz_rate", "slider": "humbar_hertz_rate" }, - { "uniform": "u_floor", "slider": "floor" }, - { "uniform": "u_power", "slider": "power" }, - { "uniform": "u_time", "parameter": "time" } - ], - "input": [ - { "sampler": "s_tex", "target": "internal" }, - { "sampler": "s_shadow", "option": "bgfx_shadow_mask", "selection": "Shadow Mask" } - ], - "output": "internal" + { + "effect": "hlsl/chroma", + "name": "Phosphor Chromaticity Conversion", + "disablewhen": [ + { "type": "slider", "condition": "equal", "name": "adjustments", "value": 0 } + ], + "uniforms": [ + { "uniform": "u_y_gain", "slider": "chroma_y_gain" }, + { "uniform": "u_chroma_a", "slider": "chroma_a" }, + { "uniform": "u_chroma_b", "slider": "chroma_b" }, + { "uniform": "u_chroma_c", "slider": "chroma_c" } + ], + "input": [ + { "sampler": "s_tex", "target": "internal" } + ], + "output": "internal" }, { "effect": "hlsl/distortion", "name": "Distortion Pass", @@ -512,6 +541,40 @@ ], "output": "internal" }, + { + "effect": "misc/lut", + "name": "Apply LUT", + "disablewhen": [ + { + "type": "slider", + "condition": "equal", + "combine": "or", + "name": "adjustments", + "value": 0 + }, + { + "type": "slider", + "condition": "equal", + "combine": "or", + "name": "lut_enable", + "value": 0 + } + ], + "input": [ + { + "sampler": "s_tex", + "target": "internal" + }, + { + "sampler": "s_3dlut", + "option": "bgfx_lut", + "bilinear": false, + "clamp": true, + "selection": "LUT Texture" + } + ], + "output": "internal" + }, { "effect": "misc/blit", "name": "Final Blit", "input": [ diff --git a/bgfx/chains/lut.json b/bgfx/chains/lut.json new file mode 100644 index 00000000000..50353b5292b --- /dev/null +++ b/bgfx/chains/lut.json @@ -0,0 +1,36 @@ +{ + "name": "3D LUT", + "author": "W. M. Martinez", + "targets": [ + { + "name": "temp", + "mode": "guest" + } + ], + "passes": [ + { + "effect": "misc/blit", + "name": "Copy To Filtered Texture", + "input": [ + { "sampler": "s_tex", "texture": "screen" } + ], + "output": "temp" + }, { + "effect": "misc/lut", + "name": "Apply LUT", + "input": [ + { + "sampler": "s_tex", + "target": "temp" + }, { + "sampler": "s_3dlut", + "option": "bgfx_lut", + "bilinear": false, + "clamp": true, + "selection": "LUT Texture" + } + ], + "output": "output" + } + ] +} diff --git a/bgfx/effects/hlsl/chroma.json b/bgfx/effects/hlsl/chroma.json new file mode 100644 index 00000000000..6f7879cdc48 --- /dev/null +++ b/bgfx/effects/hlsl/chroma.json @@ -0,0 +1,33 @@ +// license:BSD-3-Clause +// copyright-holders:W. M. Martinez +//============================================================ +// +// chroma.json: Phosphor chromaticity conversion +// +//============================================================ +{ + "blend": { + "equation": "add", + "srcColor": "srcalpha", + "dstColor": "1-srcalpha", + "srcAlpha": "srcalpha", + "dstAlpha": "1-srcalpha" + }, + "depth": { + "function": "always" + }, + "cull": { "mode": "none" }, + "write": { + "rgb": true, + "alpha": true + }, + "vertex": "chains/hlsl/vs_chroma", + "fragment": "chains/hlsl/fs_chroma", + "uniforms": [ + { "name": "s_tex", "type": "int", "values": [ 0.0 ] }, + { "name": "u_y_gain", "type": "vec4", "values": [ 0.2124, 0.7011, 0.0866, 0.0 ] }, + { "name": "u_chroma_a", "type": "vec4", "values": [ 0.630, 0.340, 0.0, 0.0 ] }, + { "name": "u_chroma_b", "type": "vec4", "values": [ 0.310, 0.595, 0.0, 0.0 ] }, + { "name": "u_chroma_c", "type": "vec4", "values": [ 0.155, 0.070, 0.0, 0.0 ] } + ] +} diff --git a/bgfx/effects/hlsl/post.json b/bgfx/effects/hlsl/post.json index 904a27fb336..e4565978d21 100644 --- a/bgfx/effects/hlsl/post.json +++ b/bgfx/effects/hlsl/post.json @@ -42,6 +42,8 @@ { "name": "u_shadow_uv", "type": "vec4", "values": [ 0.25, 0.25, 0.0, 0.0 ] }, { "name": "u_shadow_uv_offset", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }, { "name": "u_power", "type": "vec4", "values": [ 1.0, 1.0, 1.0, 0.0 ] }, - { "name": "u_floor", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] } + { "name": "u_floor", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }, + { "name": "u_chroma_mode", "type": "vec4", "values": [ 3.0, 0.0, 0.0, 0.0 ] }, + { "name": "u_conversion_gain", "type": "vec4", "values": [ 0.299, 0.587, 0.114, 0.0 ] } ] -} \ No newline at end of file +} diff --git a/bgfx/effects/misc/lut.json b/bgfx/effects/misc/lut.json new file mode 100644 index 00000000000..fede670f016 --- /dev/null +++ b/bgfx/effects/misc/lut.json @@ -0,0 +1,32 @@ +{ + "blend": { + "equation": "add", + "srcColor": "srcalpha", + "dstColor": "1-srcalpha", + "srcAlpha": "srcalpha", + "dstAlpha": "1-srcalpha" + }, + "depth": { + "function": "always" + }, + "cull": { + "mode": "none" + }, + "write": { + "rgb": true, + "alpha": true + }, + "vertex": "chains/misc/vs_lut", + "fragment": "chains/misc/fs_lut", + "uniforms": [ + { + "name": "s_tex", + "type": "int", + "values": [ 1.0 ] + }, { + "name": "s_3dlut", + "type": "int", + "values": [ 1.0 ] + } + ] +} diff --git a/bgfx/shaders/dx11/chains/hlsl/fs_chroma.bin b/bgfx/shaders/dx11/chains/hlsl/fs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..babc5ee8386895e3a6a0007a13a4803709f37a9a GIT binary patch literal 1556 zcma)6O=uHA6n@$KwK=pQC&@t;!Gj`LM5>6j+a}p2DBX}vC5o_3Yp{ZU)E4SRf{NZe zdhj4#B?m8_TM$7niU$R+3L@SlCs9zpZ+0h1*Rsunw=?_R_uhQ-&FtE4IT^d#{hXAM zb?=sUsd@QYPDEmoS@)J#R|?Z3jYAFxO4MYFfu*@ufl1>Ge#SSUr;mu!8r5d zNGyfo2HxWUxM#hp<5ubwXI=`<8K)-oQlsEFwW4$!tVs^+!8J{|w!t;gqdrrcE7hgb zam&Tpr-X-Fhl*g)|pp+^^Sav3|aMwbd^F-9$)i!|z2LYc=lU=*HHu{Ez8xzYk1>apbRY&-Y)PTKrnw ze0}->HSYDpbZ{@dGa>I`&xF{hGhu#E&lBK9i_%l+7U-$#wVvVnK|OU&>&g3TSi9?~ zal7fMaS?i^SFt~G=9y7{j;w?2s5LReYE5jE*347uJAuXrhtQfe`tIs_-Z5IZUh7Jn wVg0Y`qqJW~T+}@s#6{gxjl*(ESAJ*uThRJ)zxrQej|JcTUVl8LehHTR12E^OW&i*H literal 0 HcmV?d00001 diff --git a/bgfx/shaders/dx11/chains/hlsl/fs_post.bin b/bgfx/shaders/dx11/chains/hlsl/fs_post.bin index 86f083ae517da5b3960a5ee2d11224a1d8efb7a2..b455d3dbf597d4a7c5614d9b5716072b7a4b7d8c 100644 GIT binary patch literal 2635 zcma)7zi(Vc5T1MX{qS8JUyguG8lEU4B#a9{2qn+4eTgNMi)_a-24lX0xuy>ugqH@9~?HK}@8x0yajx+)7HyWERa*4b$8 zBsH1x!p=sTBzv(6BM2wJ=!NaAtxnRd$vsGGkhYqe?Zddcy_3Yd?M-m3DTh}yclKM& zn(UtwZnS%Qpy)$b8Bp{NYVzed(%wOA-X25oLN9LhcGsI}+)C2!$8p;1!rk|tSvBhJ zCkTtZc)xv^q&4~3ueNsDZLEIB3JKb1rS09O#{4&AS0HQe9VBUIyS*1bXm0NznYo-4 zkfiNhc&cKN@5J5Y;ZzP9DRp%BQ&8mOhmy$L>aE#tdS8G3&yP30E%dK{_tl@j5$kj# z7+*twjQ$Jy!qV-#I~Xa4DH7@%@szPmpnvFQ{zEzS6Gf5rA$frH2mnhf@x8{M1oPr zEahpGFjYj22@pQ*ku>SG8Z zugiYl6)E0Q+&em6*O45Ii+c|ue54P4cHioX%W{})S?#jAYbrC$D>6D_^EYv{mcJlU z2bqCYJufnLq8#SC{)yk4oh4!}*?w}$Q`Y=l0^i%QpYoRQa;lWTUX3~?HN}< zvU$D?zGoVD;j<80oGrS|d7sEv(|Cq+NIYX2a47D{WgpvV#gCKVcvW?l+X8Hj4{?;p zk@a1M-s~|gnx5Pach!&F!!&FetKALS+MKyUD-y#ts1>zg{H9yUd(OX*TbEO{fseuc z2_mvs?fcR83tYwGya>1QD1@zlyRvyRzs6&GMC?V&J?{`>Vx4i!#$8aE?d>J(gAJI< zy6Oy5cob6Q-p&<0bH1ajJI2mtajcAaU)a}k`D2dQSnrlU^Z$QhgTK%&dR5Ai_ubPtUpt?%%lK3jL4(;awQA(f7>1X?73k&v16fUi3$J z$vEprVSk3CXvmcW5kBW?#KrJjti}g>8aUh6k|Vau#=Rrt9mHSr zc|)d3N0vAB&FmR&QvX5RyXA}j@gTy-zxi&)73A)Xb$RNC6gg%)vurJ}&WYpO_hUaj@okf`Y7Y@f1NB{r; literal 2411 zcmZuyJ!~6g7=G_;pB=kNtm8+eLgJ{H0Ev(RP=)BVN!&(4b!8_}Ku8xSx!?$=wrpQh z7?4|_QWwO+-YH9j)QL5SjRh*i#sW(vHk6?=&vW1VU9J|d^!>d*&-;6JqkX;Pe0BP_ zFEdFrI_wOhJD>X^;>axC{baZkN4xt6BVX!vj%n;0ZAR1c+$I7tydYhPy`wStaW3Cos!NH0U43 zLth@7*IuvR$LlY=JS4t<0PBD8D2<|Vd}qNC+$$r^Xu)ytl#0mm=GCPqj~@Ryeq;UB zAAWuLpU-~#z6?n!E8ut&>mk-3SgY-8H+ne9hbf9=i2CG_=CM9WZ)PK(^7*pJ_7va6 zy8wmuMs%~;UR_&l-jJo{hs~C(t!yqeo2_LzZo(&HAO?K~SeEiWfw6X_b!}x$j*r{d zms_vFUkJrtVEBdyJ)h;i)pggPd ziWCd>{tjAe>*t2*Aa~%icUDAZP8GxYZhUESv%N&j6`PNvI9075#zFEv=YW^h=<6W$ z#$I}Q=WG$rhfngS@o4aF9z*qx=1fdaYvw!;jEgF>v3NN=#8F`!dEZsYtv#+~D<^iU z_q;io1AD|+?VQlo-q|})In#kIiS?t6jh~nsC4-syz}!#=KB_IXb3-t)IWY5Zq`p&n@$-xgAwZtngQv zw)5@=Kt^I%cGl_ZzSe-Vp7wJ~PxR$?m3cEJE;odMOis9)b8>>;m)T4&_bqrjr*4?) z>UV8=%6bfeO@H?bIy1S6oqdxjfNsNAc7!BL6@$wkglYdG&Z1}kd#nS2nfX=go2h(lwD@`Wnd8-i3KMo5~;E6ub zr4+i#r@5ZUbTmt}E>qF)yJHXHuOH7N*SXfnM`i{)szL>gkx83vWT^r1L0^9I#Mk@?4aR18f&r|EHp*0yhZSev7d|4zry?87X5vH_mg zitVpAZJ+aGJr?P@y5qpI^6Q F20we_IVu1E literal 0 HcmV?d00001 diff --git a/bgfx/shaders/dx11/chains/misc/fs_lut.bin b/bgfx/shaders/dx11/chains/misc/fs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..ca3fdb8661bb238d4d02201cc6d394ccb4449aa9 GIT binary patch literal 756 zcmZ8dJxjx25WXah{XlGR5(g=cQn1!VifHFDMg{bqkASN zad&VQH(hjg$}jM_ya|;a+QyXzi7|_yoa9gdKX&I7WvHA*`OF*i+roKh`GjbPb05No|Mz4lIknj7#8|f;X5Alggvcx6DGktRnyyzmY^Y@jpj6zKQqeo7hGe<}yRh yWeiG*_izsG4)$P9{sZpg+ip;2X{&;FrU+}w_;}>;ck$@Y%{75Fw*=-WJnIj&PfS_> literal 0 HcmV?d00001 diff --git a/bgfx/shaders/dx11/chains/misc/vs_lut.bin b/bgfx/shaders/dx11/chains/misc/vs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..d97141ff5f280c64155d72420232f6743e59882e GIT binary patch literal 577 zcmZ9I%}T>S6oqdxjfNsNAc7!BL6@$wkglYdG&Z1}kd#nS2nfX=go2h(lwD@`Wnd8-i3KMo5~;E6ub zr4+i#r@5ZUbTmt}E>qF)yJHXHuOH7N*SXfnM`i{)szL>gkx83vWT^r1L0^9I#Mk@?4aR18f&r|EHp*0yhZSev7d|4zry?87X5vH_mg zitVpAZJ+aGJr?P@y5qpI^6Q F20we_IVu1E literal 0 HcmV?d00001 diff --git a/bgfx/shaders/dx9/chains/hlsl/fs_chroma.bin b/bgfx/shaders/dx9/chains/hlsl/fs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..004387174675da8a56eb5e2f3bd9a81a5b630999 GIT binary patch literal 1029 zcmZWnO=uHA7=1Illg1(jaumT_1bdMb51vXi1qoR3C+57SX|w@rO435T4S3Mwdh@si z50V_bcy2%h!K*06o3P?lJXwUU@0;DSSzQ?Bz4!gh`#$!1yJghVU*8POIN0g$)fJ$y zxEu5~N5idd(5)&}5Z0?o7ld9_c@)aK!IR)&cksCCI=uD(cu8`cG_iW`TJs#~S02#} zFX4CreBxz!Bwaz{IdA!1^2j@EhF2o+d&{GpnrkzsiGf`E=rrkA9r#?=*t`d_k z9~4tX7Ye?sE5z3Gv>stPC$`7I<)Dt6gWhO39zNKqUA((gYpu1{YVFPLMt@XW9d2z8 z9uX|pFD>)!JAm;~i8yiNxPR;F?|1KKwv`-+Zm54gwKuzR_GjbApQROfU-T07Hy1Wm z?tj01@ZrX@hUn+HhDEowN+_87wDj&U!y(F*i1TS~!1_Q$!1Zd&81t~7^A34uzvOa# z!4Z39xfAAhY|4G&iPT0-#uX~WG2e+@zQzLiA#)BL_h5*>SiU1Q+T+`T%dF*g>FFr) z5NBLlgLsbnwv_SQC#1gMThI9>cJHP${_mT$E-t<_=MZnXuZipA^%dhL!IqV h_A6dADa3x_9ufQ5)2h)p;yryh7&$f0dkZ7n<& zE1RUvr4cRc3|0zPSc=sNX>26e*t!1S+a;I5VP|&VZ~pIN-^{o^4lCF0-0;nd-#?=ZoIS6+KJm+p{c>3K^AwOZgqFJ<4)`0#&#z(^|xo5rq|%^C;;GQ+28C7 zuH3!6wnX!fle35~v9SkC$wr1!`WTe(f!{JdD+8H>uLV2g+kxb!U%?3Y)aO|bp~4gM z5GR#YEw-%exW$^v7A$sEnQyUmWuC>_%6fqXcNLZ`_FP%XVy~4|EH+Sf%wq4ANw8AJ1gz1WZj%(Y$&UNHp;Ckr4IUOP!cmSUu z;f?A8lf*%muvUjHNE&Gr+)C3@)bywTcU&s&(L?MiFc910^yQAJCbvaXL>+kPxOB5O zuV9{6_f=6&>X;OHhqJsj*21>A?2WKwks68UsJ;GDDv?^tn$^r=NZk%R?hUm{mlcsw zk4yZqyma~y{z^g&`)q(F0;*(_XJY52R~clIYtn<@6njo}I-Pw*<+BxGS;pZ10FW@J A_y7O^ delta 740 zcmY+>Jxjwt90u?wNs}~MZ78~wf`fxPyNDp-yU;<3f_?%)DHNRC8ecv@C8LAsB4Tk6 z2fNwP!NIYc2%WX)C>Wpnr&{meF1cTxyUX3RaxLFm-CVbglaJTjnOC?i%^KA#4742p zRvdrF_gLCmSS+x6V zKMBxW(%uF3fL9Br#a{jK5xM@?r=~sWsX6jNV_IgzId{K56&5w`<@4w(HEL#h9W||R UGxW9iu&$}m8m86cea|a?0SyH|5&!@I literal 0 HcmV?d00001 diff --git a/bgfx/shaders/dx9/chains/misc/fs_lut.bin b/bgfx/shaders/dx9/chains/misc/fs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..054e545e4219c5df8dfc83ff17204095c83cf684 GIT binary patch literal 501 zcmZ8d!AiqG6r8u4+9F~>uYx(M2TAc-5L=NR>OpI7LJ?E3P-$r+2#Tcm1Mv@XHoxLe z2swE616=2=ir|CE&YPXtx0|D0ry@@uZwA%*U@souCXomPmH8kU-bDiPSAJog`*b^K zpB=O|*xnPW87|u68A!Ms5|$ak61u9h&IwBh3}O{nKf@4U#k+NcmLH3v_^(eH7(_T8 zUCt)+$yE|=oop5K+YV}-oNYn?=?$Z@5Q_G K%u zKMBxW(%uF3fL9Br#a{jK5xM@?r=~sWsX6jNV_IgzId{K56&5w`<@4w(HEL#h9W||R UGxW9iu&$}m8m86cea|a?0SyH|5&!@I literal 0 HcmV?d00001 diff --git a/bgfx/shaders/essl/chains/hlsl/fs_chroma.bin b/bgfx/shaders/essl/chains/hlsl/fs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..1bddda86292fd230afdb198787167cdf7c1803f9 GIT binary patch literal 1693 zcmcJQ-Hw|u5QRylR25I*OVegu{>+b7l`6Gb^}Y{)2%9BH5JxN|Ayu#XqzkV*QH+?o_WnS%GEi7wc*?m@QThZiMJ}<22g<>i! zpR;ar0xf(#zP7AG-VW8SB-^Uo?#W?OgyfJFq86=tZ~xWwp$YOri1rcs{jPcvZG**X zz<)H=xVPKu+wDTPpYvv4Z(9E|8TW#bMfFG;AVjERf3pdx#qqLNA^I-!?u}a4>|x2w zmsNF5J`mWk>)Q?3($RN?_jayY1jr&_r{N4XfHR;jb5}%tjoM34z>YHNG66eEgK0+G zfKz|+o@$YIN)e*K5R9lo&ram6I^?sHF>at59H}`dKo17$@j&4{LAQgWEknEmXM^4W zPsEu7Kq-Z#2%#Qx$sKk)IkI7tAml%x7djJM+T>k81LlWrv?6yN<3a4hh0DS;krkJv zQIf8R$C8*Q<1+|7KK^nZj|Y4=lzo@SXhE)t8NefiEHZ!(nvTx~Etk(<0gsV7o&#T- zz}H}+Eh7v(#=!AJ@lD_mFb6({AmG|+ zI-T<`O#X$zKf(M{%pXsb-sBGfbN*up;(sj^5r;n$x_d$X>BPURvxhb>Kgm~tggu1= NX!UvkD&K9}`VEhR^R55@ literal 0 HcmV?d00001 diff --git a/bgfx/shaders/essl/chains/hlsl/fs_post.bin b/bgfx/shaders/essl/chains/hlsl/fs_post.bin index cf41b6945738329dff11522db9b63895b6d1f1f8..4704bd96769f9c1aeda61c999755cce7de0e8547 100644 GIT binary patch delta 539 zcmdlZJz1X9E!cyVvH82jB324@yQuQ`MHVlx%nxnOpFW+j0}Q6vHZNU)S}|d z{Ji+|#LT?Ori^+_|9Lm3GKMp;LDWy4z$C+uuIvD#_~t##QcRO`c#I}{aq~~!z*D*T zJZm-Urv0Sf0!PZv6aB>}wRK0?&LP~y#0!RU> zOY|x#t8^5c5{pxv^KDrml|Z7E31I2;O1I$OXWDGQBE__so4tf}at#~*=7~H! zjFX+&EGKW^6`I`5R;iSeUtXY4mYQs$P?B3vmRJ;TXl%`;00eOE;M1& diff --git a/bgfx/shaders/essl/chains/hlsl/vs_chroma.bin b/bgfx/shaders/essl/chains/hlsl/vs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..02eb754eaa33cbbe023a9397f5ac18a48d4053a0 GIT binary patch literal 419 zcmZvY!ES>v42FZWUh)(^(rQAK^;Y%XW2H&Eq6{dwDi~!Ug-tv4N%snSg1M}PROJ#y z`Rp(L{r0+@dFS6BPsk>=n4NZ-4o{vCo;dTVjM4bsm<$TciyCZ}tU$#H9Z834Ie}jo z*Ytq~shTW^xWHs>LZnkxSfx9xa@TJM{{xJ`y3I|6d(!2#xm0EaV+wW?rcf%Zz@N)6 z3GOGRtl1tf*Zh3D2cIX{Trx&}7=+KT48r*xZ#(8=zM$){MfP?*SwI{a)e@iL;0Pj1B>Hq)$ literal 0 HcmV?d00001 diff --git a/bgfx/shaders/essl/chains/misc/fs_lut.bin b/bgfx/shaders/essl/chains/misc/fs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..f87f98dbbad86ed8abbf3a0c22cdb3c9f7316187 GIT binary patch literal 828 zcmZuvL2iRE5G1XlN?iMaJwih*Vgqdy_0%fry$?VrAp{BH$RP<(_0*U43w=S?1`|iA z#DVqB&diRz_;??WzJGsitnogs(%KqX_}%Sewki%)SKZ%Q)-e%HzRh5hXPX@y(`5k1 zc*zSc{JDMAq}W8VCFf#={lhk2b5X)RDR)IG=o=`l{~JmeIeETNb3C0J=K)mZ4xPkQp6Y*i0W?w_M2f18lJ!h;u1Uf47&9mssT*W*aA)fH#Gi(t zPiM>npUh@-`ur5S@Sq1Nf)!=2&qyn0BSw4^)ONDN9;A`5VWw#ZSL=c&mF@(FtpEqG z$%QkFU9r|uduZ1%8L9x?s9ho&x)&KxEfyMLAyHK4;IW>Z2`-Q_ECbjKtEflQyNQgE z2s4xGmwAo;%*#?w!86$~U5WNCFSW<@++hznZ{EVA-YV#})i%fph5Le%lXR68@j@io Tt9;u=ei0_7Upxl(W!u&t`c(ut literal 0 HcmV?d00001 diff --git a/bgfx/shaders/essl/chains/misc/vs_lut.bin b/bgfx/shaders/essl/chains/misc/vs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..02eb754eaa33cbbe023a9397f5ac18a48d4053a0 GIT binary patch literal 419 zcmZvY!ES>v42FZWUh)(^(rQAK^;Y%XW2H&Eq6{dwDi~!Ug-tv4N%snSg1M}PROJ#y z`Rp(L{r0+@dFS6BPsk>=n4NZ-4o{vCo;dTVjM4bsm<$TciyCZ}tU$#H9Z834Ie}jo z*Ytq~shTW^xWHs>LZnkxSfx9xa@TJM{{xJ`y3I|6d(!2#xm0EaV+wW?rcf%Zz@N)6 z3GOGRtl1tf*Zh3D2cIX{Trx&}7=+KT48r*xZ#(8=zM$){MfP?*SwI{a)e@iL;0Pj1B>Hq)$ literal 0 HcmV?d00001 diff --git a/bgfx/shaders/glsl/chains/hlsl/fs_chroma.bin b/bgfx/shaders/glsl/chains/hlsl/fs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..6f9655c3c846bc636c59f43ac5b8e47e1b21b5f5 GIT binary patch literal 1612 zcmcJP-)h@16vmxFVE8F?DQ~Iff3j@Kt~Sc<`vAgG(<~52#kEsAV^@39J;7j4up>Fb z$4=W_6+&X2qwjp*`9XYh`)#@S_4oJEd*8}lZp+=_-NN%0p5IFKz1CGJ%XwivFQ}og ze3Z?m11)_1EIsd7*8T3VCC80Q$x$l3*L8U9qjC&okSML|JLt5B-My}>LEz$ClwGWs z8ta!DYHU1~)x&;M$6txf459Syj#RKcp@ILyCqo9M+eSv$?$}fh5MIWn;GW560vj}K zy@6rWPFvxvg1I_D>V$Ru2_^ucgoZ3!5%*csDsKn^1)q-S?59~uEvp&!)1_y){%$8CxVWBFiuNxa?biOIS#{_S({P{i3y<* z3&|Cp*afCBDS^p>^d)r5MEsTY_!4pY2J v9Sr8wtqG$3oGIcAe;jmrL+ZsqeY=-8b-Ddw-rt7vU=EDkI~}O}^nLFiB7oLP literal 0 HcmV?d00001 diff --git a/bgfx/shaders/glsl/chains/hlsl/fs_post.bin b/bgfx/shaders/glsl/chains/hlsl/fs_post.bin index 226bbd57b861a1f211cac71b43950ce2a9bfcf67..cf1638a8d4c1ae766066d53ab60bd32d44a2e4aa 100644 GIT binary patch delta 580 zcmZpbx**Hx7VN>w*!=0C$VN^hMm65j_~eYD{M^L&-29YOCPoGZMg~EkSbknvYEf}! zeqMZfVrJfCQ${@|8{W;SjISBBkq!Og09@%`D8e~f=tANVj=0a4|Dx~HVrz%uK-Ga-5MtTOCns8MLsP2LKyB@2@ s(ftkgHmV_DA7Jx9E!3S5Dm^FOttc@a9E_;JV$H>=pa4`{%f-b20FBSG!vFvP delta 169 zcmca0+bYHB7VN>w*!=0C&_+%p#>wf78ccJ!H&0}I&A537GZ)k5W;Q!kj*{Ghvc#fz zS!%M00#w@2*qTcL2;khwuXuD_;5@x@1zQED#Nt%v k{G9xvctgE%i1PHDc(t<8 diff --git a/bgfx/shaders/glsl/chains/hlsl/vs_chroma.bin b/bgfx/shaders/glsl/chains/hlsl/vs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..391ef1fda409769ce9241a2d1d557bb94716d4c9 GIT binary patch literal 377 zcmZ9I%?g4*6h=p=%{;|jYJ`}%i}o#pAZR6~CKKt6X`HlZ)syxLJwZ3~x6Lrz!#(qT zv)!!5#`FC$7|(qz;_F)Cabz%NupOO&Qc~=56@!jL4+1~L6G~^n2VhR%j2EEf zq~an(lo74zK$ap)em33OdSe%Ke<9Dr0c8qlpgiajk_kmbQ;~sb@jHi~Ql)2d`LhKL zn!A0w!t#q<)3Kc?%xuRR@S-H%HL#2Fi<6VTt~(JnySHJ|sw+<~Z{_LLrBrptiZq}1 H;GBH`Zq0je literal 0 HcmV?d00001 diff --git a/bgfx/shaders/glsl/chains/misc/fs_lut.bin b/bgfx/shaders/glsl/chains/misc/fs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..3d52149d27c8cb4977486d03945db1ebe7a197ba GIT binary patch literal 786 zcmZuvPfvp|6lY5o6F$W|f?~s3iY|*M&Enk;K*+`x5?GgxZGiFQC-vynPvC3UvM!o% zpzr+-%w<<@H*hSL2^_PfsDzB? zzEh@HMuDXea)q74wpi1xq><`w-AK>yAR5Z0p`%6*>rv` zCD7D6bk3+M*nfBev~LcwK(9cXMQ)_fu$g5rhs{Xap+JC!G>Az&vB1N!PGuDjsikmVLyP#fUF6l|9U<0S?mH)aDd1H%-lPEzfHiZlZ#vj2}*$(X% z?uJu>LG&0Y<)NLNS|9HCaH3V5m`Z2hULnf zq~an(lo74zK$ap)em33OdSe%Ke<9Dr0c8qlpgiajk_kmbQ;~sb@jHi~Ql)2d`LhKL zn!A0w!t#q<)3Kc?%xuRR@S-H%HL#2Fi<6VTt~(JnySHJ|sw+<~Z{_LLrBrptiZq}1 H;GBH`Zq0je literal 0 HcmV?d00001 diff --git a/bgfx/shaders/metal/chains/hlsl/fs_chroma.bin b/bgfx/shaders/metal/chains/hlsl/fs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..5fbf69c557d68ee5c455c77280ff82b83301068e GIT binary patch literal 2245 zcmc(h&2F1O5XVW?N|B#pP8GCti}^61w7pb{+C$Vs)Kg@kHNlQ0J}g)goG7P0X%5}O zhub8r@~U>uRLI2;%eu6x>T8TXPV4+=*+^)UC+9WYeC29KkNqsS>#8pF29yJb27DM? zmZ>q*}~OT!{{bUw&ikZLt2%%94q!?yajQl z#WSmRz0PXWv6f3T(gpzZkhOK@UVjo!e}RVEimCmE$hD!N#V*fkq0|(+L}m4Hk!8&u zQ1nU5{Y;{Mr5Tb|ElcL`83v#}uwr*h>%>)IZ7s?XSnh1_l0F? zHG4U4B=3=Ke~&St;+YO{Y*0VqxH?DfFiZ7B?zplXL*MY^h7eQ9{-`2f%Vt}mZY$Ek zJC*N}Zs^-n(O{$!;1Sdrgw!L6@sB-mls`oG)= zTTNnH5gpq?#}?|?78)er>t_`2 zb&B_c$bn)!Qi+dHOeZO(Pbfw@#aO2pX%yp^P{eXaD2kHLDNc2waYJjg)qkQGON#QF iLGVQQV>x2%*~__=wU&5XYQ6SWQi literal 0 HcmV?d00001 diff --git a/bgfx/shaders/metal/chains/hlsl/fs_post.bin b/bgfx/shaders/metal/chains/hlsl/fs_post.bin index a7881efd77d2bd0ef72872eb4b3618538d88a22f..f767a135e26f3222ea84ca33e766d4b8af2597ea 100644 GIT binary patch delta 592 zcmdlYKUta6E!cyVvH8aiwN)^j?8ql&reLd(l3${Lqz={TdKHybItoa3fCMxrGjfX68yW*O8-QF5 z0wuWxWr;vH7=uhl)qts_5|#45?K}%_&Y*s0LbE53-ejAC2@3G&RAh sL5dYnodq-a)@(g|%0D921H2?qr delta 179 zcmbQNyhWbVE!cyVvH8SuVoXR{opNoC7BF7Wf$@%R3 zo5lIO7$@tqJ4|Nf6PjGd-lv?Flb={(qEM1sP?lH}Z)mJwt6*Twr2qtQp~-)Fr6#xW zOG(2;^vZ$CoDz#uo%3_@fx7g{CkF`1sKVtz2GoLxqSTVoqCAE8+>)I5d~2>+E-nTD D8@x6; diff --git a/bgfx/shaders/metal/chains/hlsl/vs_chroma.bin b/bgfx/shaders/metal/chains/hlsl/vs_chroma.bin new file mode 100644 index 0000000000000000000000000000000000000000..00695b802d3db4727bc02e8d85d819e4251dea02 GIT binary patch literal 778 zcmZ{iy-ve06onH6OP=CRC`DD2hHO=L7%D1NuvAgxrfxAx?8v!JQxFqR%F4(S;QS|5 z8Eu_=&*yXevVOQRzka_>!%|_+=y4^*+qG#Jrtx!S7%F4@0GuQ=OG!i_p-AGnm7!D- zLJ<>OV!VDOJ1QS}st`UbfPE|o`ar@+#6r5T*$_m@whF23PJ&?GYVNfr6&XV&_((My zsywYiT0}y~-FTT-$v!XhJSjW_I>h0scWaFYJU-+NbBE~ZtIm9G{p0n_*7<5L9Z>z1jy%(wxX}1`BY@>-OxtAN5t$uxGoDJB69!PDYC2q!l%?)A#EX yr&3iLIm0RzVArrtpBUVAj@9yJY|zEfV^C1%&^9^L)&H@?kQ9~V4UMkHvW!1>M+=nz literal 0 HcmV?d00001 diff --git a/bgfx/shaders/metal/chains/misc/fs_lut.bin b/bgfx/shaders/metal/chains/misc/fs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..daf4df95f01d60e3301d962135177506cb21e628 GIT binary patch literal 1300 zcma)6%Z}7A5DbU8!g2f@*u>guX$$Je(XSI-`Q{dAnw%5lb_YWL96h7CO}7&J`K`pO*y9}59fO~s9< zZ@@j1n%>qt2-WEnNox$!KR|?_ztT-F7tdI#e!&G=hvL>KS;K} zwtZ=F&cDQIaE4Xld{-{*k05kX%2j9g7XuDa+soJR4$g~BKs5b5<#}Yvv$HZnP6Iv3 zXx#@$Gr^M0GDx+0PD*54GvL8mu`A3L>=}k8{WsMF-jJ&c^mLo5Jlp4N24?O{ z4!n;4+im2U#&b?bcxB8ar))GfBM&H2A0qM~jh(J9nLi(hF=QFWtPt|ron9)nc+T*5 MZFMs~H?Hga26G9m`v3p{ literal 0 HcmV?d00001 diff --git a/bgfx/shaders/metal/chains/misc/vs_lut.bin b/bgfx/shaders/metal/chains/misc/vs_lut.bin new file mode 100644 index 0000000000000000000000000000000000000000..00695b802d3db4727bc02e8d85d819e4251dea02 GIT binary patch literal 778 zcmZ{iy-ve06onH6OP=CRC`DD2hHO=L7%D1NuvAgxrfxAx?8v!JQxFqR%F4(S;QS|5 z8Eu_=&*yXevVOQRzka_>!%|_+=y4^*+qG#Jrtx!S7%F4@0GuQ=OG!i_p-AGnm7!D- zLJ<>OV!VDOJ1QS}st`UbfPE|o`ar@+#6r5T*$_m@whF23PJ&?GYVNfr6&XV&_((My zsywYiT0}y~-FTT-$v!XhJSjW_I>h0scWaFYJU-+NbBE~ZtIm9G{p0n_*7<5L9Z>z1jy%(wxX}1`BY@>-OxtAN5t$uxGoDJB69!PDYC2q!l%?)A#EX yr&3iLIm0RzVArrtpBUVAj@9yJY|zEfV^C1%&^9^L)&H@?kQ9~V4UMkHvW!1>M+=nz literal 0 HcmV?d00001 diff --git a/hlsl/chroma.fx b/hlsl/chroma.fx new file mode 100644 index 00000000000..dbb05bfc043 --- /dev/null +++ b/hlsl/chroma.fx @@ -0,0 +1,122 @@ +// license:BSD-3-Clause +// copyright-holders:W. M. Martinez +//----------------------------------------------------------------------------- +// Phosphor Chromaticity to sRGB Transform Effect +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Sampler Definitions +//----------------------------------------------------------------------------- + +texture Diffuse; + +sampler DiffuseSampler = sampler_state +{ + Texture = ; + MipFilter = LINEAR; + MinFilter = LINEAR; + MagFilter = LINEAR; + AddressU = CLAMP; + AddressV = CLAMP; + AddressW = CLAMP; +}; + +//----------------------------------------------------------------------------- +// Vertex Definitions +//----------------------------------------------------------------------------- + +struct VS_OUTPUT +{ + float4 Position : POSITION; + float4 Color : COLOR0; + float2 TexCoord : TEXCOORD0; + float2 PrevCoord : TEXCOORD1; +}; + +struct VS_INPUT +{ + float3 Position : POSITION; + float4 Color : COLOR0; + float2 TexCoord : TEXCOORD0; +}; + +struct PS_INPUT +{ + float4 Color : COLOR0; + float2 TexCoord : TEXCOORD0; + float2 PrevCoord : TEXCOORD1; +}; + +//----------------------------------------------------------------------------- +// Chroma Vertex Shader +//----------------------------------------------------------------------------- + +uniform float2 ScreenDims; +uniform float2 TargetDims; + +uniform bool Passthrough; + +VS_OUTPUT vs_main(VS_INPUT Input) +{ + VS_OUTPUT Output = (VS_OUTPUT)0.0; + + Output.Position = float4(Input.Position.xyz, 1.0); + Output.Position.xy /= ScreenDims; + Output.Position.y = 1.0 - Output.Position.y; // flip y + Output.Position.xy -= 0.5; // center + Output.Position.xy *= 2.0; // zoom + + Output.TexCoord = Input.TexCoord; + Output.TexCoord += 0.5 / TargetDims; // half texel offset correction (DX9) + + Output.PrevCoord = Output.TexCoord; + + Output.Color = Input.Color; + + return Output; +} + +//----------------------------------------------------------------------------- +// Chroma Pixel Shader +//----------------------------------------------------------------------------- + +uniform float3 YGain = float3(0.2126, 0.7152, 0.0722); +uniform float2 ChromaA = float2(0.630, 0.340); +uniform float2 ChromaB = float2(0.310, 0.595); +uniform float2 ChromaC = float2(0.155, 0.070); + +static const float3x3 XYZ_TO_sRGB = { + 3.2406, -1.5372, -0.4986, + -0.9689, 1.8758, 0.0415, + 0.0557, -0.2040, 1.0570 +}; + +float4 ps_main(PS_INPUT Input) : COLOR +{ + const float4 cin = tex2D(DiffuseSampler, Input.TexCoord); + float4 cout = float4(0.0, 0.0, 0.0, cin.a); + const float3x2 xy = { ChromaA, ChromaB, ChromaC }; + + for (int i = 0; i < 3; ++i) { + const float Y = YGain[i] * cin[i]; + const float X = xy[i].x * (Y / xy[i].y); + const float Z = (1.0 - xy[i].x - xy[i].y) * (Y / xy[i].y); + cout.rgb += mul(XYZ_TO_sRGB, float3(X, Y, Z)); + } + return cout; +} + +//----------------------------------------------------------------------------- +// Phosphor Technique +//----------------------------------------------------------------------------- + +technique DefaultTechnique +{ + pass Pass0 + { + Lighting = FALSE; + + VertexShader = compile vs_2_0 vs_main(); + PixelShader = compile ps_2_0 ps_main(); + } +} diff --git a/hlsl/phosphor.fx b/hlsl/phosphor.fx index d78473a2c6e..e195f34764d 100644 --- a/hlsl/phosphor.fx +++ b/hlsl/phosphor.fx @@ -71,16 +71,16 @@ uniform bool Passthrough; VS_OUTPUT vs_main(VS_INPUT Input) { - VS_OUTPUT Output = (VS_OUTPUT)0; + VS_OUTPUT Output = (VS_OUTPUT)0.0; - Output.Position = float4(Input.Position.xyz, 1.0f); + Output.Position = float4(Input.Position.xyz, 1.0); Output.Position.xy /= ScreenDims; - Output.Position.y = 1.0f - Output.Position.y; // flip y - Output.Position.xy -= 0.5f; // center - Output.Position.xy *= 2.0f; // zoom + Output.Position.y = 1.0 - Output.Position.y; // flip y + Output.Position.xy -= 0.5; // center + Output.Position.xy *= 2.0; // zoom Output.TexCoord = Input.TexCoord; - Output.TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) + Output.TexCoord += 0.5 / TargetDims; // half texel offset correction (DX9) Output.PrevCoord = Output.TexCoord; @@ -93,24 +93,23 @@ VS_OUTPUT vs_main(VS_INPUT Input) // Phosphor Pixel Shader //----------------------------------------------------------------------------- -uniform float3 Phosphor = float3(0.0f, 0.0f, 0.0f); -uniform float DeltaTime = 0.0f; -static const float F = 30.0f; +uniform float DeltaTime = 0.0; +uniform float3 Phosphor = float3(0.0, 0.0, 0.0); + +static const float F = 30.0; float4 ps_main(PS_INPUT Input) : COLOR { - float4 CurrPix = tex2D(DiffuseSampler, Input.TexCoord); - float3 PrevPix = tex2D(PreviousSampler, Input.PrevCoord).rgb; + float4 CurrY = tex2D(DiffuseSampler, Input.TexCoord); + float3 PrevY = tex2D(PreviousSampler, Input.PrevCoord).rgb; - PrevPix.r *= Phosphor.r == 0 ? 0 : pow(Phosphor.r, F * DeltaTime); - PrevPix.g *= Phosphor.g == 0 ? 0 : pow(Phosphor.g, F * DeltaTime); - PrevPix.b *= Phosphor.b == 0 ? 0 : pow(Phosphor.b, F * DeltaTime); - float RedMax = max(CurrPix.r, PrevPix.r); - float GreenMax = max(CurrPix.g, PrevPix.g); - float BlueMax = max(CurrPix.b, PrevPix.b); - - return Passthrough ? - CurrPix : float4(RedMax, GreenMax, BlueMax, CurrPix.a); + PrevY[0] *= Phosphor[0] == 0.0 ? 0.0 : pow(Phosphor[0], F * DeltaTime); + PrevY[1] *= Phosphor[1] == 0.0 ? 0.0 : pow(Phosphor[1], F * DeltaTime); + PrevY[2] *= Phosphor[2] == 0.0 ? 0.0 : pow(Phosphor[2], F * DeltaTime); + float a = max(PrevY[0], CurrY[0]); + float b = max(PrevY[1], CurrY[1]); + float c = max(PrevY[2], CurrY[2]); + return Passthrough ? CurrY : float4(a, b, c, CurrY.a); } //----------------------------------------------------------------------------- diff --git a/hlsl/post.fx b/hlsl/post.fx index 0d3bf244a16..ed9dfff9e30 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -4,6 +4,10 @@ // Shadowmask Effect //----------------------------------------------------------------------------- +#define MONOCHROME 1 +#define DICHROME 2 +#define TRICHROME 3 + //----------------------------------------------------------------------------- // Sampler Definitions //----------------------------------------------------------------------------- @@ -64,8 +68,8 @@ struct PS_INPUT // Constants //----------------------------------------------------------------------------- -static const float PI = 3.1415927f; -static const float HalfPI = PI * 0.5f; +static const float PI = 3.1415927; +static const float HalfPI = PI * 0.5; //----------------------------------------------------------------------------- // Shadowmask Vertex Shader @@ -77,8 +81,8 @@ uniform float2 TargetDims; uniform float2 TargetScale; uniform float2 QuadDims; -uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size) -uniform float2 ShadowUVOffset = float2(0.0f, 0.0f); +uniform float2 ShadowDims = float2(32.0, 32.0); // size of the shadow texture (extended to power-of-two size) +uniform float2 ShadowUVOffset = float2(0.0, 0.0); uniform bool SwapXY = false; @@ -89,16 +93,16 @@ VS_OUTPUT vs_main(VS_INPUT Input) { VS_OUTPUT Output = (VS_OUTPUT)0; - Output.Position = float4(Input.Position.xyz, 1.0f); + Output.Position = float4(Input.Position.xyz, 1.0); Output.Position.xy /= ScreenDims; - Output.Position.y = 1.0f - Output.Position.y; // flip y - Output.Position.xy -= 0.5f; // center - Output.Position.xy *= 2.0f; // zoom + Output.Position.y = 1.0 - Output.Position.y; // flip y + Output.Position.xy -= 0.5; // center + Output.Position.xy *= 2.0; // zoom Output.TexCoord = Input.TexCoord; Output.TexCoord += PrepareBloom - ? 0.0f // use half texel offset (DX9) to do the blur for first bloom layer - : 0.5f / TargetDims; // fix half texel offset (DX9) + ? 0.0 // use half texel offset (DX9) to do the blur for first bloom layer + : 0.5 / TargetDims; // fix half texel offset (DX9) Output.ScreenCoord = Input.Position.xy / ScreenDims; @@ -111,34 +115,37 @@ VS_OUTPUT vs_main(VS_INPUT Input) // Shadowmask Pixel Shader //----------------------------------------------------------------------------- -uniform float HumBarDesync = 60.0f / 59.94f - 1.0f; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC) -uniform float HumBarAlpha = 0.0f; +uniform float HumBarDesync = 60.0 / 59.94 - 1.0; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC) +uniform float HumBarAlpha = 0.0; -uniform float TimeMilliseconds = 0.0f; +uniform float TimeMilliseconds = 0.0; -uniform float2 ScreenScale = float2(1.0f, 1.0f); -uniform float2 ScreenOffset = float2(0.0f, 0.0f); +uniform float2 ScreenScale = float2(1.0, 1.0); +uniform float2 ScreenOffset = float2(0.0, 0.0); -uniform float3 BackColor = float3(0.0f, 0.0f, 0.0f); +uniform float3 BackColor = float3(0.0, 0.0, 0.0); uniform int ShadowTileMode = 0; // 0 based on screen (quad) dimension, 1 based on source dimension -uniform float ShadowAlpha = 0.0f; -uniform float2 ShadowCount = float2(6.0f, 6.0f); -uniform float2 ShadowUV = float2(0.25f, 0.25f); +uniform float ShadowAlpha = 0.0; +uniform float2 ShadowCount = float2(6.0, 6.0); +uniform float2 ShadowUV = float2(0.25, 0.25); -uniform float3 Power = float3(1.0f, 1.0f, 1.0f); -uniform float3 Floor = float3(0.0f, 0.0f, 0.0f); +uniform float3 Power = float3(1.0, 1.0, 1.0); +uniform float3 Floor = float3(0.0, 0.0, 0.0); + +uniform int ChromaMode = 3; +uniform float3 ConversionGain = float3(0.0, 0.0, 0.0); float2 GetAdjustedCoords(float2 coord) { // center coordinates - coord -= 0.5f; + coord -= 0.5; // apply screen scale coord *= ScreenScale; // un-center coordinates - coord += 0.5f; + coord += 0.5; // apply screen offset coord += ScreenOffset; @@ -158,8 +165,8 @@ float2 GetShadowCoord(float2 TargetCoord, float2 SourceCoord) ? TargetCoord + ShadowUVOffset / BaseTargetDims : SourceCoord + ShadowUVOffset / SourceDims; float2 canvasTexelDims = ShadowTileMode == 0 - ? 1.0f / BaseTargetDims - : 1.0f / SourceDims; + ? 1.0 / BaseTargetDims + : 1.0 / SourceDims; float2 shadowDims = ShadowDims; float2 shadowUV = ShadowUV; @@ -186,8 +193,8 @@ float2 GetShadowCoord(float2 TargetCoord, float2 SourceCoord) float2 shadowCoord = (shadowFrac * shadowUV); shadowCoord += ShadowTileMode == 0 - ? 0.5f / shadowDims // fix half texel offset (DX9) - : 0.0f; + ? 0.5 / shadowDims // fix half texel offset (DX9) + : 0.0; return shadowCoord; } @@ -199,29 +206,14 @@ float4 ps_main(PS_INPUT Input) : COLOR // Color float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); - BaseColor.a = 1.0f; + BaseColor.a = 1.0; // clip border - if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f || - BaseCoord.x > 1.0f || BaseCoord.y > 1.0f) + if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0 || + BaseCoord.x > 1.0 || BaseCoord.y > 1.0) { // we don't use the clip function, because we don't clear the render target before - return float4(0.0f, 0.0f, 0.0f, 1.0f); - } - - // Mask Simulation (may not affect bloom) - if (!PrepareBloom && ShadowAlpha > 0.0f) - { - float2 ShadowCoord = GetShadowCoord(ScreenCoord, BaseCoord); - - float4 ShadowColor = tex2D(ShadowSampler, ShadowCoord); - float3 ShadowMaskColor = lerp(1.0f, ShadowColor.rgb, ShadowAlpha); - float ShadowMaskClear = (1.0f - ShadowColor.a) * ShadowAlpha; - - // apply shadow mask color - BaseColor.rgb *= ShadowMaskColor; - // clear shadow mask by background color - BaseColor.rgb = lerp(BaseColor.rgb, BackColor, ShadowMaskClear); + return float4(0.0, 0.0, 0.0, 1.0); } // Color Compression (may not affect bloom) @@ -236,16 +228,36 @@ float4 ps_main(PS_INPUT Input) : COLOR BaseColor.g = pow(BaseColor.g, Power.g); BaseColor.b = pow(BaseColor.b, Power.b); - // Scanline Simulation (may not affect bloom) - if (!PrepareBloom) + // Hum Bar Simulation (may not affect vector screen) + if (!PrepareBloom && !VectorScreen && HumBarAlpha > 0.0) { - // Hum Bar Simulation (may not affect vector screen) - if (!VectorScreen && HumBarAlpha > 0.0f) - { - float HumBarStep = frac(TimeMilliseconds * HumBarDesync); - float HumBarBrightness = 1.0 - frac(BaseCoord.y + HumBarStep) * HumBarAlpha; - BaseColor.rgb *= HumBarBrightness; - } + float HumBarStep = frac(TimeMilliseconds * HumBarDesync); + float HumBarBrightness = 1.0 - frac(BaseCoord.y + HumBarStep) * HumBarAlpha; + BaseColor.rgb *= HumBarBrightness; + } + + // Mask Simulation (may not affect bloom) + if (!PrepareBloom && ShadowAlpha > 0.0) + { + float2 ShadowCoord = GetShadowCoord(ScreenCoord, BaseCoord); + + float4 ShadowColor = tex2D(ShadowSampler, ShadowCoord); + float3 ShadowMaskColor = lerp(1.0, ShadowColor.rgb, ShadowAlpha); + float ShadowMaskClear = (1.0 - ShadowColor.a) * ShadowAlpha; + + // apply shadow mask color + BaseColor.rgb *= ShadowMaskColor; + // clear shadow mask by background color + BaseColor.rgb = lerp(BaseColor.rgb, BackColor, ShadowMaskClear); + } + + // Preparation for phosphor color conversion + if (ChromaMode == MONOCHROME) { + BaseColor.r = dot(ConversionGain, BaseColor.rgb); + BaseColor.gb = float2(BaseColor.r, BaseColor.r); + } else if (ChromaMode == DICHROME) { + BaseColor.r = dot(ConversionGain.rg, BaseColor.rg); + BaseColor.g = BaseColor.r; } return BaseColor; diff --git a/hlsl/primary.fx b/hlsl/primary.fx index 839ebbf8bf0..998a4b8716a 100644 --- a/hlsl/primary.fx +++ b/hlsl/primary.fx @@ -1,14 +1,23 @@ // license:BSD-3-Clause -// copyright-holders:Ryan Holtz +// copyright-holders:Ryan Holtz, W. M. Martinez //----------------------------------------------------------------------------- // Primary Effect //----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Macros +//----------------------------------------------------------------------------- + +#define LUT_TEXTURE_WIDTH 4096.0f +#define LUT_SIZE 64.0f +#define LUT_SCALE float2(1.0f / LUT_TEXTURE_WIDTH, 1.0f / LUT_SIZE) + //----------------------------------------------------------------------------- // Sampler Definitions //----------------------------------------------------------------------------- texture Diffuse; +texture LutTexture; sampler DiffuseSampler = sampler_state { @@ -21,6 +30,35 @@ sampler DiffuseSampler = sampler_state AddressW = CLAMP; }; +sampler2D LutSampler = sampler_state +{ + Texture = ; + MinFilter = LINEAR; + MagFilter = LINEAR; + MipFilter = LINEAR; + AddressU = CLAMP; + AddressV = CLAMP; + AddressW = CLAMP; +}; + +//----------------------------------------------------------------------------- +// Utilities +//----------------------------------------------------------------------------- + +float3 apply_lut(float3 color) +{ + // NOTE: Do not change the order of parameters here. + float3 lutcoord = float3((color.rg * (LUT_SIZE - 1.0f) + 0.5f) * + LUT_SCALE, color.b * (LUT_SIZE - 1.0f)); + float shift = floor(lutcoord.z); + + lutcoord.x += shift * LUT_SCALE.y; + color.rgb = lerp(tex2D(LutSampler, lutcoord.xy).rgb, tex2D(LutSampler, + float2(lutcoord.x + LUT_SCALE.y, lutcoord.y)).rgb, + lutcoord.z - shift); + return color; +} + //----------------------------------------------------------------------------- // Vertex Definitions //----------------------------------------------------------------------------- @@ -49,7 +87,7 @@ struct PS_INPUT // Primary Vertex Shaders //----------------------------------------------------------------------------- -static const float Epsilon = 1.0e-7f; +//static const float Epsilon = 1.0e-7f; uniform float2 ScreenDims; uniform float2 TargetDims; @@ -112,10 +150,15 @@ VS_OUTPUT vs_ui_main(VS_INPUT Input) // Primary Pixel Shaders //----------------------------------------------------------------------------- +uniform bool LutEnable; +uniform bool UiLutEnable; + float4 ps_screen_main(PS_INPUT Input) : COLOR { float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); + if (LutEnable) + BaseTexel.rgb = apply_lut(BaseTexel.rgb); return BaseTexel; } @@ -123,6 +166,8 @@ float4 ps_vector_buffer_main(PS_INPUT Input) : COLOR { float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); + if (LutEnable) + BaseTexel.rgb = apply_lut(BaseTexel.rgb); return BaseTexel; } @@ -131,6 +176,8 @@ float4 ps_ui_main(PS_INPUT Input) : COLOR float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); BaseTexel *= Input.Color; + if (UiLutEnable) + BaseTexel.rgb = apply_lut(BaseTexel.rgb); return BaseTexel; } diff --git a/ini/examples/bt601-525.ini b/ini/examples/bt601-525.ini new file mode 100644 index 00000000000..e2b08f5c282 --- /dev/null +++ b/ini/examples/bt601-525.ini @@ -0,0 +1,21 @@ +# Example for BT.601 525-line Color Space +# +# BT.601 is a standard for converting analog video into the digital domain, +# and serves as a reference for the color space of analog video, but the color +# spaces defined existed before the standard. +# +# Due to historical differences, there are two color spaces in BT.601: one for +# 525-line television (developed in the U.S.), and one for 625-line television +# (developed in Europe). The color spaces, along with NTSC-J, converged upon +# the development of HD television with the BT.709 standard. +# +# This color space should be used for most 60 Hz arcade systems, consoles, and +# computer systems. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 3 +chroma_a 0.630,0.340 +chroma_b 0.310,0.595 +chroma_c 0.155,0.070 +chroma_y_gain 0.2124,0.7011,0.0866 diff --git a/ini/examples/bt601-625.ini b/ini/examples/bt601-625.ini new file mode 100644 index 00000000000..1dac1a33583 --- /dev/null +++ b/ini/examples/bt601-625.ini @@ -0,0 +1,21 @@ +# Example for BT.601 625-line Color Space +# +# BT.601 is a standard for converting analog video into the digital domain, +# and serves as a reference for the color space of analog video, but the color +# spaces defined existed before the standard. +# +# Due to historical differences, there are two color spaces in BT.601: one for +# 525-line television (developed in the U.S.), and one for 625-line television +# (developed in Europe). The color spaces, along with NTSC-J, converged upon +# the development of HD television with the BT.709 standard. +# +# This color space should be used for most 50 Hz arcade systems, consoles, and +# computer systems. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 3 +chroma_a 0.64,0.33 +chroma_b 0.29,0.60 +chroma_c 0.15,0.06 +chroma_y_gain 0.2220,0.7067,0.0713 diff --git a/ini/examples/bt709.ini b/ini/examples/bt709.ini new file mode 100644 index 00000000000..e706a394a18 --- /dev/null +++ b/ini/examples/bt709.ini @@ -0,0 +1,16 @@ +# Example for BT.709 Color Space +# +# BT.709 was standardized in 1990 for HD television. The color space for +# BT.709 would later be used for sRGB, the color space used for modern +# operating systems. +# +# This color space should be used for post-1995 computer systems and HD game +# systems. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 3 +chroma_a 0.64,0.33 +chroma_b 0.30,0.60 +chroma_c 0.15,0.06 +chroma_y_gain 0.2126,0.7152,0.0722 diff --git a/ini/examples/ntscj.ini b/ini/examples/ntscj.ini new file mode 100644 index 00000000000..5e510798fc5 --- /dev/null +++ b/ini/examples/ntscj.ini @@ -0,0 +1,16 @@ +# Example for NTSC-J Color Space +# +# NTSC-J has identical colorimetry to the BT.601 525-line standard, but uses a +# 9300K white-point 'D93'. Note that this white point is not necessarily +# definitive for all Japanese works. +# +# This color space may be used for 60 Hz arcade systems and consoles as an +# alternative to BT.601 525-line. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 3 +chroma_a 0.630,0.340 +chroma_b 0.310,0.595 +chroma_c 0.155,0.070 +chroma_gain 0.1875,0.6940,0.1185 diff --git a/ini/examples/p1.ini b/ini/examples/p1.ini new file mode 100644 index 00000000000..9570eb1243e --- /dev/null +++ b/ini/examples/p1.ini @@ -0,0 +1,12 @@ +# P1 Phosphor +# +# Multipurpose green phosphor +# +# Perhaps the most well-known phosphor, it has medium persistence. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 1 +chroma_a 0.218,0.712 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 1.0,0.0,0.0 diff --git a/ini/examples/p14.ini b/ini/examples/p14.ini new file mode 100644 index 00000000000..cb2c7138861 --- /dev/null +++ b/ini/examples/p14.ini @@ -0,0 +1,15 @@ +# P14 Phosphor +# +# Dual-color phosphor for military RADAR +# +# Red channel should be set to medium-short persistence. Green +# channel should be set to medium. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +phosphor_life 0.2,0.6,0.0 +chroma_mode 1 +chroma_a 0.150,0.093 +chroma_b 0.504,0.443 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 0.50,0.50,0.0 diff --git a/ini/examples/p2.ini b/ini/examples/p2.ini new file mode 100644 index 00000000000..312a6648ae2 --- /dev/null +++ b/ini/examples/p2.ini @@ -0,0 +1,12 @@ +# P2 Phosphor +# +# Green phosphor for oscilloscopes +# +# This phosphor was developed as a fast response alternative to P1. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 1 +chroma_a 0.279,0.534 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 1.0,0.0,0.0 diff --git a/ini/examples/p3.ini b/ini/examples/p3.ini new file mode 100644 index 00000000000..519d4ff233b --- /dev/null +++ b/ini/examples/p3.ini @@ -0,0 +1,12 @@ +# P3 Phosphor +# +# Amber phosphor for monochrome monitors +# +# Medium persistence +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 1 +chroma_a 0.523,0.469 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 1.0,0.0,0.0 diff --git a/ini/examples/p35.ini b/ini/examples/p35.ini new file mode 100644 index 00000000000..3cc31f78dcd --- /dev/null +++ b/ini/examples/p35.ini @@ -0,0 +1,12 @@ +# P35 Phosphor +# +# Blue-green phosphor used for oscilloscopes. +# +# Medium-short persistence. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 1 +chroma_a 0.200,0.245 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 1.0,0.0,0.0 diff --git a/ini/examples/p4.ini b/ini/examples/p4.ini new file mode 100644 index 00000000000..cc684505a0f --- /dev/null +++ b/ini/examples/p4.ini @@ -0,0 +1,19 @@ +# P4 Phosphor +# +# White phosphor for black & white televisions +# +# This phosphor presents a clear white appearance that is perceptually similar +# to a black and white photograph on highly reflective paper when the viewing +# environment is sufficiently dim, and makes D65 look fairly dull and yellowish +# in comparison, that said, next to saturated colors the blueish tint becomes +# more apparent. This might explain why this white point was abandoned in +# favor of the more neutral Illuminant C (and later D65) for color television. +# +# Medium-short persistence +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 1 +chroma_a 0.265,0.285 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 1.0,0.0,0.0 diff --git a/ini/examples/p55.ini b/ini/examples/p55.ini new file mode 100644 index 00000000000..dcb4a6ebecb --- /dev/null +++ b/ini/examples/p55.ini @@ -0,0 +1,13 @@ +# P55 Phosphor +# +# Trichromatic phosphors for CRT projectors +# +# Red and green have medium persistence, blue has medium-short. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +chroma_mode 3 +chroma_a 0.615,0.360 +chroma_b 0.300,0.600 +chroma_c 0.150,0.070 +chroma_y_gain 0.2555,0.6582,0.0863 diff --git a/ini/examples/p7.ini b/ini/examples/p7.ini new file mode 100644 index 00000000000..4c6580d028d --- /dev/null +++ b/ini/examples/p7.ini @@ -0,0 +1,15 @@ +# P7 Phosphor +# +# Dual-color phosphor for military RADAR +# +# Red channel should be set to medium-short persistence. Green +# channel should be set to long. +# +# DIRECT3D POST-PROCESSING OPTIONS +# +phosphor_life 0.2,0.8,0.0 +chroma_mode 1 +chroma_a 0.151,0.032 +chroma_b 0.357,0.537 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 0.50,0.50,0.0 diff --git a/ini/presets/raster.ini b/ini/presets/raster.ini index 8f852cf5a10..2a1b8a3ea82 100644 --- a/ini/presets/raster.ini +++ b/ini/presets/raster.ini @@ -38,6 +38,11 @@ scale 1.15,1.05,0.90 power 0.90,0.90,1.15 floor 0.025,0.025,0.025 phosphor_life 0.25,0.25,0.25 +chroma_mode 3 +chroma_a 0.630,0.340 +chroma_b 0.310,0.595 +chroma_c 0.155,0.070 +chroma_y_gain 0.2124,0.7011,0.0866 # # NTSC POST-PROCESSING OPTIONS diff --git a/ini/presets/vector-mono.ini b/ini/presets/vector-mono.ini index 00ff7978f5d..443fdc39782 100644 --- a/ini/presets/vector-mono.ini +++ b/ini/presets/vector-mono.ini @@ -38,6 +38,10 @@ scale 1.0,1.0,1.0 power 1.0,1.0,1.0 floor 0.0,0.0,0.0 phosphor_life 0.5,0.5,0.5 +chroma_mode 1 +chroma_a 0.265,0.285 +chroma_conversion_gain 0.30,0.59,0.11 +chroma_y_gain 1.0,0.0,0.0 # # NTSC POST-PROCESSING OPTIONS diff --git a/ini/presets/vector.ini b/ini/presets/vector.ini index ea41036f3e5..2335c2f324c 100644 --- a/ini/presets/vector.ini +++ b/ini/presets/vector.ini @@ -41,6 +41,11 @@ scale 1.0,1.0,1.0 power 1.0,1.0,1.0 floor 0.0,0.0,0.0 phosphor_life 0.5,0.5,0.5 +chroma_mode 3 +chroma_a 0.630,0.340 +chroma_b 0.310,0.595 +chroma_c 0.155,0.070 +chroma_y_gain 0.2124,0.7011,0.0866 # # NTSC POST-PROCESSING OPTIONS diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp index b937a66394c..5e6be57bde3 100644 --- a/src/osd/modules/lib/osdobj_common.cpp +++ b/src/osd/modules/lib/osdobj_common.cpp @@ -155,6 +155,7 @@ const options_entry osd_options::s_option_entries[] = { OSDOPTION_BGFX_DEBUG, "0", OPTION_BOOLEAN, "enable BGFX debugging statistics" }, { OSDOPTION_BGFX_SCREEN_CHAINS, "default", OPTION_STRING, "comma-delimited list of screen chain JSON names, colon-delimited per-window" }, { OSDOPTION_BGFX_SHADOW_MASK, "slot-mask.png", OPTION_STRING, "shadow mask texture name" }, + { OSDOPTION_BGFX_LUT, "", OPTION_STRING, "LUT texture name" }, { OSDOPTION_BGFX_AVI_NAME, OSDOPTVAL_AUTO, OPTION_STRING, "filename for BGFX output logging" }, // End of list diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h index 7d6e303fd8e..8c275ebf48d 100644 --- a/src/osd/modules/lib/osdobj_common.h +++ b/src/osd/modules/lib/osdobj_common.h @@ -88,6 +88,7 @@ #define OSDOPTION_BGFX_DEBUG "bgfx_debug" #define OSDOPTION_BGFX_SCREEN_CHAINS "bgfx_screen_chains" #define OSDOPTION_BGFX_SHADOW_MASK "bgfx_shadow_mask" +#define OSDOPTION_BGFX_LUT "bgfx_lut" #define OSDOPTION_BGFX_AVI_NAME "bgfx_avi_name" //============================================================ @@ -162,6 +163,7 @@ public: bool bgfx_debug() const { return bool_value(OSDOPTION_BGFX_DEBUG); } const char *bgfx_screen_chains() const { return value(OSDOPTION_BGFX_SCREEN_CHAINS); } const char *bgfx_shadow_mask() const { return value(OSDOPTION_BGFX_SHADOW_MASK); } + const char *bgfx_lut() const { return value(OSDOPTION_BGFX_LUT); } const char *bgfx_avi_name() const { return value(OSDOPTION_BGFX_AVI_NAME); } // PortAudio options diff --git a/src/osd/modules/render/bgfx/chainentryreader.cpp b/src/osd/modules/render/bgfx/chainentryreader.cpp index 57ade646a44..156827b0a96 100644 --- a/src/osd/modules/render/bgfx/chainentryreader.cpp +++ b/src/osd/modules/render/bgfx/chainentryreader.cpp @@ -63,8 +63,10 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, std::s if (!READER_CHECK(!has_target || input["target"].IsString(), (prefix + "input[" + std::to_string(i) + ": Value 'target' must be a string\n").c_str())) return nullptr; if (!READER_CHECK(!has_option || input["option"].IsString(), (prefix + "input[" + std::to_string(i) + ": Value 'option' must be a string\n").c_str())) return nullptr; if (!READER_CHECK(has_target || !input.HasMember("bilinear") || input["bilinear"].IsBool(), (prefix + "input[" + std::to_string(i) + ": Value 'bilinear' must be a boolean\n").c_str())) return nullptr; + if (!READER_CHECK(has_target || !input.HasMember("clamp") || input["clamp"].IsBool(), (prefix + "input[" + std::to_string(i) + ": Value 'clamp' must be a boolean\n").c_str())) return nullptr; if (!READER_CHECK(has_texture || has_option || !input.HasMember("selection") || input["selection"].IsString(), (prefix + "input[" + std::to_string(i) + ": Value 'selection' must be a string\n").c_str())) return nullptr; bool bilinear = get_bool(input, "bilinear", true); + bool clamp = get_bool(input, "clamp", false); std::string selection = get_string(input, "selection", ""); std::vector texture_names; @@ -87,7 +89,8 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, std::s if (selection == "") { // create texture for specified file name - uint32_t flags = bilinear ? 0 : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT); + uint32_t flags = bilinear ? 0u : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT); + flags |= clamp ? (BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_W_CLAMP) : 0u; bgfx_texture* texture = chains.textures().create_png_texture(chains.options().art_path(), texture_name, texture_name, flags, screen_index); if (texture == nullptr) { @@ -97,7 +100,8 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, std::s else { // create texture for specified file name - uint32_t flags = bilinear ? 0 : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT); + uint32_t flags = bilinear ? 0u : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT); + flags |= clamp ? (BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_W_CLAMP) : 0u; bgfx_texture* texture = chains.textures().create_png_texture(chains.options().art_path(), texture_name, texture_name, flags, screen_index); if (texture == nullptr) { @@ -149,7 +153,8 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, std::s if (file_extension == extension) { // create textures for all files containd in the path of the specified file name - uint32_t flags = bilinear ? 0 : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT); + uint32_t flags = bilinear ? 0u : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT); + flags |= clamp ? (BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_W_CLAMP) : 0u; bgfx_texture* texture = chains.textures().create_png_texture(chains.options().art_path(), file_path, file_path, flags, screen_index); if (texture == nullptr) { diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc new file mode 100644 index 00000000000..b76370c0aa9 --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc @@ -0,0 +1,38 @@ +$input v_color0, v_texcoord0 + +// license: BSD-3-Clause +// copyright-holders: W. M. Martinez +//----------------------------------------------------------------------------- +// Phosphor Chromaticity to sRGB Transform Effect +//----------------------------------------------------------------------------- + +#include "common.sh" + +// User-supplied +uniform vec4 u_y_gain; +uniform vec4 u_chroma_a; +uniform vec4 u_chroma_b; +uniform vec4 u_chroma_c; + +// Samplers +SAMPLER2D(s_tex, 0); + +void main() +{ + vec4 cin = texture2D(s_tex, v_texcoord0); + vec4 cout = vec4(0.0, 0.0, 0.0, cin.a); + mat3 xy = mat3(u_chroma_a.xyz, u_chroma_b.xyz, u_chroma_c.xyz); + const mat3 XYZ_TO_sRGB = mat3( + 3.2406, -1.5372, -0.4986, + -0.9689, 1.8758, 0.0415, + 0.0557, -0.2040, 1.0570 + ); + + for (int i = 0; i < 3; ++i) { + float Y = u_y_gain[i] * cin[i]; + float X = xy[i].x / xy[i].y * Y; + float Z = (1.0 - xy[i].x - xy[i].y) / xy[i].y * Y; + cout.rgb += mul(XYZ_TO_sRGB, vec3(X, Y, Z)); + } + gl_FragColor = cout * v_color0; +} diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc index 4aa3719c0ab..10fb11dac8c 100644 --- a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc @@ -3,11 +3,15 @@ $input v_color0, v_texcoord0 // license:BSD-3-Clause // copyright-holders:Ryan Holtz,ImJezze //----------------------------------------------------------------------------- -// Scanline & Shadowmask Effect +// Shadowmask Effect //----------------------------------------------------------------------------- #include "common.sh" +#define MONOCHROME 1.0 +#define DICHROME 2.0 +#define TRICHROME 3.0 + // Autos uniform vec4 u_swap_xy; uniform vec4 u_source_dims; // size of the guest machine @@ -27,6 +31,8 @@ uniform vec4 u_humbar_hertz_rate; // difference between the 59.94 Hz field rate uniform vec4 u_humbar_alpha; uniform vec4 u_power; uniform vec4 u_floor; +uniform vec4 u_chroma_mode; +uniform vec4 u_conversion_gain; // Parametric uniform vec4 u_time; // milliseconds @@ -112,6 +118,14 @@ void main() } else { + // Hum Bar Simulation + if (u_humbar_alpha.x > 0.0f) + { + float HumTimeStep = fract(u_time.x * u_humbar_hertz_rate.x); + float HumBrightness = 1.0 - fract(BaseCoord.y + HumTimeStep) * u_humbar_alpha.x; + BaseColor.rgb *= HumBrightness; + } + // Mask Simulation if (u_shadow_alpha.x > 0.0) { @@ -139,14 +153,15 @@ void main() BaseColor.g = pow(BaseColor.g, u_power.g); BaseColor.b = pow(BaseColor.b, u_power.b); - // Hum Bar Simulation - if (u_humbar_alpha.x > 0.0f) - { - float HumTimeStep = fract(u_time.x * u_humbar_hertz_rate.x); - float HumBrightness = 1.0 - fract(BaseCoord.y + HumTimeStep) * u_humbar_alpha.x; - BaseColor.rgb *= HumBrightness; + BaseColor.rgb *= v_color0.rgb; + if (u_chroma_mode.x == MONOCHROME) { + BaseColor.r = dot(u_conversion_gain.rgb, BaseColor.rgb); + BaseColor.gb = vec2(BaseColor.r, BaseColor.r); + } else if (u_chroma_mode.x == DICHROME) { + BaseColor.r = dot(u_conversion_gain.rg, BaseColor.rg); + BaseColor.g = BaseColor.r; } - gl_FragColor = vec4(BaseColor.rgb * v_color0.rgb, BaseColor.a); + gl_FragColor = BaseColor; } } diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_chroma.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_chroma.sc new file mode 100644 index 00000000000..405ef8feb3b --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/vs_chroma.sc @@ -0,0 +1,14 @@ +$input a_position, a_texcoord0, a_color0 +$output v_texcoord0, v_color0 + +// license:BSD-3-Clause +// copyright-holders:Dario Manesku + +#include "common.sh" + +void main() +{ + gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0)); + v_texcoord0 = a_texcoord0; + v_color0 = a_color0; +} diff --git a/src/osd/modules/render/bgfx/shaders/chains/misc/fs_lut.sc b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_lut.sc new file mode 100644 index 00000000000..2c8cffab7e1 --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_lut.sc @@ -0,0 +1,29 @@ +$input v_color0, v_texcoord0 + +// license: BSD-3-Clause +// copyright-holders: W. M. Martinez + +#include "common.sh" + +#define LUT_TEXTURE_WIDTH 4096.0f +#define LUT_SIZE 64.0f +#define LUT_SCALE vec2(1.0f / LUT_TEXTURE_WIDTH, 1.0f / LUT_SIZE) + +SAMPLER2D(s_tex, 0); +SAMPLER2D(s_3dlut, 1); + +void main() +{ + vec4 bp = texture2D(s_tex, v_texcoord0); + vec3 color = bp.rgb; + // NOTE: Do not change the order of parameters here. + vec3 lutcoord = vec3(color.rg * ((LUT_SIZE - 1.0f) + 0.5f) * + LUT_SCALE, (LUT_SIZE - 1.0f) * color.b); + float shift = floor(lutcoord.z); + + lutcoord.x += shift * LUT_SCALE.y; + color.rgb = mix(texture2D(s_3dlut, lutcoord.xy).rgb, + texture2D(s_3dlut, vec2(lutcoord.x + LUT_SCALE.y, + lutcoord.y)).rgb, lutcoord.z - shift); + gl_FragColor = vec4(color, bp.a) * v_color0; +} diff --git a/src/osd/modules/render/bgfx/shaders/chains/misc/vs_lut.sc b/src/osd/modules/render/bgfx/shaders/chains/misc/vs_lut.sc new file mode 100644 index 00000000000..405ef8feb3b --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/misc/vs_lut.sc @@ -0,0 +1,14 @@ +$input a_position, a_texcoord0, a_color0 +$output v_texcoord0, v_color0 + +// license:BSD-3-Clause +// copyright-holders:Dario Manesku + +#include "common.sh" + +void main() +{ + gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0)); + v_texcoord0 = a_texcoord0; + v_color0 = a_color0; +} diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index a368e363de6..e2a9bb4bc53 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -25,6 +25,7 @@ #include "strconv.h" #include "d3dhlsl.h" #include "../frontend/mame/ui/slider.h" +#include #include //============================================================ @@ -171,6 +172,8 @@ shaders::shaders() : acc_t(0), delta_t(0), shadow_texture(nullptr), + lut_texture(nullptr), + ui_lut_texture(nullptr), options(nullptr), black_surface(nullptr), black_texture(nullptr), @@ -198,6 +201,7 @@ shaders::shaders() : bloom_effect(nullptr), downsample_effect(nullptr), vector_effect(nullptr), + chroma_effect(nullptr), curr_texture(nullptr), curr_render_target(nullptr), curr_poly(nullptr), @@ -546,6 +550,12 @@ bool shaders::init(d3d_base *d3dintf, running_machine *machine, renderer_d3d9 *r get_vector(winoptions.screen_floor(), 3, options->floor, true); get_vector(winoptions.screen_phosphor(), 3, options->phosphor, true); options->saturation = winoptions.screen_saturation(); + options->chroma_mode = winoptions.screen_chroma_mode(); + get_vector(winoptions.screen_chroma_a(), 2, options->chroma_a, true); + get_vector(winoptions.screen_chroma_b(), 2, options->chroma_b, true); + get_vector(winoptions.screen_chroma_c(), 2, options->chroma_c, true); + get_vector(winoptions.screen_chroma_conversion_gain(), 3, options->chroma_conversion_gain, true); + get_vector(winoptions.screen_chroma_y_gain(), 3, options->chroma_y_gain, true); options->yiq_enable = winoptions.screen_yiq_enable(); options->yiq_jitter = winoptions.screen_yiq_jitter(); options->yiq_cc = winoptions.screen_yiq_cc(); @@ -574,6 +584,10 @@ bool shaders::init(d3d_base *d3dintf, running_machine *machine, renderer_d3d9 *r options->bloom_level6_weight = winoptions.screen_bloom_lvl6_weight(); options->bloom_level7_weight = winoptions.screen_bloom_lvl7_weight(); options->bloom_level8_weight = winoptions.screen_bloom_lvl8_weight(); + strncpy(options->lut_texture, winoptions.screen_lut_texture(), sizeof(options->lut_texture)); + options->lut_enable = winoptions.screen_lut_enable(); + strncpy(options->ui_lut_texture, winoptions.ui_lut_texture(), sizeof(options->ui_lut_texture)); + options->ui_lut_enable = winoptions.ui_lut_enable(); options->params_init = true; @@ -728,6 +742,44 @@ int shaders::create_resources() d3d->get_texture_manager()->m_texture_list.push_back(std::move(tex)); } + render_load_png(lut_bitmap, file, nullptr, options->lut_texture); + if (lut_bitmap.valid()) + { + render_texinfo texture; + + // fake in the basic data so it looks like it came from render.c + texture.base = lut_bitmap.raw_pixptr(0); + texture.rowpixels = lut_bitmap.rowpixels(); + texture.width = lut_bitmap.width(); + texture.height = lut_bitmap.height(); + texture.palette = nullptr; + texture.seqid = 0; + + // now create it (no prescale, no wrap) + auto tex = std::make_unique(d3d->get_texture_manager(), &texture, 1, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); + lut_texture = tex.get(); + d3d->get_texture_manager()->m_texture_list.push_back(std::move(tex)); + } + + render_load_png(ui_lut_bitmap, file, nullptr, options->ui_lut_texture); + if (ui_lut_bitmap.valid()) + { + render_texinfo texture; + + // fake in the basic data so it looks like it came from render.c + texture.base = ui_lut_bitmap.raw_pixptr(0); + texture.rowpixels = ui_lut_bitmap.rowpixels(); + texture.width = ui_lut_bitmap.width(); + texture.height = ui_lut_bitmap.height(); + texture.palette = nullptr; + texture.seqid = 0; + + // now create it (no prescale, no wrap) + auto tex = std::make_unique(d3d->get_texture_manager(), &texture, 1, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); + ui_lut_texture = tex.get(); + d3d->get_texture_manager()->m_texture_list.push_back(std::move(tex)); + } + const char *fx_dir = downcast(machine->options()).screen_post_fx_dir(); default_effect = new effect(this, d3d->get_device(), "primary.fx", fx_dir); @@ -743,6 +795,7 @@ int shaders::create_resources() bloom_effect = new effect(this, d3d->get_device(), "bloom.fx", fx_dir); downsample_effect = new effect(this, d3d->get_device(), "downsample.fx", fx_dir); vector_effect = new effect(this, d3d->get_device(), "vector.fx", fx_dir); + chroma_effect = new effect(this, d3d->get_device(), "chroma.fx", fx_dir); if (!default_effect->is_valid() || !post_effect->is_valid() || @@ -756,14 +809,13 @@ int shaders::create_resources() !ntsc_effect->is_valid() || !bloom_effect->is_valid() || !downsample_effect->is_valid() || - !vector_effect->is_valid()) + !vector_effect->is_valid() || + !chroma_effect->is_valid()) { return 1; } - const int EFFECT_COUNT = 14; - - effect *effects[EFFECT_COUNT] = { + std::array effects = { default_effect, post_effect, distortion_effect, @@ -777,10 +829,11 @@ int shaders::create_resources() color_effect, bloom_effect, downsample_effect, - vector_effect + vector_effect, + chroma_effect }; - for (int i = 0; i < EFFECT_COUNT; i++) + for (int i = 0; i < effects.size(); i++) { effects[i]->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); effects[i]->add_uniform("TargetDims", uniform::UT_VEC2, uniform::CU_TARGET_DIMS); @@ -824,15 +877,22 @@ int shaders::create_resources() focus_effect->add_uniform("Defocus", uniform::UT_VEC2, uniform::CU_FOCUS_SIZE); - phosphor_effect->add_uniform("Phosphor", uniform::UT_VEC3, uniform::CU_PHOSPHOR_LIFE); - - post_effect->add_uniform("ShadowAlpha", uniform::UT_FLOAT, uniform::CU_POST_SHADOW_ALPHA); + post_effect->add_uniform("ShadowAlpha", uniform::UT_FLOAT, uniform::CU_POST_SHADOW_ALPHA); post_effect->add_uniform("ShadowCount", uniform::UT_VEC2, uniform::CU_POST_SHADOW_COUNT); post_effect->add_uniform("ShadowUV", uniform::UT_VEC2, uniform::CU_POST_SHADOW_UV); post_effect->add_uniform("ShadowUVOffset", uniform::UT_VEC2, uniform::CU_POST_SHADOW_UV_OFFSET); post_effect->add_uniform("ShadowDims", uniform::UT_VEC2, uniform::CU_POST_SHADOW_DIMS); post_effect->add_uniform("Power", uniform::UT_VEC3, uniform::CU_POST_POWER); post_effect->add_uniform("Floor", uniform::UT_VEC3, uniform::CU_POST_FLOOR); + post_effect->add_uniform("ChomaMode", uniform::UT_INT, uniform::CU_CHROMA_MODE); + post_effect->add_uniform("ConversionGain", uniform::UT_VEC3, uniform::CU_CHROMA_CONVERSION_GAIN); + + phosphor_effect->add_uniform("Phosphor", uniform::UT_VEC3, uniform::CU_PHOSPHOR_LIFE); + + chroma_effect->add_uniform("YGain", uniform::UT_VEC3, uniform::CU_CHROMA_Y_GAIN); + chroma_effect->add_uniform("ChromaA", uniform::UT_VEC2, uniform::CU_CHROMA_A); + chroma_effect->add_uniform("ChromaB", uniform::UT_VEC2, uniform::CU_CHROMA_B); + chroma_effect->add_uniform("ChromaC", uniform::UT_VEC2, uniform::CU_CHROMA_C); distortion_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING); distortion_effect->add_uniform("DistortionAmount", uniform::UT_FLOAT, uniform::CU_POST_DISTORTION); @@ -842,6 +902,9 @@ int shaders::create_resources() distortion_effect->add_uniform("SmoothBorderAmount", uniform::UT_FLOAT, uniform::CU_POST_SMOOTH_BORDER); distortion_effect->add_uniform("ReflectionAmount", uniform::UT_FLOAT, uniform::CU_POST_REFLECTION); + default_effect->add_uniform("LutEnable", uniform::UT_BOOL, uniform::CU_LUT_ENABLE); + default_effect->add_uniform("UiLutEnable", uniform::UT_BOOL, uniform::CU_UI_LUT_ENABLE); + return 0; } @@ -880,6 +943,7 @@ void shaders::begin_draw() bloom_effect->set_technique("DefaultTechnique"); downsample_effect->set_technique("DefaultTechnique"); vector_effect->set_technique("DefaultTechnique"); + chroma_effect->set_technique("DefaultTechnique"); HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer); if (FAILED(result)) @@ -1190,13 +1254,11 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, curr_effect = post_effect; curr_effect->update_uniforms(); - curr_effect->set_texture("ShadowTexture", shadow_texture == nullptr ? nullptr : shadow_texture->get_finaltex()); - curr_effect->set_int("ShadowTileMode", options->shadow_mask_tile_mode); + curr_effect->set_texture("ShadowTexture", shadow_texture == nullptr ? nullptr : shadow_texture->get_finaltex()); curr_effect->set_int("ShadowTileMode", options->shadow_mask_tile_mode); curr_effect->set_texture("DiffuseTexture", rt->target_texture[next_index]); curr_effect->set_vector("BackColor", 3, back_color); curr_effect->set_vector("ScreenScale", 2, screen_scale); curr_effect->set_vector("ScreenOffset", 2, screen_offset); - curr_effect->set_float("ScanlineOffset", curr_texture->get_cur_frame() == 0 ? 0.0f : options->scanline_jitter); curr_effect->set_float("TimeMilliseconds", (float)machine->time().as_double() * 1000.0f); curr_effect->set_float("HumBarAlpha", options->hum_bar_alpha); curr_effect->set_bool("PrepareBloom", prepare_bloom); @@ -1207,6 +1269,18 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, return next_index; } +int shaders::chroma_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum) +{ + int next_index = source_index; + + curr_effect = chroma_effect; + curr_effect->update_uniforms(); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); + next_index = rt->next_index(next_index); + blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2); + return next_index; +} + int shaders::downsample_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum) { int next_index = source_index; @@ -1332,6 +1406,8 @@ int shaders::vector_buffer_pass(d3d_render_target *rt, int source_index, poly_in curr_effect->set_technique("VectorBufferTechnique"); curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); + curr_effect->set_texture("LutTexture", lut_texture == nullptr ? nullptr : lut_texture->get_finaltex()); + // we need to clear the vector render target here next_index = rt->next_index(next_index); @@ -1351,6 +1427,7 @@ int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *pol curr_effect->set_technique("ScreenTechnique"); curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); + curr_effect->set_texture("LutTexture", lut_texture == nullptr ? nullptr : lut_texture->get_finaltex()); blit(backbuffer, false, poly->type(), vertnum, poly->count()); @@ -1382,6 +1459,8 @@ void shaders::ui_pass(poly_info *poly, int vertnum) curr_effect->update_uniforms(); curr_effect->set_technique("UiTechnique"); + curr_effect->set_texture("LutTexture", lut_texture == nullptr ? nullptr : ui_lut_texture->get_finaltex()); + blit(nullptr, false, poly->type(), vertnum, poly->count()); } @@ -1429,17 +1508,19 @@ void shaders::render_quad(poly_info *poly, int vertnum) next_index = deconverge_pass(rt, next_index, poly, vertnum); next_index = scanline_pass(rt, next_index, poly, vertnum); next_index = defocus_pass(rt, next_index, poly, vertnum); - next_index = phosphor_pass(rt, next_index, poly, vertnum); + //next_index = phosphor_pass(rt, next_index, poly, vertnum); // create bloom textures - int phosphor_index = next_index; + int old_index = next_index; next_index = post_pass(rt, next_index, poly, vertnum, true); next_index = downsample_pass(rt, next_index, poly, vertnum); // apply bloom textures - next_index = phosphor_index; + next_index = old_index; next_index = post_pass(rt, next_index, poly, vertnum, false); next_index = bloom_pass(rt, next_index, poly, vertnum); + next_index = phosphor_pass(rt, next_index, poly, vertnum); + next_index = chroma_pass(rt, next_index, poly, vertnum); next_index = distortion_pass(rt, next_index, poly, vertnum); @@ -1508,17 +1589,19 @@ void shaders::render_quad(poly_info *poly, int vertnum) next_index = vector_buffer_pass(rt, next_index, poly, vertnum); next_index = deconverge_pass(rt, next_index, poly, vertnum); next_index = defocus_pass(rt, next_index, poly, vertnum); - next_index = phosphor_pass(rt, next_index, poly, vertnum); + //next_index = phosphor_pass(rt, next_index, poly, vertnum); // create bloom textures - int phosphor_index = next_index; + int old_index = next_index; next_index = post_pass(rt, next_index, poly, vertnum, true); next_index = downsample_pass(rt, next_index, poly, vertnum); // apply bloom textures - next_index = phosphor_index; + next_index = old_index; next_index = post_pass(rt, next_index, poly, vertnum, false); next_index = bloom_pass(rt, next_index, poly, vertnum); + next_index = phosphor_pass(rt, next_index, poly, vertnum); + next_index = chroma_pass(rt, next_index, poly, vertnum); next_index = distortion_pass(rt, next_index, poly, vertnum); @@ -1826,6 +1909,11 @@ void shaders::delete_resources() delete ntsc_effect; ntsc_effect = nullptr; } + if (chroma_effect != nullptr) + { + delete chroma_effect; + chroma_effect = nullptr; + } if (backbuffer != nullptr) { @@ -1845,6 +1933,8 @@ void shaders::delete_resources() } shadow_bitmap.reset(); + lut_bitmap.reset(); + ui_lut_bitmap.reset(); } @@ -1980,7 +2070,8 @@ hlsl_options shaders::last_options = { false }; enum slider_option { - SLIDER_VECTOR_BEAM_SMOOTH = 0, + SLIDER_UI_LUT_ENABLE = 0, + SLIDER_VECTOR_BEAM_SMOOTH, SLIDER_VECTOR_ATT_MAX, SLIDER_VECTOR_ATT_LEN_MIN, SLIDER_SHADOW_MASK_TILE_MODE, @@ -2019,6 +2110,12 @@ enum slider_option SLIDER_SCALE, SLIDER_POWER, SLIDER_FLOOR, + SLIDER_CHROMA_MODE, + SLIDER_CHROMA_A, + SLIDER_CHROMA_B, + SLIDER_CHROMA_C, + SLIDER_CHROMA_CONVERSION_GAIN, + SLIDER_Y_GAIN, SLIDER_PHOSPHOR, SLIDER_BLOOM_BLEND_MODE, SLIDER_BLOOM_SCALE, @@ -2043,7 +2140,8 @@ enum slider_option SLIDER_NTSC_Y_VALUE, SLIDER_NTSC_I_VALUE, SLIDER_NTSC_Q_VALUE, - SLIDER_NTSC_SCAN_TIME + SLIDER_NTSC_SCAN_TIME, + SLIDER_LUT_ENABLE, }; enum slider_screen_type @@ -2058,6 +2156,7 @@ enum slider_screen_type slider_desc shaders::s_sliders[] = { + { "3D LUT (UI/Artwork)", 0, 0, 1, 1, SLIDER_INT_ENUM, SLIDER_SCREEN_TYPE_ANY, SLIDER_UI_LUT_ENABLE, 0, "%s", { "Off", "On" } }, { "Vector Beam Smooth Amount", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_VECTOR, SLIDER_VECTOR_BEAM_SMOOTH, 0.01f, "%1.2f", {} }, { "Vector Attenuation Maximum", 0, 50, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_VECTOR, SLIDER_VECTOR_ATT_MAX, 0.01f, "%1.2f", {} }, { "Vector Attenuation Length Minimum", 1, 500, 1000, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_VECTOR, SLIDER_VECTOR_ATT_LEN_MIN, 0.001f, "%1.3f", {} }, @@ -2097,6 +2196,12 @@ slider_desc shaders::s_sliders[] = { "Signal Scale,", -200, 100, 200, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_SCALE, 0.01f, "%2.2f", {} }, { "Signal Exponent,", -800, 0, 800, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_POWER, 0.01f, "%2.2f", {} }, { "Signal Floor,", 0, 0, 100, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_FLOOR, 0.01f, "%2.2f", {} }, + { "Color Mode,", 1, 3, 3, 1, SLIDER_INT_ENUM, SLIDER_SCREEN_TYPE_ANY, SLIDER_CHROMA_MODE, 0, "%s", { "", "Monochrome", "Dichrome", "Trichrome" } }, + { "Chroma Conversion Gain,", 0, 0, 10000,10, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_CHROMA_CONVERSION_GAIN, 0.0001f, "%1.4f", {} }, + { "Phosphor A Chromaticity,", 0, 0, 1000,10, SLIDER_VEC2, SLIDER_SCREEN_TYPE_ANY, SLIDER_CHROMA_A, 0.001f, "%1.3f", {} }, + { "Phosphor B Chromaticity,", 0, 0, 1000,10, SLIDER_VEC2, SLIDER_SCREEN_TYPE_ANY, SLIDER_CHROMA_B, 0.001f, "%1.3f", {} }, + { "Phosphor C Chromaticity,", 0, 0, 1000,10, SLIDER_VEC2, SLIDER_SCREEN_TYPE_ANY, SLIDER_CHROMA_C, 0.001f, "%1.3f", {} }, + { "Phosphor Gain,", 0, 0, 10000,10, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_Y_GAIN, 0.0001f, "%1.4f", {} }, { "Phosphor Persistence,", 0, 0, 100, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_ANY, SLIDER_PHOSPHOR, 0.01f, "%2.2f", {} }, { "Bloom Blend Mode", 0, 0, 1, 1, SLIDER_INT_ENUM, SLIDER_SCREEN_TYPE_ANY, SLIDER_BLOOM_BLEND_MODE, 0, "%s", { "Brighten", "Darken" } }, { "Bloom Scale", 0, 0, 2000, 5, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_ANY, SLIDER_BLOOM_SCALE, 0.001f, "%1.3f", {} }, @@ -2122,6 +2227,7 @@ slider_desc shaders::s_sliders[] = { "NTSC I Signal Bandwidth (Hz)", 0, 120, 600, 5, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_NTSC_I_VALUE, 0.01f, "%1.4f", {} }, { "NTSC Q Signal Bandwidth (Hz)", 0, 60, 600, 5, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_NTSC_Q_VALUE, 0.01f, "%1.4f", {} }, { "NTSC Scanline Duration (uSec)", 0, 5260, 10000, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_NTSC_SCAN_TIME, 0.01f, "%1.2f", {} }, + { "3D LUT (Screen)", 0, 0, 1, 1, SLIDER_INT_ENUM, SLIDER_SCREEN_TYPE_ANY, SLIDER_LUT_ENABLE, 0, "%s", { "Off", "On" } }, { nullptr, 0, 0, 0, 0, 0, 0, -1, 0, nullptr, {} } }; @@ -2169,6 +2275,12 @@ void *shaders::get_slider_option(int id, int index) case SLIDER_SCALE: return &(options->scale[index]); case SLIDER_POWER: return &(options->power[index]); case SLIDER_FLOOR: return &(options->floor[index]); + case SLIDER_CHROMA_MODE: return &(options->chroma_mode); + case SLIDER_CHROMA_A: return &(options->chroma_a[index]); + case SLIDER_CHROMA_B: return &(options->chroma_b[index]); + case SLIDER_CHROMA_C: return &(options->chroma_c[index]); + case SLIDER_CHROMA_CONVERSION_GAIN: return &(options->chroma_conversion_gain[index]); + case SLIDER_Y_GAIN: return &(options->chroma_y_gain[index]); case SLIDER_PHOSPHOR: return &(options->phosphor[index]); case SLIDER_BLOOM_BLEND_MODE: return &(options->bloom_blend_mode); case SLIDER_BLOOM_SCALE: return &(options->bloom_scale); @@ -2194,6 +2306,8 @@ void *shaders::get_slider_option(int id, int index) case SLIDER_NTSC_I_VALUE: return &(options->yiq_i); case SLIDER_NTSC_Q_VALUE: return &(options->yiq_q); case SLIDER_NTSC_SCAN_TIME: return &(options->yiq_scan_time); + case SLIDER_LUT_ENABLE: return &(options->lut_enable); + case SLIDER_UI_LUT_ENABLE: return &(options->ui_lut_enable); } return nullptr; } @@ -2458,6 +2572,24 @@ void uniform::update() m_shader->set_vector("Defocus", 2, &options->defocus[0]); break; + case CU_CHROMA_MODE: + m_shader->set_int("ChromaMode", options->chroma_mode); + break; + case CU_CHROMA_A: + m_shader->set_vector("ChromaA", 2, &options->chroma_a[0]); + break; + case CU_CHROMA_B: + m_shader->set_vector("ChromaB", 2, &options->chroma_b[0]); + break; + case CU_CHROMA_C: + m_shader->set_vector("ChromaC", 2, &options->chroma_c[0]); + break; + case CU_CHROMA_CONVERSION_GAIN: + m_shader->set_vector("ConversionGain", 3, &options->chroma_conversion_gain[0]); + case CU_CHROMA_Y_GAIN: + m_shader->set_vector("YGain", 3, &options->chroma_y_gain[0]); + break; + case CU_PHOSPHOR_LIFE: m_shader->set_vector("Phosphor", 3, options->phosphor); break; @@ -2545,6 +2677,11 @@ void uniform::update() case CU_POST_FLOOR: m_shader->set_vector("Floor", 3, options->floor); break; + case CU_LUT_ENABLE: + m_shader->set_bool("LutEnable", options->lut_enable ? true : false); + break; + case CU_UI_LUT_ENABLE: + m_shader->set_bool("UiLutEnable", options->ui_lut_enable ? true : false); } } diff --git a/src/osd/modules/render/d3d/d3dhlsl.h b/src/osd/modules/render/d3d/d3dhlsl.h index eae92ee5b3d..7f7dacc4538 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.h +++ b/src/osd/modules/render/d3d/d3dhlsl.h @@ -101,6 +101,14 @@ public: CU_POST_SCANLINE_BRIGHT_OFFSET, CU_POST_POWER, CU_POST_FLOOR, + CU_CHROMA_MODE, + CU_CHROMA_A, + CU_CHROMA_B, + CU_CHROMA_C, + CU_CHROMA_CONVERSION_GAIN, + CU_CHROMA_Y_GAIN, + CU_LUT_ENABLE, + CU_UI_LUT_ENABLE, CU_COUNT }; @@ -207,6 +215,12 @@ struct hlsl_options float floor[3]; float phosphor[3]; float saturation; + int chroma_mode; + float chroma_a[2]; + float chroma_b[2]; + float chroma_c[2]; + float chroma_conversion_gain[3]; + float chroma_y_gain[3]; // NTSC int yiq_enable; @@ -241,6 +255,12 @@ struct hlsl_options float bloom_level6_weight; float bloom_level7_weight; float bloom_level8_weight; + + // Final + char lut_texture[1024]; + int lut_enable; + char ui_lut_texture[1024]; + int ui_lut_enable; }; struct slider_desc @@ -338,6 +358,7 @@ private: int post_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum, bool prepare_bloom); int downsample_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int bloom_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); + int chroma_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int distortion_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int vector_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int vector_buffer_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); @@ -357,6 +378,10 @@ private: double delta_t; // data for delta_time bitmap_argb32 shadow_bitmap; // shadow mask bitmap for post-processing shader texture_info * shadow_texture; // shadow mask texture for post-processing shader + bitmap_argb32 lut_bitmap; + texture_info * lut_texture; + bitmap_argb32 ui_lut_bitmap; + texture_info * ui_lut_texture; hlsl_options * options; // current options IDirect3DSurface9 * black_surface; // black dummy surface @@ -391,6 +416,7 @@ private: effect * bloom_effect; // pointer to the bloom composite effect effect * downsample_effect; // pointer to the bloom downsample effect effect * vector_effect; // pointer to the vector-effect object + effect * chroma_effect; texture_info * curr_texture; d3d_render_target * curr_render_target; diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp index f33b018f1bf..cb512948b26 100644 --- a/src/osd/windows/winmain.cpp +++ b/src/osd/windows/winmain.cpp @@ -216,6 +216,12 @@ const options_entry windows_options::s_option_entries[] = { WINOPTION_POWER";fs_power", "1.0,1.0,1.0", OPTION_STRING, "signal power value (exponential)" }, { WINOPTION_FLOOR";fs_floor", "0.0,0.0,0.0", OPTION_STRING, "signal floor level" }, { WINOPTION_PHOSPHOR";fs_phosphor", "0.0,0.0,0.0", OPTION_STRING, "phosphorescence decay rate (0.0 is instant, 1.0 is forever)" }, + { WINOPTION_CHROMA_MODE, "3", OPTION_INTEGER, "Number of phosphors to use: 1 - monochrome, 2 - dichrome, 3 - trichrome (color)" }, + { WINOPTION_CHROMA_CONVERSION_GAIN, "0.299,0.587,0.114", OPTION_STRING, "Gain to be applied when summing RGB signal for monochrome and dichrome modes" }, + { WINOPTION_CHROMA_A, "0.64,0.33", OPTION_STRING, "Chromaticity coordinate for first phosphor" }, + { WINOPTION_CHROMA_B, "0.30,0.60", OPTION_STRING, "Chromaticity coordinate for second phosphor" }, + { WINOPTION_CHROMA_C, "0.15,0.06", OPTION_STRING, "Chromaticity coordinate for third phosphor" }, + { WINOPTION_CHROMA_Y_GAIN, "0.2126,0.7152,0.0722", OPTION_STRING, "Gain to be applied for each phosphor" }, /* NTSC simulation below this line */ { nullptr, nullptr, OPTION_HEADER, "NTSC POST-PROCESSING OPTIONS" }, { WINOPTION_YIQ_ENABLE";yiq", "0", OPTION_BOOLEAN, "enables YIQ-space HLSL post-processing" }, @@ -250,6 +256,10 @@ const options_entry windows_options::s_option_entries[] = { WINOPTION_BLOOM_LEVEL6_WEIGHT, "0.04", OPTION_FLOAT, "Bloom level 6 weight (1/4 smaller that level 5 target)" }, { WINOPTION_BLOOM_LEVEL7_WEIGHT, "0.02", OPTION_FLOAT, "Bloom level 7 weight (1/4 smaller that level 6 target)" }, { WINOPTION_BLOOM_LEVEL8_WEIGHT, "0.01", OPTION_FLOAT, "Bloom level 8 weight (1/4 smaller that level 7 target)" }, + { WINOPTION_LUT_TEXTURE, "", OPTION_STRING, "3D LUT texture filename for screen, PNG format" }, + { WINOPTION_LUT_ENABLE, "0", OPTION_BOOLEAN, "Enables 3D LUT to be applied to screen after post-processing" }, + { WINOPTION_UI_LUT_TEXTURE, "", OPTION_STRING, "3D LUT texture filename of UI, PNG format" }, + { WINOPTION_UI_LUT_ENABLE, "0", OPTION_BOOLEAN, "Enables 3D LUT to be applied to UI and artwork after post-processing" }, // full screen options { nullptr, nullptr, OPTION_HEADER, "FULL SCREEN OPTIONS" }, @@ -648,4 +658,3 @@ static int is_double_click_start(int argc) } #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h index 6a0d3421306..79e3b023b64 100644 --- a/src/osd/windows/winmain.h +++ b/src/osd/windows/winmain.h @@ -70,6 +70,12 @@ #define WINOPTION_FLOOR "floor" #define WINOPTION_PHOSPHOR "phosphor_life" #define WINOPTION_SATURATION "saturation" +#define WINOPTION_CHROMA_MODE "chroma_mode" +#define WINOPTION_CHROMA_CONVERSION_GAIN "chroma_conversion_gain" +#define WINOPTION_CHROMA_A "chroma_a" +#define WINOPTION_CHROMA_B "chroma_b" +#define WINOPTION_CHROMA_C "chroma_c" +#define WINOPTION_CHROMA_Y_GAIN "chroma_y_gain" #define WINOPTION_YIQ_ENABLE "yiq_enable" #define WINOPTION_YIQ_JITTER "yiq_jitter" #define WINOPTION_YIQ_CCVALUE "yiq_cc" @@ -98,6 +104,10 @@ #define WINOPTION_BLOOM_LEVEL6_WEIGHT "bloom_lvl6_weight" #define WINOPTION_BLOOM_LEVEL7_WEIGHT "bloom_lvl7_weight" #define WINOPTION_BLOOM_LEVEL8_WEIGHT "bloom_lvl8_weight" +#define WINOPTION_LUT_TEXTURE "lut_texture" +#define WINOPTION_LUT_ENABLE "lut_enable" +#define WINOPTION_UI_LUT_TEXTURE "ui_lut_texture" +#define WINOPTION_UI_LUT_ENABLE "ui_lut_enable" // full screen options #define WINOPTION_TRIPLEBUFFER "triplebuffer" @@ -199,6 +209,16 @@ public: const char *screen_floor() const { return value(WINOPTION_FLOOR); } const char *screen_phosphor() const { return value(WINOPTION_PHOSPHOR); } float screen_saturation() const { return float_value(WINOPTION_SATURATION); } + int screen_chroma_mode() const { return int_value(WINOPTION_CHROMA_MODE); } + const char *screen_chroma_a() const { return value(WINOPTION_CHROMA_A); } + const char *screen_chroma_b() const { return value(WINOPTION_CHROMA_B); } + const char *screen_chroma_c() const { return value(WINOPTION_CHROMA_C); } + const char *screen_chroma_conversion_gain() const { return value(WINOPTION_CHROMA_CONVERSION_GAIN); } + const char *screen_chroma_y_gain() const { return value(WINOPTION_CHROMA_Y_GAIN); } + const char *screen_lut_texture() const { return value(WINOPTION_LUT_TEXTURE); } + bool screen_lut_enable() const { return bool_value(WINOPTION_LUT_ENABLE); } + const char *ui_lut_texture() const { return value(WINOPTION_UI_LUT_TEXTURE); } + bool ui_lut_enable() const { return bool_value(WINOPTION_UI_LUT_ENABLE); } // full screen options bool triple_buffer() const { return bool_value(WINOPTION_TRIPLEBUFFER); }