Merge pull request #1826 from anikom15/hlsl

Make phosphor persistence independent of frame rate
This commit is contained in:
R. Belmont 2016-12-13 22:48:22 -05:00 committed by GitHub
commit d43a87e92e
3 changed files with 29 additions and 14 deletions

View File

@ -94,19 +94,23 @@ VS_OUTPUT vs_main(VS_INPUT Input)
//-----------------------------------------------------------------------------
uniform float3 Phosphor = float3(0.0f, 0.0f, 0.0f);
uniform float DeltaTime = 0.0f;
static const float F = 30.0f;
float4 ps_main(PS_INPUT Input) : COLOR
{
float4 CurrPix = tex2D(DiffuseSampler, Input.TexCoord);
float3 PrevPix = tex2D(PreviousSampler, Input.PrevCoord).rgb * float3(Phosphor.r, Phosphor.g, Phosphor.b);
float3 PrevPix = 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);
return Passthrough ?
CurrPix : float4(RedMax, GreenMax, BlueMax, CurrPix.a);
}
//-----------------------------------------------------------------------------

View File

@ -164,14 +164,15 @@ private:
shaders::shaders() :
d3dintf(nullptr), machine(nullptr), d3d(nullptr), post_fx_enable(false), oversampling_enable(false),
num_screens(0), curr_screen(0), shadow_texture(nullptr), options(nullptr), black_surface(nullptr),
black_texture(nullptr), recording_movie(false), render_snap(false), snap_copy_target(nullptr),
snap_copy_texture(nullptr), snap_target(nullptr), snap_texture(nullptr), snap_width(0), snap_height(0),
initialized(false), backbuffer(nullptr), curr_effect(nullptr), default_effect(nullptr),
prescale_effect(nullptr), post_effect(nullptr), distortion_effect(nullptr), focus_effect(nullptr),
phosphor_effect(nullptr), deconverge_effect(nullptr), color_effect(nullptr), ntsc_effect(nullptr),
bloom_effect(nullptr), downsample_effect(nullptr), vector_effect(nullptr), curr_texture(nullptr),
curr_render_target(nullptr), curr_poly(nullptr), d3dx_create_effect_from_file_ptr(nullptr)
num_screens(0), curr_screen(0), acc_t(0), delta_t(0), shadow_texture(nullptr), options(nullptr),
black_surface(nullptr), black_texture(nullptr), recording_movie(false), render_snap(false),
snap_copy_target(nullptr), snap_copy_texture(nullptr), snap_target(nullptr), snap_texture(nullptr),
snap_width(0), snap_height(0), initialized(false), backbuffer(nullptr), curr_effect(nullptr),
default_effect(nullptr), prescale_effect(nullptr), post_effect(nullptr), distortion_effect(nullptr),
focus_effect(nullptr), phosphor_effect(nullptr), deconverge_effect(nullptr), color_effect(nullptr),
ntsc_effect(nullptr), bloom_effect(nullptr), downsample_effect(nullptr), vector_effect(nullptr),
curr_texture(nullptr), curr_render_target(nullptr), curr_poly(nullptr),
d3dx_create_effect_from_file_ptr(nullptr)
{
}
@ -819,6 +820,8 @@ int shaders::create_resources()
void shaders::begin_draw()
{
double t;
if (!enabled())
{
return;
@ -826,6 +829,10 @@ void shaders::begin_draw()
curr_screen = 0;
curr_effect = default_effect;
// Update for delta_time
t = machine->time().as_double();
delta_t = t - acc_t;
acc_t = t;
default_effect->set_technique("ScreenTechnique");
post_effect->set_technique("DefaultTechnique");
@ -900,7 +907,6 @@ void shaders::blit(
curr_effect->end();
}
//============================================================
// shaders::find_render_target
//============================================================
@ -1069,11 +1075,13 @@ int shaders::phosphor_pass(d3d_render_target *rt, int source_index, poly_info *p
return next_index;
}
// Shader needs time between last update
curr_effect = phosphor_effect;
curr_effect->update_uniforms();
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
curr_effect->set_texture("LastPass", rt->cache_texture);
curr_effect->set_bool("Passthrough", false);
curr_effect->set_float("DeltaTime", delta_time());
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);

View File

@ -319,7 +319,8 @@ private:
void enumerate_screens();
void render_snapshot(IDirect3DSurface9 *surface);
// Time since last call, only updates once per render of all screens
double delta_time() { return delta_t; }
d3d_render_target* find_render_target(int source_width, int source_height, uint32_t screen_index);
rgb_t apply_color_convolution(rgb_t color);
@ -349,6 +350,8 @@ private:
bool oversampling_enable; // oversampling enable flag
int num_screens; // number of emulated physical screens
int curr_screen; // current screen for render target operations
double acc_t; // accumulated machine time
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
hlsl_options * options; // current options