{"id":453,"date":"2018-05-14T11:33:31","date_gmt":"2018-05-14T02:33:31","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/05\/14\/shader-picture"},"modified":"2022-10-26T09:21:15","modified_gmt":"2022-10-26T00:21:15","slug":"shader-picture","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/05\/14\/shader-picture\/","title":{"rendered":"Three.js\u3067\u30b7\u30a7\u30fc\u30c0\u304a\u7d75\u304b\u304d\u74b0\u5883\u3092\u4f5c\u3063\u3066\u307f\u305f"},"content":{"rendered":"

\u5165\u793e\u3057\u3066\u7d042\u30f6\u6708\u306b\u306a\u308a\u307e\u3057\u305f\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5185\u5c71\u3067\u3059\u3002
\n\u30ea\u30e2\u30fc\u30c8\u30ef\u30fc\u30af\u3068\u3044\u3046\u50cd\u304d\u65b9\u306f\u81ea\u5206\u306b\u5408\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3001\u3068\u3066\u3082\u5feb\u9069\u306b\u904e\u3054\u3057\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n

\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u306e\u6642\u9593\u3082\u3060\u3044\u3076\u78ba\u4fdd\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u8da3\u5473\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3082\u6357\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n

\u4eca\u56de\u306f\u3001\u6700\u8fd1\u53d6\u308a\u7d44\u3093\u3067\u3044\u308b\u300c\u30b7\u30a7\u30fc\u30c0\u30fc\u304a\u7d75\u304b\u304d\u300d\u306b\u3064\u3044\u3066\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n

\u30b7\u30a7\u30fc\u30c0\u30fc\u304a\u7d75\u304b\u304d\u3068\u306f<\/h1>\n

\u30b7\u30a7\u30fc\u30c0\u30fc\u304a\u7d75\u304b\u304d\u3068\u306f\u3001
\n3DCG\u306e\u8868\u793a\u306a\u3069\u3067\u4f7f\u308f\u308c\u308b\u30b7\u30a7\u30fc\u30c0\u30fc\u3067\u3001\u304a\u7d75\u304b\u304d\u3092\u3057\u3088\u3046\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n

\u4ee5\u4e0b\u306e\u30b9\u30e9\u30a4\u30c9\u3067\u7d39\u4ecb\u3055\u308c\u3066\u3044\u307e\u3059\u3002
\n\u697d\u3057\u3044\uff01Unity\u30b7\u30a7\u30fc\u30c0\u30fc \u304a\u7d75\u63cf\u304d\u5165\u9580\uff01<\/a><\/p>\n

\u5143\u306fUnity\u4e0a\u3067\u884c\u3046\u65b9\u6cd5\u304c\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001
\nWebGL\u4e0a\u3067\u3082\u3067\u304d\u308b\u3093\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3063\u305f\u306e\u3067\u8a66\u3057\u306b\u69cb\u7bc9\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

Three.js\u306e\u5c0e\u5165<\/h1>\n

\u6700\u521d\u306f\u7d20\u306eWebGL\u3092\u4f7f\u3063\u3066\u69cb\u7bc9\u3057\u305f\u306e\u3067\u3059\u304c\u3001\u521d\u671f\u5316\u624b\u9806\u304c\u591a\u304f\u3066\u9762\u5012\u3067\u3057\u305f\u3002
\n\u4eca\u56de\u306f\u7d39\u4ecb\u306e\u305f\u3081\u306b\u3001\u305d\u308c\u3089\u3092\u7c21\u7565\u5316\u3057\u3066\u304f\u308c\u308bThree.js<\/code>\u3092\u5c0e\u5165\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n

\u4ee5\u4e0b\u306e\u30b5\u30a4\u30c8\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u3001three.js<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u696d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u3057\u307e\u3059\u3002
\n
https:\/\/threejs.org\/<\/a><\/p>\n

\u30ad\u30e3\u30f3\u30d0\u30b9\u306e\u6e96\u5099<\/h1>\n

HTML\u306ecanvas\u30bf\u30b0\u3067\u3001\u7d75\u3092\u63cf\u304f\u6e96\u5099\u3092\u3057\u307e\u3059\u3002
\n\u4ee5\u4e0b\u306e\u65b9\u91dd\u3067\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

    \n
  • 400x400\u56fa\u5b9a\u3067\u8868\u793a<\/li>\n
  • \u9802\u70b9\u30b7\u30a7\u30fc\u30c0\u30fc\/\u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u30b7\u30a7\u30fc\u30c0\u30fc\u306fscript\u30bf\u30b0\u5185\u306b\u8a18\u8ff0<\/li>\n<\/ul>\n
    <html>\n<head>\n    <title>Shader Test<\/title>\n    <style>\n        body {\n            border: 0;\n            background-color: white;\n        }\n        canvas {\n            width: 400px;\n            height: 400px;\n            display: block;\n        }\n    <\/style>\n<\/head>\n<body>\n<canvas id="c" width="400" height="400"><\/canvas>\n<script src="three.js"><\/script>\n<script id="vertexShader" type="x-shader\/x-vertex">\n        void main() {\n            gl_Position = vec4( position, 1.0 );\n        }\n<\/script>\n<script id="fragmentShader" type="x-shader\/x-fragment">\n        uniform vec2 u_resolution;\n        uniform float u_time;\n\n        void main() {\n            vec2 st = gl_FragCoord.xy\/u_resolution.xy;\n            gl_FragColor = vec4(st.x, st.y, 0.0, 1.0);\n        }\n<\/script>\n<script>\n  var container;\n  var camera, scene, renderer;\n  var uniforms;\n\n  init();\n  animate();\n\n  function init() {\n    container = document.getElementById( 'c' );\n\n    camera = new THREE.Camera();\n    camera.position.z = 1;\n\n    scene = new THREE.Scene();\n\n    var geometry = new THREE.PlaneBufferGeometry( 2, 2 );\n\n    uniforms = {\n      u_time: { type: "f", value: 1.0 },\n      u_resolution: { type: "v2", value: new THREE.Vector2() },\n      u_mouse: { type: "v2", value: new THREE.Vector2() }\n    };\n\n    var material = new THREE.ShaderMaterial( {\n      uniforms: uniforms,\n      vertexShader: document.getElementById( 'vertexShader' ).textContent,\n      fragmentShader: document.getElementById( 'fragmentShader' ).textContent\n    } );\n\n    var mesh = new THREE.Mesh( geometry, material );\n    scene.add( mesh );\n\n    renderer = new THREE.WebGLRenderer({\n      canvas: container,\n    });\n    renderer.setSize(400, 400);\n    uniforms.u_resolution.value.x = renderer.domElement.width;\n    uniforms.u_resolution.value.y = renderer.domElement.height;\n  }\n\n  function animate() {\n    requestAnimationFrame( animate );\n    render();\n  }\n\n  function render() {\n    uniforms.u_time.value += 0.05;\n    renderer.render( scene, camera );\n  }\n<\/script>\n<\/body>\n<\/html><\/code><\/pre>\n

    \u3053\u308c\u3092\u8868\u793a\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u753b\u50cf\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n

    \"\"<\/p>\n

    \u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u30b7\u30a7\u30fc\u30c0\u30fc\u306b\u3064\u3044\u3066<\/h1>\n

    \u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u30b7\u30a7\u30fc\u30c0\u30fc\u306f\u3001\u5404\u30d4\u30af\u30bb\u30eb\u306e\u8272\u3092\u6c7a\u3081\u308b\u51e6\u7406\u3092\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002
    \n<script id="fragmentShader" type="x-shader\/x-fragment"><\/code>\u3067\u56f2\u308f\u308c\u3066\u3044\u308b\u90e8\u5206\u3067\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002
    \nC\u8a00\u8a9e\u306b\u4f3c\u305fGLSL\u3068\u3044\u3046\u8a00\u8a9e\u3067\u66f8\u304d\u307e\u3059\u3002<\/p>\n

    uniform vec2 u_resolution;\nuniform float u_time;\n\nvoid main() {\n    vec2 st = gl_FragCoord.xy\/u_resolution.xy;\n    gl_FragColor = vec4(st.x, st.y, 0.0, 1.0);\n}<\/code><\/pre>\n

    main\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u3001gl_FragColor\u3068\u3044\u3046\u7279\u5225\u306a\u5909\u6570\u306b\u8272(rgba)\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002
    \n\u4e0a\u8a18\u306e\u4f8b\u3067\u306f\u3001\u30d4\u30af\u30bb\u30eb\u306e\u4f4d\u7f6e(st)\u3092\u8272\u306b\u5909\u63dbvec4(st.x, st.y, 0.0, 1.0)<\/code>\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

    \u3044\u304f\u3064\u304b\u306e\u30b5\u30f3\u30d7\u30eb<\/h1>\n

    \u74b0\u5883\u304c\u69cb\u7bc9\u3067\u304d\u305f\u306e\u3067\u3001\u30b9\u30e9\u30a4\u30c9\u3067\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b\u4f8b\u3092\u540c\u3058\u3088\u3046\u306b\u5b9f\u88c5\u3067\u304d\u308b\u304b\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002
    \nUnity\u306e\u30b5\u30dd\u30fc\u30c8\u6a5f\u80fd\uff1f\u304c\u4f7f\u308f\u308c\u3066\u3044\u308b\u90e8\u5206\u3082\u3042\u3063\u305f\u306e\u3067\u3001\u82e5\u5e72\u66f8\u304d\u76f4\u3057\u304c\u5fc5\u8981\u3067\u3057\u305f\u304c\u3001\u540c\u3058\u7d75\u3092\u63cf\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n

    \u30de\u30eb\u3092\u63cf\u304f<\/h2>\n

    \"\"<\/p>\n

            uniform vec2 u_resolution;\n        uniform float u_time;\n\n        vec4 circle(vec2 st) {\n            float d = distance(vec2(0.5, 0.5), st);\n            float a = 0.4;\n\n            float ret = step(a, d);\n\n            return vec4(ret, ret, ret, 1);\n        }\n\n        void main() {\n            vec2 st = gl_FragCoord.xy\/u_resolution.xy;\n            gl_FragColor = circle(st);\n        }        \n<\/code><\/pre>\n

    \u30de\u30eb\u3092\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u308b<\/h2>\n

    \"\"<\/p>\n

            uniform vec2 u_resolution;\n        uniform float u_time;\n\n        vec4 circle(vec2 st) {\n            float d = distance(vec2(0.5, 0.5), st);\n            float a = abs(sin(u_time*0.5)) * 0.4;\n\n            float ret = step(a, d);\n\n            return vec4(ret, ret, ret, 1);\n        }\n\n        void main() {\n            vec2 st = gl_FragCoord.xy\/u_resolution.xy;\n            gl_FragColor = circle(st);\n        }        <\/code><\/pre>\n

    \u8907\u6570\u306e\u56db\u89d2\u3092\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u308b<\/h2>\n

    \"\"<\/p>\n

            uniform vec2 u_resolution;\n        uniform float u_time;\n\n        vec2 stepVec2(vec2 a, float v) {\n            return vec2(step(a.x, v), step(a.y, v));\n        }\n\n        vec2 fracVec2(vec2 v) {\n            return vec2(fract(v.x), fract(v.y));\n        }\n\n        float wave(vec2 st, float n) {\n            st = (floor(st * n) + 0.5) \/ n;\n            float d = distance(vec2(0.5, 0.5), st);\n            return (1.0 + sin(d * 3.0 - u_time)) * 0.5;\n        }\n\n        float box(vec2 st, float size) {\n            size = 0.5 + size * 0.5;\n            st = stepVec2(st, size) * stepVec2(1.0 - st, size);\n            return st.x * st.y;\n        }\n\n        void main() {\n            vec2 st = gl_FragCoord.xy\/u_resolution.xy;\n\n            float n = 10.0;\n            vec2 xy = fracVec2(st.xy * n);\n            float size = wave(st.xy, n);\n            float ret = box(xy, size);\n            gl_FragColor = vec4(ret, ret, ret, 1);\n        }<\/code><\/pre>\n

    \u307e\u3068\u3081<\/h1>\n

    WebGL\u4e0a\u3067\u30b7\u30a7\u30fc\u30c0\u30fc\u304a\u7d75\u304b\u304d\u306e\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u3066\u307f\u307e\u3057\u305f\u3002
    \nUnity\u3068WebGL\u306f\u4e21\u8005\u3068\u3082GLSL\u3067\u30b7\u30a7\u30fc\u30c0\u30fc\u3092\u5b9f\u88c5\u3059\u308b\u306e\u3067\u3001\u540c\u3058\u3088\u3046\u306b\u304a\u7d75\u304b\u304d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002
    \nWebGL\u3067\u69cb\u7bc9\u3059\u308b\u3053\u3068\u3067\u3001Unity\u304c\u3084\u3063\u3066\u304f\u308c\u3066\u3044\u305f\u3053\u3068\u306a\u3069\u3082\u77e5\u308c\u307e\u3057\u305f\u3002
    \n\u3053\u308c\u304b\u3089\u3082\u4e21\u8005\u3092\u898b\u6bd4\u3079\u3064\u3064\u3001\u30b7\u30a7\u30fc\u30c0\u30fc\u30843D\u307e\u308f\u308a\u306e\u77e5\u898b\u3092\u5e83\u3081\u3066\u3044\u304d\u305f\u3044\u3067\u3059\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5165\u793e\u3057\u3066\u7d042\u30f6\u6708\u306b\u306a\u308a\u307e\u3057\u305f\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5185\u5c71\u3067\u3059\u3002 \u30ea\u30e2\u30fc\u30c8\u30ef\u30fc\u30af\u3068\u3044\u3046\u50cd\u304d\u65b9\u306f\u81ea\u5206\u306b\u5408\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3001\u3068\u3066\u3082\u5feb\u9069\u306b\u904e\u3054\u3057\u3066\u304a\u308a\u307e\u3059\u3002 \u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u306e\u6642\u9593\u3082\u3060\u3044\u3076\u78ba\u4fdd\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u8da3\u5473\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3082\u6357\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u4eca\u56de\u306f\u3001\u6700\u8fd1\u53d6\u308a\u7d44\u3093\u3067\u3044\u308b\u300c\u30b7\u30a7\u30fc\u30c0\u30fc\u304a\u7d75\u304b\u304d\u300d\u306b\u3064\u3044\u3066\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002 \u30b7\u30a7\u30fc\u30c0\u30fc\u304a\u7d75\u304b\u304d\u3068\u306f \u30b7\u30a7\u30fc\u30c0\u30fc\u304a\u7d75\u304b\u304d\u3068\u306f\u3001 3DCG\u306e\u8868\u793a\u306a\u3069\u3067\u4f7f\u308f\u308c\u308b\u30b7\u30a7 […]<\/p>\n","protected":false},"author":5,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[161],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/453"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=453"}],"version-history":[{"count":1,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/453\/revisions"}],"predecessor-version":[{"id":3317,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/453\/revisions\/3317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}