1// Compatibility #ifdefs needed for parameters
2#ifdef GL_ES
3#define COMPAT_PRECISION mediump
4#else
5#define COMPAT_PRECISION
6#endif
7
8// Parameter lines go here:
9#pragma parameter RETRO_PIXEL_SIZE "Retro Pixel Size" 0.84 0.0 1.0 0.01
10#ifdef PARAMETER_UNIFORM
11// All parameter floats need to have COMPAT_PRECISION in front of them
12uniform COMPAT_PRECISION float RETRO_PIXEL_SIZE;
13#else
14#define RETRO_PIXEL_SIZE 0.84
15#endif
16
17#if defined(VERTEX)
18
19#if __VERSION__ >= 130
20#define COMPAT_VARYING out
21#define COMPAT_ATTRIBUTE in
22#define COMPAT_TEXTURE texture
23#else
24#define COMPAT_VARYING varying
25#define COMPAT_ATTRIBUTE attribute
26#define COMPAT_TEXTURE texture2D
27#endif
28
29#ifdef GL_ES
30#define COMPAT_PRECISION mediump
31#else
32#define COMPAT_PRECISION
33#endif
34
35COMPAT_ATTRIBUTE vec4 VertexCoord;
36COMPAT_ATTRIBUTE vec4 COLOR;
37COMPAT_ATTRIBUTE vec4 TexCoord;
38COMPAT_VARYING vec4 COL0;
39COMPAT_VARYING vec4 TEX0;
40// out variables go here as COMPAT_VARYING whatever
41
42vec4 _oPosition1;
43uniform mat4 MVPMatrix;
44uniform COMPAT_PRECISION int FrameDirection;
45uniform COMPAT_PRECISION int FrameCount;
46uniform COMPAT_PRECISION vec2 OutputSize;
47uniform COMPAT_PRECISION vec2 TextureSize;
48uniform COMPAT_PRECISION vec2 InputSize;
49
50// compatibility #defines
51#define vTexCoord TEX0.xy
52#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
53#define OutSize vec4(OutputSize, 1.0 / OutputSize)
54
55void main()
56{
57    gl_Position = MVPMatrix * VertexCoord;
58    TEX0.xy = VertexCoord.xy;
59// Paste vertex contents here:
60}
61
62#elif defined(FRAGMENT)
63
64#if __VERSION__ >= 130
65#define COMPAT_VARYING in
66#define COMPAT_TEXTURE texture
67out vec4 FragColor;
68#else
69#define COMPAT_VARYING varying
70#define FragColor gl_FragColor
71#define COMPAT_TEXTURE texture2D
72#endif
73
74#ifdef GL_ES
75#ifdef GL_FRAGMENT_PRECISION_HIGH
76precision highp float;
77#else
78precision mediump float;
79#endif
80#define COMPAT_PRECISION mediump
81#else
82#define COMPAT_PRECISION
83#endif
84
85uniform COMPAT_PRECISION int FrameDirection;
86uniform COMPAT_PRECISION int FrameCount;
87uniform COMPAT_PRECISION vec2 OutputSize;
88uniform COMPAT_PRECISION vec2 TextureSize;
89uniform COMPAT_PRECISION vec2 InputSize;
90uniform sampler2D Texture;
91COMPAT_VARYING vec4 TEX0;
92// in variables go here as COMPAT_VARYING whatever
93
94// compatibility #defines
95#define Source Texture
96#define vTexCoord TEX0.xy
97
98#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
99#define OutSize vec4(OutputSize, 1.0 / OutputSize)
100
101// delete all 'params.' or 'registers.' or whatever in the fragment
102float iGlobalTime = float(FrameCount)*0.025;
103vec2 iResolution = OutputSize.xy;
104
105// Sound - Digital Ambience -  srtuss - 2014-07-31
106// https://www.shadertoy.com/view/MdXXW2
107
108// i tried to rebuild the technique that creates the ambience sounds in my game project. it's based on additive synthesis. go ahead and "listen" to various textures
109
110// srtuss, 2014
111
112vec2 rotate(vec2 p, float a)
113{
114	return vec2(p.x * cos(a) - p.y * sin(a), p.x * sin(a) + p.y * cos(a));
115}
116
117#define ITS 8
118
119vec2 circuit(vec3 p)
120{
121	p = mod(p, 2.0) - 1.0;
122	float w = 1e38;
123	vec3 cut = vec3(1.0, 0.0, 0.0);
124	vec3 e1 = vec3(-1.0);
125	vec3 e2 = vec3(1.0);
126	float rnd = 0.23;
127	float pos, plane, cur;
128	float fact = 0.9;
129	float j = 0.0;
130	for(int i = 0; i < ITS; i ++)
131	{
132		pos = mix(dot(e1, cut), dot(e2, cut), (rnd - 0.5) * fact + 0.5);
133		plane = dot(p, cut) - pos;
134		if(plane > 0.0)
135		{
136			e1 = mix(e1, vec3(pos), cut);
137			rnd = fract(rnd * 9827.5719);
138			cut = cut.yzx;
139		}
140		else
141		{
142			e2 = mix(e2, vec3(pos), cut);
143			rnd = fract(rnd * 15827.5719);
144			cut = cut.zxy;
145		}
146		j += step(rnd, 0.2);
147		w = min(w, abs(plane));
148	}
149	return vec2(j / float(ITS - 1), w);
150}
151
152float scene(vec3 p)
153{
154	vec2 cir = circuit(p);
155	return exp(-100.0 * cir.y) + pow(cir.x * 1.8 * (sin(p.z * 10.0 + iGlobalTime * -5.0 + cir.x * 10.0) * 0.5 + 0.5), 8.0);
156}
157
158float nse(float x)
159{
160    return fract(sin(x * 297.9712) * 90872.2961);
161}
162
163float nseI(float x)
164{
165    float fl = floor(x);
166    return mix(nse(fl), nse(fl + 1.0), smoothstep(0.0, 1.0, fract(x)));
167}
168
169float fbm(float x)
170{
171    return nseI(x) * 0.5 + nseI(x * 2.0) * 0.25 + nseI(x * 4.0) * 0.125;
172}
173
174void mainImage( out vec4 fragColor, in vec2 fragCoord )
175{
176	vec2 uv = fragCoord.xy / iResolution.xy;
177	vec2 suv = uv;
178	uv = 2.0 * uv - 1.0;
179	uv.x *= iResolution.x / iResolution.y;
180	vec3 ro = vec3(0.0, iGlobalTime * 0.2, 0.1);
181	vec3 rd = normalize(vec3(uv, 0.9));
182	ro.xz = rotate(ro.xz, iGlobalTime * 0.1);
183	ro.xy = rotate(ro.xy, 0.2);
184	rd.xz = rotate(rd.xz, iGlobalTime * 0.2);
185	rd.xy = rotate(rd.xy, 0.2);
186	float acc = 0.0;
187	vec3 r = ro + rd * 0.5;
188	for(int i = 0; i < 50; i ++)
189	{
190		acc += scene(r + nse(r.x) * 0.03);
191		r += rd * 0.015;
192	}
193	vec3 col = pow(vec3(acc * 0.04), vec3(0.2, 0.6, 2.0) * 8.0) * 2.0;
194	//col -= exp(length(suv - 0.5) * -2.5 - 0.2);
195    col = clamp(col, vec3(0.0), vec3(1.0));
196    col *= fbm(iGlobalTime * 6.0) * 2.0;
197	col = pow(col, vec3(1.0 / 2.2));
198	//col = clamp(col, vec3(0.0), vec3(1.0));
199	fragColor = vec4(col, 1.0);
200}
201
202void main(void)
203{
204  //just some shit to wrap shadertoy's stuff
205  vec2 FragCoord = vTexCoord.xy*OutputSize.xy;
206  mainImage(FragColor,FragCoord);
207}
208#endif
209