I'll have a go
EDIT
Ok, below is the scanline shader (save as "scanline.ps" in your media folder):
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
varying vec2 uvVarying;
uniform vec2 screenSize;
uniform float noise;
float rand(vec2 n)
{
return 0.5 + 0.5 *
fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);
}
void main()
{
float y = floor(uvVarying.y * screenSize.y);
float ran = (rand(uvVarying.xy) - 1.0) * 0.5;
if (noise < 0.1)
{
ran = 0.0;
}
float delta = mod(y, 4.0) * 0.5;
gl_FragColor = texture2D(texture0, uvVarying.xy) * (delta + ran);
}
...and below is an example project:
// Project: scanline
// Created: 2016-10-04
// show all errors
SetErrorMode(2)
// set display properties
SetWindowTitle( "scanline" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
SetSyncRate( 60, 0 )
SetPrintSize(16)
// load media
img = LoadImage("scanline.png")
// load shader
shader = LoadFullScreenShader("scanline.ps")
SetShaderConstantByName(shader, "screenSize", 1024, 768, 0, 0)
// set 1 to 0 to remove noise
SetShaderConstantByName(shader, "noise", 1, 0, 0, 0)
// create quad object
renderImage = CreateRenderImage(1024, 768, 0, 0)
quad = CreateObjectQuad()
SetObjectShader(quad, shader)
// create sprite
SetImageMagFilter(img, 0)
spr = CreateSprite(img)
SetSpriteScale(spr, 2, 2)
SetSpritePositionByOffset(spr, 512, 384)
do
// do actions on mouse button pressed
// reset state
MODE = 0
change = 0
// set state based on mouse pressed
if GetPointerState()>0
if MODE=0 then change = 1
MODE = 1
else
if MODE=1 then change = 2
MODE = 0
endif
// set shader visible as needed
select change
case 1
SetObjectShader(quad, shader)
endcase
case 2
SetObjectShader(quad, 0)
endcase
endselect
select MODE
case 0
Print("Press mouse button to see shader")
Sync()
endcase
case 1
// render to the render image
SetRenderToImage(renderImage, -1)
ClearScreen()
Update(GetFrameTime())
print("Showing shader")
Render2DBack()
Render2DFront()
SetObjectImage(quad, renderImage, 0)
// render to the screen
SetRenderToScreen()
ClearScreen()
DrawObject(quad)
Swap()
endcase
endselect
loop
... and this is the effect:
Using AppGameKit V2 Tier 1