summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Westley M. Martinez <anikom15@gmail.com>2016-12-11 12:01:43 -0800
committer Westley M. Martinez <anikom15@gmail.com>2016-12-11 12:01:43 -0800
commiteba9550c42f6b12d563ead1412d6a67bfb78bd00 (patch)
treea3bd3f74c7277743ff16ff3426eb67a3914aa83f
parent8daa648671105c91373bf2e34eff1bb2af8001d5 (diff)
Fix phosphor persistence shader behavior based on time.
hlsl/phosphor.fx: Add calculation time passed to be used by shader. src/osd/modules/render/d3d/d3dhlsl.cpp: Make pixel shader calculate the current pixel by factoring in the amount of time which has passed since the last rendering.
-rw-r--r--hlsl/phosphor.fx12
-rw-r--r--src/osd/modules/render/d3d/d3dhlsl.cpp10
2 files changed, 18 insertions, 4 deletions
diff --git a/hlsl/phosphor.fx b/hlsl/phosphor.fx
index 7d665b44749..40bc049bbc2 100644
--- a/hlsl/phosphor.fx
+++ b/hlsl/phosphor.fx
@@ -94,19 +94,23 @@ VS_OUTPUT vs_main(VS_INPUT Input)
//-----------------------------------------------------------------------------
uniform float3 Phosphor = float3(0.0f, 0.0f, 0.0f);
+uniform float dt = 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 * dt);
+ PrevPix.g *= Phosphor.g == 0 ? 0 : pow(Phosphor.g, f * dt);
+ PrevPix.b *= Phosphor.b == 0 ? 0 : pow(Phosphor.b, f * dt);
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);
}
//-----------------------------------------------------------------------------
diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp
index dff6082745e..18234b4ba82 100644
--- a/src/osd/modules/render/d3d/d3dhlsl.cpp
+++ b/src/osd/modules/render/d3d/d3dhlsl.cpp
@@ -28,6 +28,7 @@
#undef min
#undef max
#include <utility>
+#include <iostream>
//============================================================
// PROTOTYPES
@@ -1061,7 +1062,11 @@ int shaders::defocus_pass(d3d_render_target *rt, int source_index, poly_info *po
int shaders::phosphor_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum)
{
+ static double ct = 0;
+
int next_index = source_index;
+ float dt;
+ double t;
// skip phosphor if no influencing settings
if (options->phosphor[0] == 0.0f && options->phosphor[1] == 0.0f && options->phosphor[2] == 0.0f)
@@ -1069,11 +1074,16 @@ int shaders::phosphor_pass(d3d_render_target *rt, int source_index, poly_info *p
return next_index;
}
+ // Shader needs time between last update
+ t = machine->time().as_double();
+ dt = (float) (t - ct);
+ ct = t;
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("dt", dt);
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);