First post, by Spa8nky
Rank
Newbie
Hi folks,
I've written an HLSL shader for producing evenly spaced scanlines on an HDTV (tested in 1080p):
/*
Copyright (C) 2010 Rhys J. Perkins
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//
// 2D Scale Effect File
//
// Point Sampling
//
#define LINES_ON 1.0
#define LINES_OFF 1.0
#define OFF_INTENSITY 0.5
#include "Scaling.inc"
// The name of this effect
string name : NAME = "Point Sampling";
float scaling : SCALING = 2.0;
//
// Techniques
//
// combineTechnique: Final combine steps. Outputs to destination frame buffer
string combineTechique : COMBINETECHNIQUE = "Point";
//
// Vertex Shader Output
//
struct VS_OUTPUT
{
float4 Position : POSITION;
float2 UV : TEXCOORD0;
};
//
// Vertex Shader
//
VS_OUTPUT VS(float3 Position : POSITION, float2 TexCoord : TEXCOORD0)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Position = mul(float4(Position, 1), WorldViewProjection); // Matrix multipliy
Out.UV = TexCoord;
return Out;
}
//
// Pixel Shader
//
float4 PS (in VS_OUTPUT input) : COLOR
{
// Adjust pixelRatio in multiples of 0.9 (derived from 16:9 / 16:10 ratio)
// This will adjust the thickness of the scanlines
float pixelRatio = 2.7; //1.8; //0.9;
float intensity = (input.UV.y * SourceDims.y * pixelRatio) % (LINES_ON + LINES_OFF);
intensity = intensity < LINES_ON ? 1.0 : OFF_INTENSITY;
return tex2D(SourceSampler, input.UV) * intensity;
}
//
// Technique
//
technique Point
{
pass P0
{
// shaders
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
AlphaBlendEnable = FALSE;
ColorWriteEnable = RED|GREEN|BLUE|ALPHA;
SRGBWRITEENABLE = FALSE;
}
}
DosBox is unable to produce evenly spaced scalines using the tv2x shader in fullscreen mode on my HDTV. This shader fixes that.
It should be noted that I have tested this using ykhwong's 2010-12-25 SVN build for Windows.
I hope somebody else finds it useful.
Thanks,
Rhys