Port scanline modification to BGFX

This commit is contained in:
W. M. Martinez 2018-09-14 19:00:52 -07:00
parent e04d852034
commit b4888aabc0
21 changed files with 184 additions and 57 deletions

View file

@ -390,6 +390,29 @@
],
"output": "internal"
},
{
"effect": "hlsl/scanline",
"name": "Scanline Pass",
"disablewhen": [
{ "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 },
{ "type": "slider", "condition": "equal", "combine": "or", "name": "scanline_alpha", "value": 0 }
],
"uniforms": [
{ "uniform": "u_scanline_alpha", "slider": "scanline_alpha" },
{ "uniform": "u_scanline_scale", "slider": "scanline_scale" },
{ "uniform": "u_scanline_bright_scale", "slider": "scanline_bright_scale" },
{ "uniform": "u_scanline_bright_offset", "slider": "scanline_bright_offset" },
{ "uniform": "u_scanline_height", "slider": "scanline_height" },
{ "uniform": "u_scanline_variation", "slider": "scanline_variation" },
{ "uniform": "u_scanline_jitter", "slider": "scanline_jitter_amount" },
{ "uniform": "u_jitter_amount", "parameter": "jitter" },
{ "uniform": "u_time", "parameter": "time" }
],
"input": [
{ "sampler": "s_tex", "target": "internal" }
],
"output": "internal"
},
{ "effect": "hlsl/defocus",
"name": "Defocus Pass",
"disablewhen": [
@ -440,19 +463,12 @@
"name": "Non-Bloom Post Pass",
"disablewhen": [
{ "type": "slider", "condition": "equal", "combine": "or", "name": "adjustments", "value": 0 },
{ "type": "slider", "condition": "equal", "combine": "and", "name": "scanline_alpha", "value": 0.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_scanline_alpha", "slider": "scanline_alpha" },
{ "uniform": "u_scanline_scale", "slider": "scanline_scale" },
{ "uniform": "u_scanline_bright_scale", "slider": "scanline_bright_scale" },
{ "uniform": "u_scanline_bright_offset", "slider": "scanline_bright_offset" },
{ "uniform": "u_scanline_height", "slider": "scanline_height" },
{ "uniform": "u_scanline_variation", "slider": "scanline_variation" },
{ "uniform": "u_shadow_tile_mode", "slider": "shadow_tile_mode" },
{ "uniform": "u_shadow_alpha", "slider": "shadow_alpha" },
{ "uniform": "u_shadow_count", "slider": "shadow_uv_count" },
@ -462,8 +478,6 @@
{ "uniform": "u_humbar_hertz_rate", "slider": "humbar_hertz_rate" },
{ "uniform": "u_floor", "slider": "floor" },
{ "uniform": "u_power", "slider": "power" },
{ "uniform": "u_scanline_jitter", "slider": "scanline_jitter_amount" },
{ "uniform": "u_jitter_amount", "parameter": "jitter" },
{ "uniform": "u_time", "parameter": "time" }
],
"input": [

View file

@ -2,7 +2,7 @@
// copyright-holders:Ryan Holtz,ImJezze
//============================================================
//
// post.json: Scanline, hum-bar, shadow-mask, and final
// post.json: Hum-bar, shadow-mask, and final
// color convolution shader for CRT simulation.
//
//============================================================
@ -31,21 +31,12 @@
{ "name": "u_source_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_target_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_target_scale", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_humbar_hertz_rate", "type": "vec4", "values": [ 0.001, 0.0, 0.0, 0.0 ] },
{ "name": "u_humbar_alpha", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_time", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_screen_scale", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_screen_offset", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_shadow_tile_mode", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_alpha", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_scale", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_bright_scale", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_bright_offset", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_jitter", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_height", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_variation", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_jitter_amount", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_shadow_alpha", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_shadow_count", "type": "vec4", "values": [ 12.0, 12.0, 0.0, 0.0 ] },
{ "name": "u_shadow_uv", "type": "vec4", "values": [ 0.25, 0.25, 0.0, 0.0 ] },

View file

@ -0,0 +1,44 @@
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz,ImJezze
//============================================================
//
// scanline.json: Scanline shader for CRT simulation.
//
//============================================================
{
"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_scanline",
"fragment": "chains/hlsl/fs_scanline",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 0.0 ] },
{ "name": "u_swap_xy", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_source_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_target_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_quad_dims", "type": "vec4", "values": [ 256.0, 256.0, 0.0, 0.0 ] },
{ "name": "u_time", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_screen_scale", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] },
{ "name": "u_screen_offset", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_alpha", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_scale", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_bright_scale", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_bright_offset", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_jitter", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_height", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_scanline_variation", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_jitter_amount", "type": "vec4", "values": [ 0.0, 0.0, 0.0, 0.0 ] }
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -13,19 +13,11 @@ uniform vec4 u_swap_xy;
uniform vec4 u_source_dims; // size of the guest machine
uniform vec4 u_target_dims;
uniform vec4 u_target_scale;
uniform vec4 u_quad_dims;
uniform vec4 u_screen_scale;
uniform vec4 u_screen_offset;
// uniform vec4 u_back_color; // TODO
// User-supplied
uniform vec4 u_scanline_alpha;
uniform vec4 u_scanline_scale;
uniform vec4 u_scanline_bright_scale;
uniform vec4 u_scanline_bright_offset;
uniform vec4 u_scanline_jitter;
uniform vec4 u_scanline_height;
uniform vec4 u_scanline_variation;
uniform vec4 u_shadow_tile_mode;
uniform vec4 u_shadow_alpha;
uniform vec4 u_shadow_count;
@ -38,14 +30,13 @@ uniform vec4 u_floor;
// Parametric
uniform vec4 u_time; // milliseconds
uniform vec4 u_jitter_amount;
// Samplers
SAMPLER2D(s_tex, 0);
SAMPLER2D(s_shadow, 1);
//-----------------------------------------------------------------------------
// Scanline & Shadowmask Pixel Shader
// Shadowmask Pixel Shader
//-----------------------------------------------------------------------------
vec2 GetAdjustedCoords(vec2 coord)
@ -148,34 +139,6 @@ void main()
BaseColor.g = pow(BaseColor.g, u_power.g);
BaseColor.b = pow(BaseColor.b, u_power.b);
// Scanline Simulation
if (u_scanline_alpha.x > 0.0f)
{
float BrightnessOffset = (u_scanline_bright_offset.x * u_scanline_alpha.x);
float BrightnessScale = (u_scanline_bright_scale.x * u_scanline_alpha.x) + (1.0 - u_scanline_alpha.x);
float ColorBrightness = 0.299 * BaseColor.r + 0.587 * BaseColor.g + 0.114 * BaseColor.b;
float ScanCoord = BaseCoord.y;
ScanCoord += u_swap_xy.x > 0.0
? u_quad_dims.x <= u_source_dims.x * 2.0
? 0.5 / u_quad_dims.x // uncenter scanlines if the quad is less than twice the size of the source
: 0.0
: u_quad_dims.y <= u_source_dims.y * 2.0
? 0.5 / u_quad_dims.y // uncenter scanlines if the quad is less than twice the size of the source
: 0.0;
ScanCoord *= u_source_dims.y * u_scanline_scale.x * 3.1415927; // PI
float ScanCoordJitter = u_scanline_jitter.x * u_jitter_amount.x * 1.5707963; // half PI
float ScanSine = sin(ScanCoord + ScanCoordJitter);
float ScanlineWide = u_scanline_height.x + u_scanline_variation.x * max(1.0, u_scanline_height.x) * (1.0 - ColorBrightness);
float ScanSineScaled = pow(ScanSine * ScanSine, ScanlineWide);
float ScanBrightness = ScanSineScaled * BrightnessScale + BrightnessOffset * BrightnessScale;
BaseColor.rgb *= mix(vec3(1.0, 1.0, 1.0), vec3(ScanBrightness, ScanBrightness, ScanBrightness), u_scanline_alpha.xxx);
}
// Hum Bar Simulation
if (u_humbar_alpha.x > 0.0f)
{

View file

@ -0,0 +1,101 @@
$input v_color0, v_texcoord0
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz,ImJezze
//-----------------------------------------------------------------------------
// Scanline Effect
//-----------------------------------------------------------------------------
#include "common.sh"
// Autos
uniform vec4 u_swap_xy;
uniform vec4 u_source_dims; // size of the guest machine
uniform vec4 u_target_dims;
uniform vec4 u_quad_dims;
uniform vec4 u_screen_scale;
uniform vec4 u_screen_offset;
// User-supplied
uniform vec4 u_scanline_alpha;
uniform vec4 u_scanline_scale;
uniform vec4 u_scanline_bright_scale;
uniform vec4 u_scanline_bright_offset;
uniform vec4 u_scanline_jitter;
uniform vec4 u_scanline_height;
uniform vec4 u_scanline_variation;
// Parametric
uniform vec4 u_time; // milliseconds
uniform vec4 u_jitter_amount;
// Samplers
SAMPLER2D(s_tex, 0);
SAMPLER2D(s_shadow, 1);
//-----------------------------------------------------------------------------
// Scanline Pixel Shader
//-----------------------------------------------------------------------------
vec2 GetAdjustedCoords(vec2 coord)
{
// center coordinates
coord -= 0.5;
// apply screen scale
coord *= u_screen_scale.xy;
// un-center coordinates
coord += 0.5;
// apply screen offset
coord += u_screen_offset.xy;
return coord;
}
void main()
{
vec2 BaseCoord = GetAdjustedCoords(v_texcoord0);
// Color
vec4 BaseColor = texture2D(s_tex, BaseCoord);
// Clamp
if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0 || BaseCoord.x > 1.0 || BaseCoord.y > 1.0)
{
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
}
else
{
// Scanline Simulation
if (u_scanline_alpha.x > 0.0f)
{
float BrightnessOffset = (u_scanline_bright_offset.x * u_scanline_alpha.x);
float BrightnessScale = (u_scanline_bright_scale.x * u_scanline_alpha.x) + (1.0 - u_scanline_alpha.x);
float ColorBrightness = 0.299 * BaseColor.r + 0.587 * BaseColor.g + 0.114 * BaseColor.b;
float ScanCoord = BaseCoord.y;
ScanCoord += u_swap_xy.x > 0.0
? u_quad_dims.x <= u_source_dims.x * 2.0
? 0.5 / u_quad_dims.x // uncenter scanlines if the quad is less than twice the size of the source
: 0.0
: u_quad_dims.y <= u_source_dims.y * 2.0
? 0.5 / u_quad_dims.y // uncenter scanlines if the quad is less than twice the size of the source
: 0.0;
ScanCoord *= u_source_dims.y * u_scanline_scale.x * 3.1415927; // PI
float ScanCoordJitter = u_scanline_jitter.x * u_jitter_amount.x * 1.5707963; // half PI
float ScanSine = sin(ScanCoord + ScanCoordJitter);
float ScanlineWide = u_scanline_height.x + u_scanline_variation.x * max(1.0, u_scanline_height.x) * (1.0 - ColorBrightness);
float ScanSineScaled = pow(ScanSine * ScanSine, ScanlineWide);
float ScanBrightness = ScanSineScaled * BrightnessScale + BrightnessOffset * BrightnessScale;
BaseColor.rgb *= mix(vec3(1.0, 1.0, 1.0), vec3(ScanBrightness, ScanBrightness, ScanBrightness), u_scanline_alpha.xxx);
}
gl_FragColor = vec4(BaseColor.rgb * v_color0.rgb, BaseColor.a);
}
}

View file

@ -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;
}