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// Skyline 3D -  FabriceNeyret2 - 2015-07-02
106// https://www.shadertoy.com/view/4tlSWr
107
108// in the spirit of the 2D skylines (e.g., https://www.shadertoy.com/view/4tlXzM )... but in 3D :-)  ( I even reproduced the original temporal aliasing :-D  )
109
110// Be sure to wait long enough ;-)
111
112#define T iGlobalTime
113
114// --- using the base ray-marcher of Trisomie21: https://www.shadertoy.com/view/4tfGRB#
115
116vec4 bg = vec4(0); // vec4(0,0,.3,0);
117
118void mainImage( out vec4 f, vec2 w ) {
119    vec4 p = vec4(w,0,1)/iResolution.yyxy-.5, d,c; p.x-=.4; // init ray
120    // r(p.xz,.13); r(p.yz,.2); r(p.xy,.1);   // camera rotations
121    d =p;                                 // ray dir = ray0-vec3(0)
122    p.x += 15.*T; p += 2.*d;
123    f = bg;
124    float l,x=1e9, closest = 999.;
125
126    for (float i=1.; i>0.; i-=.01)  {
127
128        vec4 u = floor(p/8.), t = mod(p, 8.)-4., ta; // objects id + local frame
129      	u.y = 0.;
130        u = sin(78.17*(u+u.yzxw));                     // randomize ids
131
132        c = p/p*1.2;
133        ta = abs(t);
134        x=1e9;
135        if (sin(17.*(u.x+u.y+u.z))>.95) { // 10% of blocks
136            ta.y = p.y + 30.*u.x - .3*pow(abs(.03*floor(p.z)),3.) + 35.;
137            x = max(ta.x,max(ta.y,ta.z))  -3.;
138         }
139        closest = min(closest, p.y+150.);
140
141        // artifacts: passed a object, we might be fooled about dist to next (hidden in next modulo-tile)
142#if 1        // if dist to box border is closest to object, go there.  <<< the working solution ! (at mod8 scale)
143        vec4 k, k1 = (4.-t)/d ,k2 = (-4.-t)/d, dd;
144        k = min (k1-1e5*sign(k1),k2-1e5*sign(k2))+1e5; // ugly trick to get the min only if positive.
145        // 2 less ugly/costly formulations, but less robust close to /0 :
146        //   k = mix(k1,k2, .5+.5*sign(k2));
147        //   dd = d+.001*clamp(1.-d*d,.999,1.); k = (4.*sign(dd)-t)/dd;
148        l = min(k.x,min(k.y,k.z));
149        if (l<x) { p+= 1.*d*(l+0.01); continue; }
150#endif
151        // if (x<.01) c = texture(iChannel0,.1*(p.xy+p.yz));
152
153        if(x<.01) // hit !
154            { f = mix(bg,c,i*i); break;  }  // color texture + black fog
155
156        p += d*x;       // march ray
157     }
158    //if (length(f)==0.) f = vec4(1,1,.6,0)*smoothstep(.31,.3,length(w/iResolution.y-vec2(1.3,.7)));
159    f += vec4(1) * exp(-.01*closest)*(.5+.5*cos(1.+T/8.)); // thanks kuvkar !
160}
161
162 void main(void)
163{
164  //just some shit to wrap shadertoy's stuff
165  vec2 FragCoord = vTexCoord.xy*OutputSize.xy;
166  mainImage(FragColor,FragCoord);
167}
168#endif
169