こんにちは!SensitiveCubeです!
このチュートリアルでは、ホログラムインディケーターの作成方法を解説します。
この記事では、Cinema4Dを使ったUVの編集とノーマルマップのベイク、PhotoshopとQuixelを使ってノーマルマップの編集、Unity Amplify shader Editorを使ってシェーダーの作成、Unity Playmakerを使ってノードベースでのスクリプティングを行います。.
![Screenshot (259) - STYLY hologram indicator by sensitiveCube](https://styly.cc/wp-content/uploads/2018/10/Screenshot-259-1024x615.png)
UnityでAmplify shader editorとPlayMakerを使用する 1
Amplify Shader Editorを使用してシェーダーを作成:最初のノードを追加
まず、次のアセットをUnityへインポートしてください。
indi_indiset.fbx, indiNormal_quixel.png, screenMask.png, lineNoise.png と wagerFlag.jpg(またはお好みの画像)を5つです。
FBXファイルを選択し、Inspector > Materials から Extract Materials をクリックしてください。
また、RigのAnimation TypeはLegacyに変更してください。
ホログラム用のシェーダーを作成しましょう。このチュートリアルでは、Amplify Shader Editorを使用します。
まずProjectパネルでAmplify Surface Shaderを作成します。
![Screenshot (252) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-252-1.png)
UnityでAmplify shader editorとPlayMakerを使用する 2
エディター編集ウィンドウが開きます。
ウィンドウの左側で、名前を”hologram”に変更してください。
そしてパラメータを変更します。Light ModeをUnlitに、Shader Modelを2.5に、Blend ModeをTransparentに変更してください。Rendering Platformsのパラメータはすべてオンにしてください。
![Screenshot (221) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-221.png)
UnityでAmplify shader editorとPlayMakerを使用する 3
では最初のノード、Color nodeを追加します。
エディター画面で右クリックし、Colorを検索、”Color[5]”をクリックしてください。
![Screenshot (234) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-234.png)
UnityでAmplify shader editorとPlayMakerを使用する 4
TypeをPropertyに変更し、Emissionに接続してください。
Colorはwhiteに変更します。
Texture sample nodeを追加し、”ScreenMask.png”を選択、RをOpacityへ接続してください。
![Screenshot (218) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-218-1024x439.png)
UnityでAmplify shader editorとPlayMakerを使用する 5
ではシェーダーを確認してみましょう。
”indiHolo”マテリアルを選択し、Shader を “hologram”に変更してください。
![Screenshot (225) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-225.png)
UnityでAmplify shader editorとPlayMakerを使用する 6
HierarchyパネルからCubeを作成し、マテリアルを適用してください。良い感じですね。
![Screenshot (226) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-226-1024x513.png)
UnityでAmplify shader editorとPlayMakerを使用する 7
Amplify Shader Editorを使用してシェーダーを作成:texture animation
新しくTexture sampleノードを作成し、”lineNoise.png”を選択します。
そしてこれらのテクスチャを合成します。
Multiplyノードを追加し、両テクスチャの”R”をMultiplyノードへ接続してください。
そしてMultiplyは”Opacity”へ接続してください。
![Screenshot (229) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-229.png)
UnityでAmplify shader editorとPlayMakerを使用する 9
これでシェーダーを確認してみます。
では、”lineNoise.png”へアニメーションを追加します。
5つのノードが必要となり、少し複雑なので、まず下の画像で全体図を確認してください。
![Screenshot (231) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-231-1024x704.png)
UnityでAmplify shader editorとPlayMakerを使用する 10
このノードで何をしているかというと、テクスチャのUVを垂直方向に時間で変化させます。
Vector node には animation vertical を設定します。
Time Parameter ではアニメーションスピードを設定します。
更にTexture SamplesとMultiplyのふたつのノードを追加します。
Texture Samplesには”waterFlag.jpg”を追加し、Multiplyに接続してください。
Color nodeもMultiplyに接続し、MultiplyをEmissionに接続してください。
![Screenshot (232) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-232-1024x623.png)
UnityでAmplify shader editorとPlayMakerを使用する 11
Playmakerを使ってビジュアルスクリプティング:準備
では、シェーダーが完成したのでFBXで確認してみましょう。
Projectの”indi_indiset”を選択、InspectorのAnimationをオンにし、Playボタンをクリックしてください。
![Screenshot (233) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-233-921x1024.png)
UnityでAmplify shader editorとPlayMakerを使用する 12
シェーダーをアニメーション付きで確認することができます。マテリアルは以下の図のように設定してください。
![Screenshot (236) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-236-485x1024.png)
UnityでAmplify shader editorとPlayMakerを使用する 13
![Screenshot (237) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-237-478x1024.png)
UnityでAmplify shader editorとPlayMakerを使用する 14
最後に、Playmakerでビジュアルスクリプティングを行います。
プレイヤーとの距離によってホログラムのオンオフが切り替わるよう設定します。”indi_indiset”を選択し、Inspectorを開きます。
![Screenshot (255) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-255.png)
UnityでAmplify shader editorとPlayMakerを使用する 15
![Screenshot (256) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-256.png)
UnityでAmplify shader editorとPlayMakerを使用する 16
RigのAnimation TypeはLegacyに設定します。
Animationでは、クリップを2つ作成しDurationを変更します。
”open”を0.0から50.0で設定し、”close”を50.0から100.0で設定します。
設定後、”indi_indiset”をHierarchyに追加してください。
Playmakerを使ってビジュアルスクリプティング:距離によって変化させる
Inspectorパネルを開き、AnimationのPlay automaticallyをオフにします。Add Componentをクリックし、PlayMakerFSMをクリックしてください。
![Screenshot (257) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-257.png)
UnityでAmplify shader editorとPlayMakerを使用する 17
PlayMakerエディタを開きます。
最初にカメラ情報を取得します。取得の方法は以下の記事を参照します。
Init stateで、Fin Game Objectのアクションを挿入します。Object Nameの項目に”[VRTK]_VIVE”を入力します。
Main CameraをStore内のNew Variable…を選択し、”mainCam”変数へ保存します。
waitNearとwaitFarステートはそれぞれメインカメラ(=プレイヤー)とオブジェクト間の距離を確認します。
![3 - STYLY](https://styly.cc/wp-content/uploads/2018/11/3-1-1024x481.png)
UnityでAmplify shader editorとPlayMakerを使用する 18
”switchVal”より距離が大きい/小さい時、openAnim/closeAnimステートに変遷します。
openAnimとcloseAnimステートではアニメーションが再生され、次のステートに移ります。この動きはUnityのPlayモードでMain Cameraを動かすことで確認することができます。
![Screenshot (244) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-244-1024x453.png)
UnityでAmplify shader editorとPlayMakerを使用する 19
![Screenshot (245) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-245-1024x453.png)
UnityでAmplify shader editorとPlayMakerを使用する 20
![Screenshot (246) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-246-1024x467.png)
UnityでAmplify shader editorとPlayMakerを使用する 21
![Screenshot (247) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-247-1024x454.png)
UnityでAmplify shader editorとPlayMakerを使用する 22
![Screenshot (248) - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Screenshot-248.png)
UnityでAmplify shader editorとPlayMakerを使用する 23
![Unity-2017.4 - STYLY Hologram indicator : tutorial 3 Unity with Amplify shader editor and playmakerHologram indicator : tutorial 3 Unity with Amplify shader editor and playmaker](https://styly.cc/wp-content/uploads/2018/10/Unity-2017.4.gif)
UnityでAmplify shader editorとPlayMakerを使用する 24
問題なく動くようであれば、STYLYへアップロードし完成です!お疲れ様でした!