forked from libretro/common-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanline.cg
77 lines (62 loc) · 1.81 KB
/
scanline.cg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* COMPATIBILITY
- HLSL compilers
- Cg compilers
*/
/*
Author: Themaister
License: Public domain
*/
struct sine_coord
{
float2 omega;
};
struct input
{
float2 video_size;
float2 texture_size;
float2 output_size;
float frame_count;
float frame_direction;
float frame_rotation;
};
void main_vertex
(
float4 position : POSITION,
out float4 oPosition : POSITION,
uniform float4x4 modelViewProj,
float4 color : COLOR,
out float4 oColor : COLOR,
float2 tex : TEXCOORD,
out float2 oTex : TEXCOORD,
uniform input IN,
out sine_coord coords : TEXCOORD2
)
{
oPosition = mul(modelViewProj, position);
oColor = color;
oTex = tex;
float2 texsize = IN.texture_size;
float2 delta = 0.5 / texsize;
float dx = delta.x;
float dy = delta.y;
coords.omega = float2(3.1415 * IN.output_size.x * IN.texture_size.x / IN.video_size.x, 2.0 * 3.1415 * IN.texture_size.y);
}
#pragma parameter SCANLINE_BASE_BRIGHTNESS "Scanline Base Brightness" 0.95 0.0 1.0 0.01
#pragma parameter SCANLINE_SINE_COMP_A "Scanline Sine Comp A" 0.05 0.0 0.10 0.01
#pragma parameter SCANLINE_SINE_COMP_B "Scanline Sine Comp B" 0.15 0.0 1.0 0.05
#ifdef PARAMETER_UNIFORM
uniform float SCANLINE_BASE_BRIGHTNESS;
uniform float SCANLINE_SINE_COMP_A;
uniform float SCANLINE_SINE_COMP_B;
#else
#define SCANLINE_BASE_BRIGHTNESS 0.95
#define SCANLINE_SINE_COMP_A 0.05
#define SCANLINE_SINE_COMP_B 0.15
#endif
float4 main_fragment (in sine_coord co : TEXCOORD2, float2 tex : TEXCOORD, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
float2 sine_comp = float2(SCANLINE_SINE_COMP_A, SCANLINE_SINE_COMP_B);
float3 res = tex2D(s0, tex).xyz;
float3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(tex * co.omega), float2(1.0, 1.0)));
return float4(scanline.x, scanline.y, scanline.z, 1.0);
}