åçªã«WebGLãåå¼·ãã¦ã¿ããã¨æã£ã¦ãç·´ç¿ã¨ãã¦ä½ã£ã¦ã¿ãã
- http://sugyan-static.herokuapp.com/webgl/portalkey.html
- http://sugyan-static.herokuapp.com/webgl/portalshield.html
(â»WebGL対å¿ãã©ã¦ã¶ã§ã覧ãã ãã)
WebGLã«ã¤ãã¦å ¨ç¶ç¥èãç¡ãã£ãã®ã§ããã®ã¸ããèªãã§åå¼·ããã
ç¹ã« wgld.org ã¯åºç¤ããå§ã¾ã詳ãã解説ãã¤ã¤å¾ã
ã«è²ããªè¦ç´ ãçãè¾¼ãã§ãã¦ãåãããããã楽ãããã²ãããåçµãã¤ã¤èªã¿é²ãããã¨ã§ããªãã¨ãªã3Dã®æç»ã®ãã¨ãåãã£ã¦ãã(ãããªæ°ã«ãªã£ã)ã
ç´ æ´ãããããã¹ããæ¬å½ã«ãããããã§ãã
ã§ã3Dã§ä½ãæãã¦ã¿ãã®ã«ä½ãè¯ãé¡æãªãããªã¼ã¨æã£ã¦ãã¨ããã« Ingress ã«ã¡ããã©ããã£ã¦ããã®ã§ã
ããããã¦iTunesã¨åæããipaãã¡ã¤ã«ã解åãããä½ã3Dã¢ãã«ã®ãã¼ã¿ã転ãã£ã¦ãããããªãããã¨è¦ãã¦ã¿ãã¨ãã Ingress.app/scanner
ã£ã¦ãã£ã¬ã¯ããªã«ããã£ã½ããã¡ã¤ã«åã®ãã®ãã¡ãçºè¦ã
*.obj
ã£ã¦ãããã¡ã¤ã«åã ãã©Wevefrontã®ASCIIå½¢å¼ã®â¦ã§ã¯ãªãã£ãããã¤ããªãã©ãããJavaã§ã·ãªã¢ã©ã¤ãºããããã®ãããã
ã®ã§é©å½ã« デシリアライズするコード ãæ¸ãã¦ä¸èº«ãåãåºãã¦ã¿ãã
æåã«floatã®é
åãåºã¦ãã¦ããã®å¾ã«shortã®é
åã2ã¤åºã¦ãããæåã®floatã®ãé ç¹åº§æ¨ã®ãã¼ã¿ã«éããªããã¨æã£ãã®ã ãã©è¦ç´ æ°ã3ã®åæ°ãããªãã¦5ã®åæ°ã«ãªã£ã¦ããããããã©ãããé ç¹ã®ä½ç½®åº§æ¨ã¨ãã¯ã¹ãã£ã®åº§æ¨ãæ··å¨ãã¦ããã£ã½ãï¼ã¨ãããã¨ã§è²ã
ãããã¦ã¿ãã
ã¨ããæãã«ä¸¦ãã§ããããã ã£ããã®ã§indexã®0, 1, 2, 5, 6, 7, 10, 11, ...çªç®ã®ç©ãé ç¹ä½ç½®åº§æ¨ã«ã3, 4, 8, 9, 12, 13, ...çªç®ã®ãã®ããã¯ã¹ãã£åº§æ¨ã¨ãã¦åãåºãã¦ã2çªç®ã«åºã¦ããshorté åãé ç¹ã¤ã³ããã¯ã¹ã¨ãã¦ä½¿ã£ã¦ã¿ãã¨ããä¸æããã£ãã3çªç®ã«åºã¦ããshorté åã¯ä½ã«ä½¿ãã®ãåãããªãâ¦ã
é ç¹1ã®x座æ¨, é ç¹1ã®y座æ¨, é ç¹1ã®z座æ¨, é ç¹1ã®ãã¯ã¹ãã£x座æ¨, é ç¹1ã®ãã¯ã¹ãã£y座æ¨,
é ç¹2ã®x座æ¨, é ç¹2ã®y座æ¨, é ç¹2ã®z座æ¨, é ç¹2ã®ãã¯ã¹ãã£x座æ¨, é ç¹2ã®ãã¯ã¹ãã£y座æ¨,
é ç¹3ã®x座æ¨, é ç¹3ã®y座æ¨, é ç¹3ã®z座æ¨, é ç¹3ã®ãã¯ã¹ãã£x座æ¨, é ç¹3ã®ãã¯ã¹ãã£y座æ¨,
...
Portal Keyã¯åãåºãããã¼ã¿ãå
ã«ããã£ã½ããã¡ã¤ã«åã®ãã¯ã¹ãã£ç»åã使ã£ã¦ã¯ãã¦ã¿ããæå¤ã«ç°¡åã«ã§ããã
ã·ã§ã¼ãããã°ã©ã ã¯ãããªãããã glMatrix ã使ã£ã¦é©å½ã«å転ããã¦ã¿ã¦ãã
attribute vec3 position; attribute vec2 texCoord; uniform mat4 pMatrix; uniform mat4 mvMatrix; varying vec2 vTexCoord; void main() { vTexCoord = texCoord; gl_Position = pMatrix * mvMatrix * vec4(position, 1.0); }
precision mediump float; uniform sampler2D texture; varying vec2 vTexCoord; void main() { gl_FragColor = vec4(vec3(0.0), 1.0) + texture2D(texture, vTexCoord); }
次ã«Portal Shieldã«ãã£ã¬ã³ã¸ãã¦ã¿ãã®ã ãã©ãããã¯é¨åã2åã«åããã¦ãã¦ãå¤å´ã®ãã®ã¯Portal Keyã¨åãè¦é ã§æããã®ã ãã© å
å´ã®æ£äºåé¢ä½ã®ãã®ã¯ãªãã表é¢ã®æ¨¡æ§ãã¦ã¨ã¦ã¨ã¨åãã¦ãããããã¯ã©ããã£ã¦ãããã ããâ¦ã¨æã£ã¦åã³è§£åããipaã®ä¸èº«ãæ¢ã£ã¦ã¿ãã¨Ingress.app/shaders
ã¨ãããã£ã¬ã¯ããªã«ã·ã§ã¼ãããã°ã©ã ãè²ã
ãã£ã¦ãããã«æ¸ãã¦ãã£ãã
attribute vec3 a_position; attribute vec2 a_texCoord; uniform mat4 u_pMatrix; uniform mat4 u_mvMatrix; uniform float u_elapsedTime; varying vec2 v_texCoord; varying vec4 v_texCoord0And1; void main() { v_texCoord = a_texCoord; v_texCoord0And1 = vec4(a_texCoord, a_texCoord * 1.35); v_texCoord0And1 += vec4(0, u_elapsedTime * 0.6, u_elapsedTime * 0.6, u_elapsedTime * 0.45); gl_Position = u_pMatrix * u_mvMatrix * vec4(a_position, 1.0); }
precision mediump float; uniform sampler2D u_texture; varying vec2 v_texCoord; varying vec4 v_texCoord0And1; void main() { vec4 base = texture2D(u_texture, v_texCoord0And1.xy); vec4 scrolled = texture2D(u_texture, v_texCoord0And1.zw * 1.35); float blend_mask = ((base.g * scrolled.g) + (base.r * scrolled.r)) * 2.0; vec4 colorTint = mix(vec4(vec3(0.5, 0.0, 0.5), 1.0), vec4(vec3(0.5), 1.0), blend_mask - 0.25); gl_FragColor = colorTint + vec4(blend_mask) - vec4(1.0); gl_FragColor.a = 0.5; }
ã¨ããæãã§ãelapsed timeãuniformå¤æ°ã§æ¸¡ãã¦ãããããã¨ã«ãã¯ã¹ãã£åº§æ¨ããããããã®ãçæãã¦ããããã使ã£ã¦åæãã¦ãªããã¤ã¤ã«ã³ã¸ã«ããã£ã½ã模æ§ã®åãã表ç¾ãã¦ãããããã(ããåãã£ã¦ãªã)ããã¯ã¹ãã£ç»åã¯objectXMTexture.tga
ã£ã¦ããè¬ã®æ¨¡æ§ã表ãã¦ãããã¡ã¤ã«ããã£ãã®ã§pngã«å¤æãã¦ä½¿ã£ã¦ã¿ã¦ãã
è¤æ°ã®ã·ã§ã¼ãã使ã£ã¦å¥ã
ã®ãªãã¸ã§ã¯ããæç»ããã®ã«è¯ãæ¹æ³ãããåãããªãã¦ãæ¯ãã¬ã¼ã ãã¨ã«gl.useProgram()
ã§åãæ¿ãã¤ã¤Vertex Buffer ObjectãIndex Buffer Objectãbindããã¦ãã¨ããã£ã¦ãã¾ã£ã¦ããâ¦ãããããã®ç¡é§ã£ã½ãããçããã¨æã£ãã®ã ãã© ã©ãããã°ããã®ããªã
ã¾ãã¨ããããã¯Portal Shieldçãªãã®ãæç»ã§ããããã«ãªã£ããã¨ãããã¨ã§ä»ã®ModãXMPãResonatorã¨ããåããããªæãã§æãã¦éãã§ã¿ããã£ã¨ã