mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
Fixed scanlines, nwn. This took much longer to fix than it should have. :[
This commit is contained in:
parent
37e8c1d7e4
commit
ed6689e2d4
@ -72,6 +72,8 @@ uniform float GrnRadialConvergeY;
|
||||
uniform float BluRadialConvergeX;
|
||||
uniform float BluRadialConvergeY;
|
||||
|
||||
uniform float Prescale;
|
||||
|
||||
VS_OUTPUT vs_main(VS_INPUT Input)
|
||||
{
|
||||
VS_OUTPUT Output = (VS_OUTPUT)0;
|
||||
@ -115,23 +117,20 @@ float4 ps_main(PS_INPUT Input) : COLOR
|
||||
Deconverge = 1.0f;//clamp(Deconverge, 0.0f, 1.0f);
|
||||
float Alpha = tex2D(DiffuseSampler, Input.TexCoord).a;
|
||||
|
||||
float2 RawDims = float2(RawWidth, RawHeight);
|
||||
float2 TexCoord = Input.TexCoord * RawDims;
|
||||
float2 RedCoord = Input.RedCoord * RawDims;
|
||||
float2 GrnCoord = Input.GrnCoord * RawDims;
|
||||
float2 BluCoord = Input.BluCoord * RawDims;
|
||||
TexCoord.y = TexCoord.y - frac(TexCoord.y);
|
||||
RedCoord.y = RedCoord.y - frac(RedCoord.y);
|
||||
GrnCoord.y = GrnCoord.y - frac(GrnCoord.y);
|
||||
BluCoord.y = BluCoord.y - frac(BluCoord.y);
|
||||
float2 TargetDims = float2(RawWidth * Prescale, RawHeight * Prescale);
|
||||
float2 DimOffset = 0.5f / TargetDims;
|
||||
float2 TexCoord = Input.TexCoord;
|
||||
float2 RedCoord = Input.RedCoord;
|
||||
float2 GrnCoord = Input.GrnCoord;
|
||||
float2 BluCoord = Input.BluCoord;
|
||||
|
||||
RedCoord = lerp(TexCoord, RedCoord, Deconverge) / RawDims;
|
||||
GrnCoord = lerp(TexCoord, GrnCoord, Deconverge) / RawDims;
|
||||
BluCoord = lerp(TexCoord, BluCoord, Deconverge) / RawDims;
|
||||
RedCoord = lerp(TexCoord, RedCoord, Deconverge);
|
||||
GrnCoord = lerp(TexCoord, GrnCoord, Deconverge);
|
||||
BluCoord = lerp(TexCoord, BluCoord, Deconverge);
|
||||
|
||||
float RedTexel = tex2D(DiffuseSampler, RedCoord + float2(0.0f, 0.5f) / RawDims).r;
|
||||
float GrnTexel = tex2D(DiffuseSampler, GrnCoord + float2(0.0f, 0.5f) / RawDims).g;
|
||||
float BluTexel = tex2D(DiffuseSampler, BluCoord + float2(0.0f, 0.5f) / RawDims).b;
|
||||
float RedTexel = tex2D(DiffuseSampler, RedCoord - DimOffset).r;
|
||||
float GrnTexel = tex2D(DiffuseSampler, GrnCoord - DimOffset).g;
|
||||
float BluTexel = tex2D(DiffuseSampler, BluCoord - DimOffset).b;
|
||||
|
||||
//RedTexel *= Input.RedCoord.x < (WidthRatio / RawWidth) ? 0.0f : 1.0f;
|
||||
//RedTexel *= Input.RedCoord.y < (HeightRatio / RawHeight) ? 0.0f : 1.0f;
|
||||
|
@ -79,7 +79,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
|
||||
|
||||
float2 InvTexSize = float2(1.0f / TargetWidth, 1.0f / TargetHeight);
|
||||
Output.TexCoord = Input.TexCoord + 0.5f * InvTexSize;
|
||||
Output.PrevCoord = Input.TexCoord + 0.5f * InvTexSize;
|
||||
Output.PrevCoord = Input.TexCoord;// + 0.5f * InvTexSize;
|
||||
|
||||
return Output;
|
||||
}
|
||||
@ -101,7 +101,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
|
||||
float GreenMax = max(CurrPix.g, PrevPix.g);
|
||||
float BlueMax = max(CurrPix.b, PrevPix.b);
|
||||
|
||||
return float4(RedMax, GreenMax, BlueMax, CurrPix.a);
|
||||
return CurrPix;//float4(RedMax, GreenMax, BlueMax, CurrPix.a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
21
hlsl/post.fx
21
hlsl/post.fx
@ -128,21 +128,18 @@ float4 ps_main(PS_INPUT Input) : COLOR
|
||||
float2 PinUnitCoord = (Input.TexCoord + PinViewpointOffset) * Ratios * 2.0f - 1.0f;
|
||||
float PincushionR2 = pow(length(PinUnitCoord), 2.0f) / pow(length(Ratios), 2.0f);
|
||||
float2 PincushionCurve = PinUnitCoord * PincushionAmount * PincushionR2;
|
||||
float2 BaseCoord = Input.TexCoord + float2(0.0f, 0.0f / TargetHeight);
|
||||
BaseCoord.y *= TargetHeight;
|
||||
BaseCoord.y -= frac(BaseCoord.y);
|
||||
BaseCoord.y += 0.5f;
|
||||
BaseCoord.y /= TargetHeight;
|
||||
float2 BaseCoord = Input.TexCoord;
|
||||
float2 ScanCoord = BaseCoord - 0.5f / (float2(RawWidth, RawHeight) * Ratios);
|
||||
|
||||
BaseCoord -= 0.5f / Ratios;
|
||||
BaseCoord *= 1.0f - PincushionAmount * Ratios * 0.2f; // Warning: Magic constant
|
||||
BaseCoord += 0.5f / Ratios;
|
||||
BaseCoord += PincushionCurve;
|
||||
|
||||
float2 CurveViewpointOffset = float2(0.2f, 0.0f);
|
||||
float2 CurveUnitCoord = (Input.TexCoord + CurveViewpointOffset) * 2.0f - 1.0f;
|
||||
float CurvatureR2 = pow(length(CurveUnitCoord),2.0f) / pow(length(Ratios), 2.0f);
|
||||
float2 CurvatureCurve = CurveUnitCoord * CurvatureAmount * CurvatureR2;
|
||||
float2 ScreenCurveCoord = Input.TexCoord + CurvatureCurve;
|
||||
ScanCoord -= 0.5f / Ratios;
|
||||
ScanCoord *= 1.0f - PincushionAmount * Ratios * 0.2f; // Warning: Magic constant
|
||||
ScanCoord += 0.5f / Ratios;
|
||||
ScanCoord += PincushionCurve;
|
||||
|
||||
float2 CurveClipUnitCoord = Input.TexCoord * Ratios * 2.0f - 1.0f;
|
||||
float CurvatureClipR2 = pow(length(CurveClipUnitCoord),2.0f) / pow(length(Ratios), 2.0f);
|
||||
@ -166,9 +163,9 @@ float4 ps_main(PS_INPUT Input) : COLOR
|
||||
clip((BaseCoord.y > (1.0f / HeightRatio + 1.0f / RawHeight)) ? -1 : 1);
|
||||
|
||||
// -- Scanline Simulation --
|
||||
float InnerSine = BaseCoord.y * RawHeight * ScanlineScale;
|
||||
float InnerSine = ScanCoord.y * RawHeight * ScanlineScale;
|
||||
float ScanBrightMod = sin(InnerSine * PI + ScanlineOffset * RawHeight);
|
||||
float3 ScanBrightness = lerp(1.0f, pow(ScanBrightMod * ScanBrightMod, ScanlineHeight) * ScanlineBrightScale + 1.0f, ScanlineAmount);
|
||||
float3 ScanBrightness = lerp(1.0f, (pow(ScanBrightMod * ScanBrightMod, ScanlineHeight) * ScanlineBrightScale + 1.0f) * 0.5f, ScanlineAmount);
|
||||
float3 Scanned = BaseTexel.rgb * ScanBrightness;
|
||||
|
||||
// -- Color Compression (increasing the floor of the signal without affecting the ceiling) --
|
||||
|
@ -59,7 +59,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
|
||||
Output.Position.y -= 0.5f;
|
||||
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
|
||||
|
||||
Output.TexCoord = Input.TexCoord + 0.5f / float2(RawWidth, RawHeight);
|
||||
Output.TexCoord = Input.TexCoord;
|
||||
|
||||
return Output;
|
||||
}
|
||||
@ -70,7 +70,12 @@ VS_OUTPUT vs_main(VS_INPUT Input)
|
||||
|
||||
float4 ps_main(PS_INPUT Input) : COLOR
|
||||
{
|
||||
float4 Center = tex2D(DiffuseSampler, Input.TexCoord);
|
||||
float2 RawDims = float2(RawWidth, RawHeight);
|
||||
float2 TexCoord = Input.TexCoord * RawDims;
|
||||
TexCoord -= frac(float2(0.0f, TexCoord.y));
|
||||
TexCoord /= RawDims;
|
||||
|
||||
float4 Center = tex2D(DiffuseSampler, TexCoord);
|
||||
return Center;
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,6 @@ struct _d3d_info
|
||||
|
||||
bool hlsl_enable; // HLSL enable flag
|
||||
bool yiq_enable; // HLSL YIQ-convolution flag
|
||||
bool hlsl_prescale; // HLSL prescale enable flag
|
||||
int hlsl_prescale_size; // HLSL prescale size
|
||||
int hlsl_preset; // HLSL preset, if relevant
|
||||
float oversample_x; // render target oversampling factor (width) for shader prettification
|
||||
@ -2160,7 +2159,6 @@ static int device_verify_caps(d3d_info *d3d, win_window_info *window)
|
||||
|
||||
d3d->hlsl_enable = downcast<windows_options &>(window->machine().options()).d3d_hlsl_enable() && d3dintf->post_fx_available;
|
||||
d3d->yiq_enable = downcast<windows_options &>(window->machine().options()).screen_yiq_enable();
|
||||
d3d->hlsl_prescale = downcast<windows_options &>(window->machine().options()).d3d_hlsl_prescale();
|
||||
d3d->hlsl_prescale_size = downcast<windows_options &>(window->machine().options()).d3d_hlsl_prescale_size();
|
||||
d3d->hlsl_preset = downcast<windows_options &>(window->machine().options()).d3d_hlsl_preset();
|
||||
|
||||
@ -3151,48 +3149,9 @@ static void primitive_flush_pending(d3d_info *d3d)
|
||||
|
||||
(*d3dintf->effect.end)(curr_effect);
|
||||
|
||||
/* Pre-scaling pass (if enabled) */
|
||||
if(d3d->hlsl_prescale)
|
||||
{
|
||||
curr_effect = d3d->prescale_effect;
|
||||
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", d3d->hlslsmalltexture0[poly->texture->target_index]);
|
||||
|
||||
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
|
||||
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
|
||||
|
||||
(*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
|
||||
|
||||
result = (*d3dintf->device.set_render_target)(d3d->device, 0, d3d->hlslprescaletarget0[poly->texture->target_index]);
|
||||
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
|
||||
result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
|
||||
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
|
||||
|
||||
for (UINT pass = 0; pass < num_passes; pass++)
|
||||
{
|
||||
(*d3dintf->effect.begin_pass)(curr_effect, pass);
|
||||
// add the primitives
|
||||
result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, 0, poly->count);
|
||||
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
|
||||
(*d3dintf->effect.end_pass)(curr_effect);
|
||||
}
|
||||
|
||||
(*d3dintf->effect.end)(curr_effect);
|
||||
|
||||
curr_effect = d3d->deconverge_effect;
|
||||
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", d3d->hlslprescaletexture0[poly->texture->target_index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
curr_effect = d3d->deconverge_effect;
|
||||
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", d3d->hlslsmalltexture0[poly->texture->target_index]);
|
||||
}
|
||||
|
||||
/* Deconverge pass */
|
||||
curr_effect = d3d->deconverge_effect;
|
||||
/* Pre-scaling pass */
|
||||
curr_effect = d3d->prescale_effect;
|
||||
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", d3d->hlslsmalltexture0[poly->texture->target_index]);
|
||||
|
||||
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
|
||||
@ -3200,6 +3159,37 @@ static void primitive_flush_pending(d3d_info *d3d)
|
||||
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
|
||||
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
|
||||
|
||||
(*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
|
||||
|
||||
result = (*d3dintf->device.set_render_target)(d3d->device, 0, d3d->hlslprescaletarget0[poly->texture->target_index]);
|
||||
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
|
||||
result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
|
||||
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
|
||||
|
||||
for (UINT pass = 0; pass < num_passes; pass++)
|
||||
{
|
||||
(*d3dintf->effect.begin_pass)(curr_effect, pass);
|
||||
// add the primitives
|
||||
result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, 0, poly->count);
|
||||
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
|
||||
(*d3dintf->effect.end_pass)(curr_effect);
|
||||
}
|
||||
|
||||
(*d3dintf->effect.end)(curr_effect);
|
||||
|
||||
|
||||
/* Deconverge pass */
|
||||
curr_effect = d3d->deconverge_effect;
|
||||
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", d3d->hlslprescaletexture0[poly->texture->target_index]);
|
||||
|
||||
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
|
||||
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
|
||||
(*d3dintf->effect.set_float)(curr_effect, "Prescale", d3d->hlsl_prescale_size);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "RedConvergeX", options->screen_red_converge_x);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "RedConvergeY", options->screen_red_converge_y);
|
||||
(*d3dintf->effect.set_float)(curr_effect, "GrnConvergeX", options->screen_green_converge_x);
|
||||
@ -4016,8 +4006,7 @@ static texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsour
|
||||
goto error;
|
||||
(*d3dintf->texture.get_surface_level)(d3d->hlsltexture4[idx], 0, &d3d->hlsltarget4[idx]);
|
||||
|
||||
int scale = 1;
|
||||
if(d3d->hlsl_prescale) scale = d3d->hlsl_prescale_size;
|
||||
int scale = d3d->hlsl_prescale_size;
|
||||
|
||||
result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth * scale, texture->rawheight * scale, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &d3d->hlslsmalltexture0[idx]);
|
||||
if (result != D3D_OK)
|
||||
@ -4108,8 +4097,7 @@ static texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsour
|
||||
goto error;
|
||||
(*d3dintf->texture.get_surface_level)(d3d->hlsltexture4[idx], 0, &d3d->hlsltarget4[idx]);
|
||||
|
||||
int scale = 1;
|
||||
if(d3d->hlsl_prescale) scale = d3d->hlsl_prescale_size;
|
||||
int scale = d3d->hlsl_prescale_size;
|
||||
|
||||
result = (*d3dintf->device.create_texture)(d3d->device, scwidth * scale, scheight * scale, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &d3d->hlslsmalltexture0[idx]);
|
||||
if (result != D3D_OK)
|
||||
|
@ -330,7 +330,6 @@ const options_entry windows_options::s_option_entries[] =
|
||||
{ NULL, NULL, OPTION_HEADER, "DIRECT3D POST-PROCESSING OPTIONS" },
|
||||
{ WINOPTION_HLSL_ENABLE";hlsl", "0", OPTION_BOOLEAN, "enable HLSL post-processing (PS3.0 required)" },
|
||||
{ WINOPTION_HLSLPATH, "hlsl", OPTION_STRING, "path to hlsl files" },
|
||||
{ WINOPTION_HLSL_PRESCALE";hlsl_prescale", "0", OPTION_BOOLEAN, "enable HLSL scaling pre-pass (for 'x' filters)" },
|
||||
{ WINOPTION_HLSL_PRESCALE_SIZE, "2", OPTION_INTEGER, "HLSL scaling pre-pass factor (usually 2 or 3)" },
|
||||
{ WINOPTION_HLSL_PRESET";(-1-5)", "-1", OPTION_INTEGER, "HLSL preset to use (0-5)" },
|
||||
{ WINOPTION_HLSL_WRITE, NULL, OPTION_STRING, "enable HLSL AVI writing (huge disk bandwidth suggested)" },
|
||||
|
@ -81,7 +81,6 @@
|
||||
// core post-processing options
|
||||
#define WINOPTION_HLSL_ENABLE "hlsl_enable"
|
||||
#define WINOPTION_HLSLPATH "hlslpath"
|
||||
#define WINOPTION_HLSL_PRESCALE "hlsl_prescale"
|
||||
#define WINOPTION_HLSL_PRESCALE_SIZE "hlsl_prescale_size"
|
||||
#define WINOPTION_HLSL_PRESET "hlsl_preset"
|
||||
#define WINOPTION_HLSL_WRITE "hlsl_write"
|
||||
@ -222,7 +221,6 @@ public:
|
||||
const char *screen_post_fx_dir() const { return value(WINOPTION_HLSLPATH); }
|
||||
bool d3d_hlsl_enable() const { return bool_value(WINOPTION_HLSL_ENABLE); }
|
||||
const char *d3d_hlsl_write() const { return value(WINOPTION_HLSL_WRITE); }
|
||||
bool d3d_hlsl_prescale() const { return bool_value(WINOPTION_HLSL_PRESCALE); }
|
||||
int d3d_hlsl_prescale_size() const { return int_value(WINOPTION_HLSL_PRESCALE_SIZE); }
|
||||
int d3d_hlsl_preset() const { return int_value(WINOPTION_HLSL_PRESET); }
|
||||
int d3d_snap_width() const { return int_value(WINOPTION_HLSL_SNAP_WIDTH); }
|
||||
|
Loading…
Reference in New Issue
Block a user