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// Spell Demon's Souls - leon - 2017-10-21 106// https://www.shadertoy.com/view/XljcD1 107 108// A sketch inspired by Dark Souls. Sometime you can see the twisted souls emerging from the distorted shapes. I could tweak this for days and nights... 109 110#define STEPS 1./50. 111#define VOLUME_BIAS 0.01 112#define MIN_DIST 0.005 113#define STEP_DAMPING .9 114#define PI 3.14159 115#define TAU PI*2. 116 117// raymarch toolbox 118float rng (vec2 seed) { return fract(sin(dot(seed*.1684,vec2(54.649,321.547)))*450315.); } 119mat2 rot (float a) { float c=cos(a),s=sin(a); return mat2(c,-s,s,c); } 120float sdSphere (vec3 p, float r) { return length(p)-r; } 121float sdCylinder (vec2 p, float r) { return length(p)-r; } 122float sdIso(vec3 p, float r) { return max(0.,dot(p,normalize(sign(p))))-r; } 123float sdBox( vec3 p, vec3 b ) { 124 vec3 d = abs(p) - b; 125 return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0)); 126} 127float amod (inout vec2 p, float count) { 128 float an = TAU/count; 129 float a = atan(p.y,p.x)+an/2.; 130 float c = floor(a/an); 131 a = mod(a,an)-an/2.; 132 p.xy = vec2(cos(a),sin(a))*length(p); 133 return c; 134} 135 136float repeat (float v, float c) { return mod(v,c)-c/2.; } 137float smin (float a, float b, float r) { 138 float h = clamp(.5+.5*(b-a)/r, 0., 1.); 139 return mix(b,a,h)-r*h*(1.-h); 140} 141 142// geometry for spell 143float tubes (vec3 pos) { 144 145 // cylinder made of 8 tube 146 float cylinderRadius = .02; // change shape 147 vec3 p = pos; 148 p.xz *= rot(p.y*.5); // twist amount 149 float c = amod(p.xz, 8.); // amount of tubes 150 p.x -= 2.; // tube cylinder radius 151 float tube = sdCylinder(p.xz, cylinderRadius); 152 153 // another cylinder made of tubes 16 154 p = pos; 155 p.xz *= rot(-p.y*.5); // twist amount 156 c = amod(p.xz, 16.); // amount of tubes 157 p.x -= 2.; // tube cylinder radius 158 tube = smin(tube, sdCylinder(p.xz, cylinderRadius), .15); 159 return tube; 160} 161 162// geometry for spell 163float disks (vec3 pos) { 164 float radius = 1.5; 165 float radiusInner = .57; 166 float thin = .01; 167 float repeatY = 2.; 168 float cellY = floor(pos.y/repeatY); 169 float a = atan(pos.z,pos.x)-iGlobalTime*.3+cellY*.1; 170 vec3 p = pos; 171 p.y += sin(a*6.)*.1; 172 p.y = repeat(p.y, repeatY); 173 float disk = max(-sdCylinder(p.xz, radiusInner), sdCylinder(p.xz, radius)); 174 disk = max(abs(p.y)-thin,disk); 175 return disk; 176} 177 178vec3 anim1 (vec3 p) { 179 float t = iGlobalTime*.5; 180 p.xz *= rot(t); 181 p.xy *= rot(t*.7); 182 p.yz *= rot(t*.5); 183 return p; 184} 185 186vec3 anim2 (vec3 p) { 187 float t = -iGlobalTime*.4; 188 p.xz *= rot(t*.9); 189 p.xy *= rot(t*.6); 190 p.yz *= rot(t*.3); 191 return p; 192} 193 194float map (vec3 pos) { 195 float scene = 1000.; 196 197 // ground and ceiling 198#ifdef BUMP 199 float bump = texture(iChannel0, pos.xz*.1).r; 200#else 201 float bump = 0.0; 202#endif 203 float ground = 2. - bump*.1; 204 scene = min(scene, pos.y+ground); 205 scene = min(scene, -(pos.y-ground)); 206 207 // spell geometry 1 208 vec3 p = pos; 209 p.y += sin(atan(p.z,p.x)*10.)*3.; // change numbers to get new distortion 210 p.xz *= rot(p.y*.2-iGlobalTime); 211 p = anim1(p); 212 p.x = length(p.xyz)-3.; 213 scene = smin(scene, tubes(p), .5); 214 scene = smin(scene, disks(p), .5); 215 216 // spell geometry 2 217 p = pos; 218 p.y += sin(atan(p.z,p.x)*3.)*2.; // change numbers to get new distortion 219 p = anim2(p); 220 p.xz *= rot(p.y+iGlobalTime); 221 p.x = length(p.xyz)-3.; 222 scene = smin(scene, tubes(p), .3); 223 scene = smin(scene, disks(p), .3); 224 225 return scene; 226} 227 228void camera (inout vec3 p) { 229#ifdef MOUSE 230 p.xz *= rot((-PI*(iMouse.x/iResolution.x-.5))); 231#else 232 p.xz *= rot((-PI*(0.0/iResolution.x-.5))); 233#endif 234} 235 236void mainImage( out vec4 color, in vec2 uv ) 237{ 238 uv = (uv.xy-.5*iResolution.xy)/iResolution.y; 239#ifdef MOUSE 240 vec2 mouse = iMouse.xy/iResolution.xy; 241#else 242 vec2 mouse = 0.0/iResolution.xy; 243#endif 244 vec3 eye = vec3(0.,0.,-7.+mouse.y*3.); 245 vec3 ray = normalize(vec3(uv,.7)); 246 camera(eye); 247 camera(ray); 248 vec3 pos = eye; 249 float shade = 0.; 250 for (float i = 0.; i <= 1.; i += STEPS) { 251 float dist = map(pos); 252 if (dist < VOLUME_BIAS) { 253 shade += STEPS; 254 } 255 if (shade >= 1.) break; 256 dist *= STEP_DAMPING + .1 * rng(uv+fract(iGlobalTime)); 257 dist = max(MIN_DIST, dist); 258 pos += dist * ray; 259 } 260 color = vec4(1); 261 color.rgb *= shade; 262} 263 264 void main(void) 265{ 266 //just some shit to wrap shadertoy's stuff 267 vec2 FragCoord = vTexCoord.xy*OutputSize.xy; 268 mainImage(FragColor,FragCoord); 269} 270#endif 271