-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbead.fsh
83 lines (67 loc) · 2.1 KB
/
bead.fsh
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
/*
bead fragment shader
Original code by Themaister, released into the public domain
'Ported' (i.e. copy/paste) to PPSSPP format by jdgleaver
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.
*** Requires rendering resolution to be set to 1xPSP
*** Absolutely requires a display resolution of at least 1080p
*/
//=== Config
#define BEAD_HIGH 0.35 // "Bead High" - default: 0.35, min: 0.0, max: 1.0, step: 0.01
//#define BEAD_LOW 0.2 // "Bead Low" - default: 0.2, min: 0.0, max: 1.0, step: 0.01
//================
#ifdef GL_ES
precision mediump float;
precision mediump int;
// For android, use this instead...
//precision highp float;
//precision highp int;
//
#endif
//================
uniform sampler2D sampler0;
uniform vec2 u_texelDelta;
varying vec2 v_texcoord0;
// Have to use standard names to ensure compatibility with
// Vulkan backend...
varying vec2 v_texcoord1; // pixel_no
//================
float dist(vec2 coord, vec2 source)
{
vec2 delta = coord - source;
return sqrt(dot(delta, delta));
}
float rolloff(float len)
{
return exp(-6.0 * len);
}
vec3 lookup(vec2 pixel_no, vec3 color)
{
float delta = dist(fract(pixel_no), vec2(0.5, 0.5));
// if (delta > BEAD_LOW && delta < BEAD_HIGH)
// return color;
// else if (delta >= BEAD_HIGH)
// return color * rolloff(delta - BEAD_HIGH);
// else if (delta <= BEAD_LOW)
// return color * rolloff(BEAD_LOW - delta);
// else
// return vec3(0.0, 0.0, 0.0);
// The PSP has such a 'high' resolution that the
// 'hole' in the bead will never be visible on any
// conventional display. We can therefore reduce the
// performance impact of this shader by ignoring the
// 'BEAD_LOW' stuff
if (delta < BEAD_HIGH)
return color;
else
return color * rolloff(delta - BEAD_HIGH);
}
//================
void main()
{
vec3 mid_color = lookup(v_texcoord1, texture2D(sampler0, v_texcoord0.xy).rgb); // pixel_no == v_texcoord1
gl_FragColor = vec4(mid_color, 1.0);
}