就是实现一个球形地图无限无缝放大效果代码
代码语言:html
所属分类:动画
代码描述:就是实现一个球形地图无限无缝放大效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html { height: 100%; } img { display: none; } body { background: #000; overflow: hidden; padding: 0; margin: 0; width: 100%; height: 100%; text-align: center; } canvas { height: 100%; width: 100%; margin: auto; } </style> </head> <body > <!-- VertexShader code here --> <script id="vertexShader" type="x-shader/x-vertex">#version 300 es precision highp float; in vec4 vPosition; void main() { gl_Position = vPosition; } </script> <!-- FragmentShader code here --> <script id="fragmentShader" type="x-shader/x-fragment">#version 300 es precision highp float; out vec4 fragColor; uniform vec4 mouse; uniform vec2 resolution; uniform float time; #define R resolution #define T time #define M mouse #define PI 3.14159265359 #define PI2 6.28318530718 #define MAX_DIST 30.00 #define MIN_DIST 0.001 float hash21(vec2 a){ return fract(sin(dot(a, vec2(27.609, 57.583)))*43758.5453); } mat2 rot(float a) { return mat2(cos(a),sin(a),-sin(a),cos(a)); } //@iq https://iquilezles.org/www/articles/palettes/palettes.htm vec3 hue(float t){ vec3 d = vec3(0.110,0.584,0.949); return .45+.4*cos( PI2*t*vec3(.95,.97,.88)*d ); } //@iq cylinder float box(vec3 p, vec3 b) { vec3 q = abs(p) - b; return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0); } const float sz = 2.; const float hl = sz*.5; const vec2 boxSize = vec2(sz*.45,.25); const float density = 16.; //global vec3 hit,ghp; vec2 cellId,gid; float lpscale,movement; mat2 turn; vec2 map(vec3 q){ vec2 res = vec2(1e5,0.); vec2 p = q.xz; p*=turn; float r = length(p); p = vec2(log(r), atan(p.y, p.x)); p *= lpscale; float mul = r/lpscale; p.y -= hl; p.x += .0 + movement; vec2 id = floor((p+hl)/sz) - 1.5; p = mod(p+hl,sz)-hl; vec3 lp = vec3(p.x, max(0.0, q.y/mul), p.y); float bx = box(lp,boxSize.xyx)-.035; if(bx<res.x) { res = vec2(bx*mul,2.); gid = id; ghp = lp; } return res; } // Tetrahedron technique @iq // https://www.iquilezles.org/www/articles/normalsSDF vec3 normal(vec3 p, float t) { float e = MIN_DIST*t; vec2 h =vec2(1,-1)*.5773; vec3 n = h.xyy * map(p+h.xyy*e).x+ h.yyx * map(p+h.yyx*e).x+ h.yxy * map(p+h.yxy*e).x+ h.xxx * map(p+h.xxx*e).x; return normalize(n); } vec3 truchet(vec2 vuv) { float px = fwidth(length(vuv)/PI); vec2 id = cellId; vec2 grid = vuv; float hs = hash21(id); if(hs>.5) grid.x*=-1.; vec3 h = vec3(0); vec3 bc = vec3(1); float chk = mod(id.y + id.x,2.) * 2. - 1.; vec2 d2 = vec2(length(grid-hl), length(grid+hl)); vec2 gx = d2.x<d2.y? vec2(grid-hl) : vec2(grid+hl); float circle = length(gx)-hl; float circle2 = abs(abs(circle)-.125)-(.085+.065*sin(vuv.x*3.25) ); circle2=smoothstep(-px,px,circle2); // color flip for every other one and then ones // thats are flipped by the hash circle=(chk>0.^^ hs>.5) ? smoothstep(-px,px,circle) : smoothstep(px,-px,circle); vec2 sx = abs(grid)-hl; float cbx = length(sx)-.2; cbx=abs(cbx)-.025; cbx=smoothstep(px,-px,cbx); h = mix(h, bc, min(circle2,circle)); h = mix(h, bc, cbx); return h; } void main() { // pre-cal lpscale = floor(density)/PI; movement = time*lpscale * .123; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0