Skip to content

Commit

Permalink
Scale and phosphor persistence sliders.
Browse files Browse the repository at this point in the history
	hlsl/phosphor.fx: Scale parameter into tau or gamma.

	src/osd/modules/render/d3d/d3dhlsl.cpp:
	src/osd/modules/render/d3d/d3dhlsl.h:
	src/osd/windows/winmain.cpp:
	src/osd/windows/winmain.h: Combine tau and beta sliders into one
slider labeled 'Time Constant'.
  • Loading branch information
anikom15 committed Dec 30, 2016
1 parent b2682b7 commit 7cda486
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 36 deletions.
19 changes: 11 additions & 8 deletions hlsl/phosphor.fx
Expand Up @@ -99,9 +99,8 @@ uniform bool LCD = false;
uniform int Mode = 0;
uniform float DeltaTime = 0.0f;
uniform float LCDTau = 0.0f;
uniform float3 Tau = { 0.0f, 0.0f, 0.0f };
uniform float3 TimeConstant = { 0.0f, 0.0f, 0.0f };
uniform float3 Beta = { 0.0f, 0.0f, 0.0f };
uniform float3 Gamma = { 0.0f, 0.0f, 0.0f };

float4 ps_main(PS_INPUT Input) : COLOR
{
Expand All @@ -122,17 +121,21 @@ float4 ps_main(PS_INPUT Input) : COLOR
b = 0;
}
else if (Mode == 1) {
r *= Tau.r == 0 ? 0 : exp(-DeltaTime / Tau.r);
g *= Tau.g == 0 ? 0 : exp(-DeltaTime / Tau.g);
b *= Tau.b == 0 ? 0 : exp(-DeltaTime / Tau.b);
float3 tau = TimeConstant * 0.4342944819;

r *= tau.r == 0 ? 0 : exp(-DeltaTime / tau.r);
g *= tau.g == 0 ? 0 : exp(-DeltaTime / tau.g);
b *= tau.b == 0 ? 0 : exp(-DeltaTime / tau.b);
}
else {
float3 gamma = 1 / (TimeConstant * 0.04342944819);

if (r != 0.0f)
r = pow(Gamma.r * DeltaTime + pow(1 / r, 1 / Beta.r), -Beta.r);
r = pow(gamma.r * DeltaTime + pow(1 / r, 1 / Beta.r), -Beta.r);
if (g != 0.0f)
g = pow(Gamma.g * DeltaTime + pow(1 / g, 1 / Beta.g), -Beta.g);
g = pow(gamma.g * DeltaTime + pow(1 / g, 1 / Beta.g), -Beta.g);
if (b != 0.0f)
b = pow(Gamma.b * DeltaTime + pow(1 / b, 1 / Beta.b), -Beta.b);
b = pow(gamma.b * DeltaTime + pow(1 / b, 1 / Beta.b), -Beta.b);
}
// Prevent burn-in
if (DeltaTime > 0.0f) {
Expand Down
26 changes: 9 additions & 17 deletions src/osd/modules/render/d3d/d3dhlsl.cpp
Expand Up @@ -520,12 +520,10 @@ bool shaders::init(d3d_base *d3dintf, running_machine *machine, renderer_d3d9 *r
get_vector(winoptions.screen_power(), 3, options->power, true);
get_vector(winoptions.screen_floor(), 3, options->floor, true);
options->phosphor_mode = winoptions.screen_phosphor_mode();
get_vector(winoptions.screen_phosphor_tau(), 3,
options->phosphor_tau, true);
get_vector(winoptions.screen_phosphor_time(), 3,
options->phosphor_time, true);
get_vector(winoptions.screen_phosphor_beta(), 3,
options->phosphor_beta, true);
get_vector(winoptions.screen_phosphor_gamma(), 3,
options->phosphor_gamma, true);
options->lcd_persistence = winoptions.screen_lcd_persistence();
options->saturation = winoptions.screen_saturation();
options->yiq_enable = winoptions.screen_yiq_enable();
Expand Down Expand Up @@ -795,9 +793,8 @@ int shaders::create_resources()
focus_effect->add_uniform("Defocus", uniform::UT_VEC2, uniform::CU_FOCUS_SIZE);

phosphor_effect->add_uniform("Mode", uniform::UT_INT, uniform::CU_PHOSPHOR_MODE);
phosphor_effect->add_uniform("Tau", uniform::UT_VEC3, uniform::CU_PHOSPHOR_TAU);
phosphor_effect->add_uniform("TimeConstant", uniform::UT_VEC3, uniform::CU_PHOSPHOR_TIME);
phosphor_effect->add_uniform("Beta", uniform::UT_VEC3, uniform::CU_PHOSPHOR_BETA);
phosphor_effect->add_uniform("Gamma", uniform::UT_VEC3, uniform::CU_PHOSPHOR_GAMMA);
phosphor_effect->add_uniform("LCDTau", uniform::UT_FLOAT, uniform::CU_LCD_PERSISTENCE);

post_effect->add_uniform("ShadowAlpha", uniform::UT_FLOAT, uniform::CU_POST_SHADOW_ALPHA);
Expand Down Expand Up @@ -1968,9 +1965,8 @@ enum slider_option
SLIDER_POWER,
SLIDER_FLOOR,
SLIDER_PHOSPHOR_MODE,
SLIDER_PHOSPHOR_TAU,
SLIDER_PHOSPHOR_TIME,
SLIDER_PHOSPHOR_BETA,
SLIDER_PHOSPHOR_GAMMA,
SLIDER_LCD_PERSISTENCE,
SLIDER_BLOOM_BLEND_MODE,
SLIDER_BLOOM_SCALE,
Expand Down Expand Up @@ -2051,9 +2047,8 @@ slider_desc shaders::s_sliders[] =
{ "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", {} },
{ "Phosphor Persistence Mode,", 0, 0, 2, 1, SLIDER_INT_ENUM, SLIDER_SCREEN_TYPE_RASTER_OR_VECTOR, SLIDER_PHOSPHOR_MODE, 0, "%s", { "Off", "Exponential", "Inverse Power" } },
{ "Phosphor Persistence tau,", 1, 26, 100, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_RASTER_OR_VECTOR, SLIDER_PHOSPHOR_TAU, 0.001f, "%3.3f", {} },
{ "Phosphor Persistence beta,", 50, 70, 200, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_RASTER_OR_VECTOR, SLIDER_PHOSPHOR_BETA, 0.01f, "%2.2f", {} },
{ "Phosphor Persistence gamma,", 1, 300, 1000, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_RASTER_OR_VECTOR, SLIDER_PHOSPHOR_GAMMA, 1, "%.0f", {} },
{ "Phosphor Persistence Time Constant,",1, 5000, 10000,10, SLIDER_COLOR, SLIDER_SCREEN_TYPE_RASTER_OR_VECTOR, SLIDER_PHOSPHOR_TIME, 0.0001f, "%4.4f", {} },
{ "Phosphor Persistence beta,", 50, 100, 200, 1, SLIDER_COLOR, SLIDER_SCREEN_TYPE_RASTER_OR_VECTOR, SLIDER_PHOSPHOR_BETA, 0.01f, "%2.2f", {} },
{ "LCD Perisistence,", 0, 20, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD, SLIDER_LCD_PERSISTENCE, 0.001f, "%3.3f", {} },
{ "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", {} },
Expand Down Expand Up @@ -2127,9 +2122,8 @@ void *shaders::get_slider_option(int id, int index)
case SLIDER_POWER: return &(options->power[index]);
case SLIDER_FLOOR: return &(options->floor[index]);
case SLIDER_PHOSPHOR_MODE: return &(options->phosphor_mode);
case SLIDER_PHOSPHOR_TAU: return &(options->phosphor_tau[index]);
case SLIDER_PHOSPHOR_TIME: return &(options->phosphor_time[index]);
case SLIDER_PHOSPHOR_BETA: return &(options->phosphor_beta[index]);
case SLIDER_PHOSPHOR_GAMMA: return &(options->phosphor_gamma[index]);
case SLIDER_LCD_PERSISTENCE: return &(options->lcd_persistence);
case SLIDER_BLOOM_BLEND_MODE: return &(options->bloom_blend_mode);
case SLIDER_BLOOM_SCALE: return &(options->bloom_scale);
Expand Down Expand Up @@ -2420,14 +2414,12 @@ void uniform::update()
case CU_PHOSPHOR_MODE:
m_shader->set_int("Mode", options->phosphor_mode);
break;
case CU_PHOSPHOR_TAU:
m_shader->set_vector("Tau", 3, options->phosphor_tau);
case CU_PHOSPHOR_TIME:
m_shader->set_vector("TimeConstant", 3, options->phosphor_time);
break;
case CU_PHOSPHOR_BETA:
m_shader->set_vector("Beta", 3, options->phosphor_beta);
break;
case CU_PHOSPHOR_GAMMA:
m_shader->set_vector("Gamma", 3, options->phosphor_gamma);

case CU_LCD_PERSISTENCE:
m_shader->set_float("LCDTau", options->lcd_persistence);
Expand Down
6 changes: 2 additions & 4 deletions src/osd/modules/render/d3d/d3dhlsl.h
Expand Up @@ -78,9 +78,8 @@ class uniform
CU_FOCUS_SIZE,

CU_PHOSPHOR_MODE,
CU_PHOSPHOR_TAU,
CU_PHOSPHOR_TIME,
CU_PHOSPHOR_BETA,
CU_PHOSPHOR_GAMMA,

CU_LCD_PERSISTENCE,

Expand Down Expand Up @@ -209,9 +208,8 @@ struct hlsl_options
float power[3];
float floor[3];
int phosphor_mode;
float phosphor_tau[3];
float phosphor_time[3];
float phosphor_beta[3];
float phosphor_gamma[3];
float lcd_persistence;
float saturation;

Expand Down
5 changes: 2 additions & 3 deletions src/osd/windows/winmain.cpp
Expand Up @@ -216,9 +216,8 @@ 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_MODE";fs_phosphor_mode", "0", OPTION_STRING, "phosphorescence decay mode (0: off, 1: exponential, 2: inverse-power)" },
{ WINOPTION_PHOSPHOR_TAU";fs_phosphor_tau", "0.026,0.026,0.026", OPTION_STRING, "exponential time constant" },
{ WINOPTION_PHOSPHOR_BETA";fs_phosphor_beta", "0.7,0.7,0.7", OPTION_STRING, "inverse power order" },
{ WINOPTION_PHOSPHOR_GAMMA";fs_phosphor_gamma", "300,300,300", OPTION_STRING, "inverse power time constant" },
{ WINOPTION_PHOSPHOR_TIME";fs_phosphor_time", "0.5,0.5,0.5", OPTION_STRING, "exponential time constant" },
{ WINOPTION_PHOSPHOR_BETA";fs_phosphor_beta", "1.0,1.0,1.0", OPTION_STRING, "inverse power order" },
{ WINOPTION_LCD_PERSISTENCE";fs_lcd_persistence", "0.02", OPTION_STRING, "LCD pixel persistence time constant" },
/* NTSC simulation below this line */
{ nullptr, nullptr, OPTION_HEADER, "NTSC POST-PROCESSING OPTIONS" },
Expand Down
6 changes: 2 additions & 4 deletions src/osd/windows/winmain.h
Expand Up @@ -69,9 +69,8 @@
#define WINOPTION_POWER "power"
#define WINOPTION_FLOOR "floor"
#define WINOPTION_PHOSPHOR_MODE "phosphor_mode"
#define WINOPTION_PHOSPHOR_TAU "phosphor_tau"
#define WINOPTION_PHOSPHOR_TIME "phosphor_time"
#define WINOPTION_PHOSPHOR_BETA "phosphor_beta"
#define WINOPTION_PHOSPHOR_GAMMA "phosphor_gamma"
#define WINOPTION_LCD_PERSISTENCE "lcd_persistence"
#define WINOPTION_SATURATION "saturation"
#define WINOPTION_YIQ_ENABLE "yiq_enable"
Expand Down Expand Up @@ -202,9 +201,8 @@ class windows_options : public osd_options
const char *screen_power() const { return value(WINOPTION_POWER); }
const char *screen_floor() const { return value(WINOPTION_FLOOR); }
int screen_phosphor_mode() const { return int_value(WINOPTION_PHOSPHOR_MODE); }
const char* screen_phosphor_tau() const { return value(WINOPTION_PHOSPHOR_TAU); }
const char* screen_phosphor_time() const { return value(WINOPTION_PHOSPHOR_TIME); }
const char* screen_phosphor_beta() const { return value(WINOPTION_PHOSPHOR_BETA); }
const char* screen_phosphor_gamma() const { return value(WINOPTION_PHOSPHOR_GAMMA); }
float screen_lcd_persistence() const { return float_value(WINOPTION_LCD_PERSISTENCE); }
float screen_saturation() const { return float_value(WINOPTION_SATURATION); }

Expand Down

0 comments on commit 7cda486

Please sign in to comment.