http://baba-s.hatenablog.com/entry/2017/12/30/230200を使わせていただき、
上記のページにあるスクリプト(下記)は、音に合わせてy軸にスケールが上がりますが、
音に合わせて分解したポリゴンを広げたいと思ってます。
using UnityEngine; public class Example : MonoBehaviour { public AudioSpectrum spectrum; public Transform[] cubes; public float scale; private void Update() { for ( int i = 0; i < cubes.Length; i++ ) { var cube = cubes[ i ]; var localScale = cube.localScale; localScale.y = spectrum.Levels[ i ] * scale; cube.localScale = localScale; } } } ```分解したポリゴン(下記シェーダ)_PositionFactorのパラメーターをスクリプトで弄れるようにし(上記)のスクリプトを参考に音に合わせてポリゴンを広げたいと色々調べ試していたのですが分からず詰まってしまい、わかる方がいましたら返信くださると嬉しいです。 何卒よろしくお願いいたします。 ```ここに言語名を入力 Shader "Unlit/NewUnlitShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _PositionFactor("Position Factor", Range(0.0, 1.0)) = 0.2 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Cull off Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma geometry geom #include "UnityCG.cginc" struct v2g { float4 vertex : POSITION; float3 normal : NORMAL; float2 uv : TEXCOORD0; }; struct g2f { float2 uv : TEXCOORD0; float4 pos : SV_POSITION; fixed4 col : COLOR; }; sampler2D _MainTex; float4 _MainTex_ST; v2g vert (appdata_base v) { v2g o; o.vertex = v.vertex; o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); o.normal = v.normal; return o; } float _PositionFactor; [maxvertexcount(3)] void geom(triangle v2g input[3], inout TriangleStream<g2f> tristream) { g2f o; float3 edgeA = input[1].vertex - input[0].vertex; float3 edgeB = input[2].vertex - input[0].vertex; float3 normalFace = normalize(cross(edgeA, edgeB)); for (int i = 0; i < 3; i++) { o.pos = UnityObjectToClipPos(input[i].vertex + float4(normalFace, 0) * _PositionFactor); o.uv = input[i].uv; o.col = fixed4(0, 0, 0, 1.); tristream.Append(o); } tristream.RestartStrip(); } fixed4 frag (g2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); return col; } ENDCG } } }
回答1件
あなたの回答
tips
プレビュー