So, this shader works pretty well with Demul
/*-----------------------------------------------------------.
/ SweetCRT /
'-----------------------------------------------------------*/
/*
SweetCRT - a Work in progress.
*/
#define scanline_strength 0.75
float4 SweetCRTPass( float4 colorInput, float2 tex )
{
//
float scanlines = frac(tex.y * (screen_size.y * 0.5)) - 0.49; //
scanlines = 1.0 + scanlines * scanline_strength;
colorInput.rgb = saturate(colorInput.rgb * scanlines);
//colorInput.rgb = saturate(scanlines).xxx;
return colorInput;
}
But not as nice as yours, which unfortunately, isn’t compatible with Demul
struct data
{
float2 tex;
float2 pix_no;
float2 one;
};
struct input
{
float2 video_size;
float2 texture_size;
float2 output_size;
float frame_count;
};
void main_vertex
(
float4 position : POSITION,
out float4 oPosition : POSITION,
uniform float4x4 modelViewProj,
float2 tex : TEXCOORD,
uniform input IN,
out data oData
)
{
oPosition = mul(modelViewProj, position);
oData.tex = tex;
oData.pix_no = tex * IN.texture_size;
oData.one = 1.0 / IN.texture_size;
}
float4 main_fragment (uniform input IN, in data vertex, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
#define DISPLAY_GAMMA 2.2
#define CRT_GAMMA 2.4
#define TEX(off) pow(tex2D(s0, vertex.tex + float2(0.0, (off) * vertex.one.y)).rgb, float3(CRT_GAMMA))
float3 frame0 = TEX(0.0);
float3 frame1 = TEX(0.0);
float3 frame2 = TEX(0.0);
float3 frame3 = TEX(0.0);
float3 frame4 = TEX(0.0);
float offset_dist = frac(vertex.pix_no.y) - 0.5;
float dist0 = 2.0 + offset_dist;
float dist1 = 1.0 + offset_dist;
float dist2 = 0.0 + offset_dist;
float dist3 = -1.0 + offset_dist;
float dist4 = -2.0 + offset_dist;
float3 scanline = frame0 * exp(-5.0 * dist0 * dist0);
scanline += frame1 * exp(-5.0 * dist1 * dist1);
scanline += frame2 * exp(-10.0 * dist2 * dist2); //scanline darkness
scanline += frame3 * exp(-5.0 * dist3 * dist3);
scanline += frame4 * exp(-5.0 * dist4 * dist4);
//return float4(pow(1.15 * scanline, float3(1.0 / DISPLAY_GAMMA)), 1.0); default
return float4(pow(1.2 * scanline, float3(1.0 / DISPLAY_GAMMA)), 1.0);
}
I am not very knowledgeable when it comes to converting shaders… Can any of you shader experts improve the original, or if it’s simple, can you modify/port the other scanline shader so it’ll work? I know a few guys that’ll be extremely happy, myself included.
Thanks!