-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSpiral.cpp
More file actions
96 lines (69 loc) · 2.64 KB
/
Spiral.cpp
File metadata and controls
96 lines (69 loc) · 2.64 KB
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
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2016 Darren Mothersele <me@daz.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/
#include "Spiral.h"
FFGL_PLUGIN(Spiral,"DZSP","Spiral Source",FF_SOURCE,"Sample FFGL Plugin",
"by Darren Mothersele - www.darrenmothersele.com")
std::string fragmentShaderCode = R"GLSL(
uniform vec3 iResolution;
uniform float iGlobalTime;
// Original shader by s23b https://www.shadertoy.com/user/s23b
// Adapted from https://www.shadertoy.com/view/4st3WX
#define PI 3.14159265359
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy / .5 - 1.;
uv.x *= iResolution.x / iResolution.y;
// make a tube
float f = 1. / length(uv);
// add the angle
f += atan(uv.x, uv.y) / acos(0.);
// let's roll
f -= iGlobalTime;
// make it black and white
// old version without AA: f = floor(fract(f) * 2.);
// new version based on Shane's suggestion:
f = 1. - clamp(sin(f * PI * 2.) * dot(uv, uv) * iResolution.y / 15. + .5, 0., 1.);
// add the darkness to the end of the tunnel
f *= sin(length(uv) - .1);
fragColor = vec4(f, f, f, 1.0);
}
void main(void) {
mainImage(gl_FragColor, gl_FragCoord.xy);
}
)GLSL";
PluginConfig Spiral::getConfig() {
PluginConfig pluginConfig;
pluginConfig.shaderCode = fragmentShaderCode;
pluginConfig.params.push_back({"Speed", FF_TYPE_STANDARD, 0.5f});
pluginConfig.inputNames.push_back({"iChannel0"});
return pluginConfig;
}
void Spiral::init(FFGLShader &shader) {
timeLocation = shader.FindUniform("iGlobalTime");
resolutionLocation = shader.FindUniform("iResolution");
start = std::chrono::steady_clock::now();
}
void Spiral::process(std::vector<float> ¶mValues, FFGLExtensions &extensions)
{
float vpdim[4];
glGetFloatv(GL_VIEWPORT, vpdim);
extensions.glUniform3fARB(resolutionLocation, vpdim[2], vpdim[3], 1.0);
double lastTime = elapsedTime;
elapsedTime = GetCounter()/1000.0;
globalTime = globalTime + (float)(elapsedTime-lastTime) * (paramValues[0] - 0.5f) * 8.0f;
extensions.glUniform1fARB(timeLocation, globalTime);
}
double Spiral::GetCounter()
{
end = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()/1000.;
}