もねスタ

Unity、Blender、Aflame中心にVR/ARなど好き勝手書いていく雑記ブログ

【aframe】エモい空つくろう!空の色を変更・グラデーションにする方法

f:id:saharu54:20180902162704p:plain

さて、今回学ぶことはこちら

  • 空の色の変更方法(単色)
  • 空をグラデーションにする方法

空の色の変更方法(単色)

f:id:saharu54:20180902163105p:plain
まずは空の色を変更する方法です。

<a-sky color="black"></a-sky>

これをa-sceneの中に入れましょう。
終わった!一瞬!!

"black"の部分に色名かカラーコードを入れてください。
ちなみに上の画像は"lightblue"を入れました。
お好みの色名やカラーコードを入れてくださいね。

空をグラデーションにする方法

f:id:saharu54:20180902163307p:plain

空をグラデーションにするにはこちら。

<head>
  <title>Page Title</title>

  <!-- aframeのライブラリ呼び出し -->
  <script src="https://rawgit.com/aframevr/aframe/master/dist/aframe-master.min.js"></script>

  <!-- 空のグラデーションのためのコンポーネント呼び出し -->
  <script src="https://unpkg.com/aframe-environment-component@1.0.0/dist/aframe-environment-component.min.js"></script>

</head>

<body>
  <a-scene>
  <a-sky radius="200" theta-length="110" material="shader:gradientshader;topColor:black;bottomColor:white" geometry="" visible="" id="sky" position=""></a-sky>
  </a-scene>
</body>

skyをグラデーションにできるコンポーネントを追加しています。
https://github.com/supermedium/aframe-environment-component

a-skyの中の"shader:gradientshader;topColor:black;bottomColor:white"
ここでtopColor(天井側の色)とbottomColor(地面側の色)を指定してあげるといい感じのグラデーションな空が完成します。

あと、radius="200" theta-length="110"
ふたつの色の割合とか変更できると思います!(まだ試してない)

上のサンプルで指定したtopColor:black;bottomColor:whiteで実行した空はこんな感じ。
f:id:saharu54:20180902164622p:plain

おまけ

f:id:saharu54:20180902165032p:plain
引用:uiGradients - Beautiful colored gradients

グラデーションの空をいい感じに作り上げるためにこんなサイトを利用してみてはいかがでしょうか!
カラーの組み合わせがとても参考になります。

uigradients.com


エモい空を作りましょう!