【Shader Graph】図形を回転させる
はじめに
前回の記事で作った平面図形を描画するシェーダーに回転を追加する
Shader Graphで図形を回転させる方法
Rotateノードを使ってPolarCoordinatesを回転させる。
Unitで回転量の単位を選べる(Radian or Degrees)。
Rotate ノード | Shader Graph | 10.0.0-preview.27
シェーダー作成
環境
- Unity 2020.3.18f1
- Universal Render Pipeline 10.6.0
- Shader Graph 10.6.0
Graph
出力結果
図形の回転を制御するスクリプトのサンプル
using UnityEngine; using UnityEngine.UI; namespace ProceduralShapesShaderPack.Samples { public class ShapeRotation : MonoBehaviour { [SerializeField] private Renderer _targetShape; [SerializeField] private Slider _slider; private Material _material; private int _rotationPropertyId; void Awake() { _rotationPropertyId = Shader.PropertyToID("Rotation_Degrees"); _material = _targetShape.material; _slider.onValueChanged.AddListener(value => { _material.SetFloat(_rotationPropertyId, value); }); } } }