File: scan-lines.effect

package info (click to toggle)
obs-retro-effects 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,984 kB
  • sloc: ansic: 7,150; sh: 153; makefile: 27; cpp: 16
file content (110 lines) | stat: -rw-r--r-- 2,642 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

#define TAU 6.2831855

uniform float4x4 ViewProj;
uniform texture2d image;
uniform float2 uv_size;
uniform float period;
uniform float offset;
uniform float intensity;

sampler_state textureSampler{
    Filter = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
    MinLOD = 0;
    MaxLOD = 0;
};

struct VertData
{
	float4 pos : POSITION;
	float2 uv : TEXCOORD0;
};

VertData mainTransform(VertData v_in)
{
	v_in.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
	return v_in;
}

float4 sinImage(VertData v_in) : TARGET
{
	float2 coord = v_in.uv * uv_size;
	float4 color = image.Sample(textureSampler, v_in.uv);
	float v = 1.0 - intensity + intensity * (1.0 + sin(TAU * (coord.y - offset) / period)) / 2.0;
	return float4(color.rgb * v, color.a);
}

float4 squareImage(VertData v_in) : TARGET
{
	float2 coord = v_in.uv * uv_size;
	float4 color = image.Sample(textureSampler, v_in.uv);
	float coord_y = fmod(coord.y - offset, period);
	float step_val = step(0.25 * period, abs(coord_y)) * (1.0 - step(0.75 * period, abs(coord_y)));
	float v = 1.0 - intensity + intensity * step_val;
	return float4(color.rgb * v, color.a);
}

float4 smoothstepImage(VertData v_in) : TARGET
{
	float2 coord = v_in.uv * uv_size;
	float4 color = image.Sample(textureSampler, v_in.uv);
	float coord_y = fmod(coord.y - offset, period);
	float step_val = smoothstep(0.0, 0.333 * period, abs(coord_y)) * (1.0 - smoothstep(0.667 * period, period, abs(coord_y)));
	float v = 1.0 - intensity + intensity * step_val;
	return float4(color.rgb * v, color.a);
}

float4 triangularImage(VertData v_in) : TARGET
{
	float2 coord = v_in.uv * uv_size;
	float4 color = image.Sample(textureSampler, v_in.uv);
	
	float coord_y = fmod(coord.y - offset, period);
	//float s = 1.0 - step(0.5 * period, abs(coord_y));
	//float m = 1.0 / (0.5 * period) * (2.0 * s - 1.0);
	//float b = 2.0 * (1.0 - s);
	//float step_val = m * abs(coord_y) + b;
	float step_val = 2.0 * abs(abs(coord_y) / period - 0.5);
	
	//float step_val = smoothstep(0.0, 0.333 * period, abs(coord_y)) * (1.0 - smoothstep(0.667 * period, period, abs(coord_y)));
	float v = 1.0 - intensity + intensity * step_val;
	return float4(color.rgb * v, color.a);
}

technique DrawSin
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = sinImage(v_in);
	}
}

technique DrawSquare
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = squareImage(v_in);
	}
}

technique DrawSmoothstep
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = smoothstepImage(v_in);
	}
}

technique DrawTriangular
{
	pass
	{
		vertex_shader = mainTransform(v_in);
		pixel_shader = triangularImage(v_in);
	}
}