diff options
author | 2016-02-20 21:58:56 +0100 | |
---|---|---|
committer | 2016-02-20 21:58:56 +0100 | |
commit | e57c90084c5d1dd9f6cdb0bbbf8782dc4f369cda (patch) | |
tree | 650be9617f5dd57cce30eb78e283e15c149a0472 /hlsl/prescale.fx | |
parent | d15d53c728b4848e3ed74d66b9ab446811e1acee (diff) |
Quality and Performance improvements
- HLSL now uses NPOT sized target surfaces (breaks compatibility with
graphics cards based on R300/R400/NV30 and older)
- HLSL target surfaces now have the size of the screen canvas
- removed HLSL pre-scale factor
- HLSL now uses a sharp bilinear interpolation to pre-scale textures to
screen canvas size, based on [Themaister's] implementation
- improved overall performance (based on the previously required
pre-scale factor, you might notice a 5-50% speed-up depending on your
graphics card, more if you used a higher pre-scale factor)
- improved shadow mask quality (pixel-perfect) in screen-mode
- fixed half source texel offset of bloom level alignment
- removed ./hlsl/artwork_support folder
- all shaders after pre-scale are now based on screen coordinate
(workaground, till both raster and vector pass can work on texture
coordinates)
- disabled distortion shader for more than one screen and for artworks
in full mode, does not affect artworks in copped mode (workaground, till
both raster and vector pass can work on texture coordinates)
- moved compute_texture_size() from texture_info to texture_manager (nw)
Diffstat (limited to 'hlsl/prescale.fx')
-rw-r--r-- | hlsl/prescale.fx | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/hlsl/prescale.fx b/hlsl/prescale.fx index 6faa659e6d0..1cbcaa0f753 100644 --- a/hlsl/prescale.fx +++ b/hlsl/prescale.fx @@ -1,7 +1,11 @@ // license:BSD-3-Clause -// copyright-holders:Ryan Holtz +// copyright-holders:Ryan Holtz,Themaister,ImJezze //----------------------------------------------------------------------------- -// Prescale Effect +// Pre-scale Effect +// +// Uses the hardware bilinear interpolator to avoid having to sample 4 times manually. +// +// https://github.com/libretro/common-shaders/blob/master/retro/shaders/sharp-bilinear.cg //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -13,9 +17,9 @@ texture Diffuse; sampler DiffuseSampler = sampler_state { Texture = <Diffuse>; - MipFilter = NONE; - MinFilter = NONE; - MagFilter = NONE; + MipFilter = LINEAR; + MinFilter = LINEAR; + MagFilter = LINEAR; AddressU = CLAMP; AddressV = CLAMP; AddressW = CLAMP; @@ -45,11 +49,12 @@ struct PS_INPUT }; //----------------------------------------------------------------------------- -// Prescale Vertex Shader +// Pre-scale Vertex Shader //----------------------------------------------------------------------------- uniform float2 ScreenDims; uniform float2 TargetDims; +uniform float2 SourceDims; VS_OUTPUT vs_main(VS_INPUT Input) { @@ -62,22 +67,35 @@ VS_OUTPUT vs_main(VS_INPUT Input) Output.Position.xy *= 2.0f; // zoom Output.TexCoord = Input.TexCoord; - Output.TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9) + // Output.TexCoord += 0.5f / targetDims; // half texel offset correction (DX9) return Output; } //----------------------------------------------------------------------------- -// Prescale Pixel Shader +// Pre-scale Pixel Shader //----------------------------------------------------------------------------- float4 ps_main(PS_INPUT Input) : COLOR { - return tex2D(DiffuseSampler, Input.TexCoord); + float2 Scale = TargetDims / SourceDims; + + float2 TexelDims = Input.TexCoord * SourceDims; + float2 i = floor(TexelDims); + float2 s = frac(TexelDims); + + // Figure out where in the texel to sample to get the correct pre-scaled bilinear. + float2 CenterDistance = s - 0.5f; + float2 RegionRange = 0.5f - 0.5f / Scale; + float2 f = (CenterDistance - clamp(CenterDistance, -RegionRange, RegionRange)) * Scale + 0.5f; + + float2 TexCoord = (i + f) / SourceDims; + + return tex2D(DiffuseSampler, TexCoord); } //----------------------------------------------------------------------------- -// Prescale Technique +// Pre-scale Technique //----------------------------------------------------------------------------- technique DefaultTechnique @@ -89,4 +107,4 @@ technique DefaultTechnique VertexShader = compile vs_3_0 vs_main(); PixelShader = compile ps_3_0 ps_main(); } -} +}
\ No newline at end of file |