Skip to content

Commit 5dea0cc

Browse files
committed
RMS値によるビジュアライザを追加
1 parent 144364c commit 5dea0cc

8 files changed

+637
-0
lines changed

Assets/AudioTexture/Examples/RMSVisualizer.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_PrefabParentObject: {fileID: 0}
8+
m_PrefabInternal: {fileID: 0}
9+
m_Name: RMSVisualizer
10+
m_Shader: {fileID: 4800000, guid: 20753a619ac6b8c4ea1f1bff9de7ef51, type: 3}
11+
m_ShaderKeywords:
12+
m_LightmapFlags: 4
13+
m_EnableInstancingVariants: 0
14+
m_DoubleSidedGI: 0
15+
m_CustomRenderQueue: -1
16+
stringTagMap: {}
17+
disabledShaderPasses: []
18+
m_SavedProperties:
19+
serializedVersion: 3
20+
m_TexEnvs:
21+
- _BumpMap:
22+
m_Texture: {fileID: 0}
23+
m_Scale: {x: 1, y: 1}
24+
m_Offset: {x: 0, y: 0}
25+
- _DetailAlbedoMap:
26+
m_Texture: {fileID: 0}
27+
m_Scale: {x: 1, y: 1}
28+
m_Offset: {x: 0, y: 0}
29+
- _DetailMask:
30+
m_Texture: {fileID: 0}
31+
m_Scale: {x: 1, y: 1}
32+
m_Offset: {x: 0, y: 0}
33+
- _DetailNormalMap:
34+
m_Texture: {fileID: 0}
35+
m_Scale: {x: 1, y: 1}
36+
m_Offset: {x: 0, y: 0}
37+
- _EmissionMap:
38+
m_Texture: {fileID: 0}
39+
m_Scale: {x: 1, y: 1}
40+
m_Offset: {x: 0, y: 0}
41+
- _MainTex:
42+
m_Texture: {fileID: 2800000, guid: 8ff1cf269c265fd47aeb878a162542b1, type: 2}
43+
m_Scale: {x: 1, y: 1}
44+
m_Offset: {x: 0, y: 0}
45+
- _MetallicGlossMap:
46+
m_Texture: {fileID: 0}
47+
m_Scale: {x: 1, y: 1}
48+
m_Offset: {x: 0, y: 0}
49+
- _OcclusionMap:
50+
m_Texture: {fileID: 0}
51+
m_Scale: {x: 1, y: 1}
52+
m_Offset: {x: 0, y: 0}
53+
- _ParallaxMap:
54+
m_Texture: {fileID: 0}
55+
m_Scale: {x: 1, y: 1}
56+
m_Offset: {x: 0, y: 0}
57+
m_Floats:
58+
- _BumpScale: 1
59+
- _Cutoff: 0.5
60+
- _DetailNormalMapScale: 1
61+
- _DstBlend: 0
62+
- _GlossMapScale: 1
63+
- _Glossiness: 0.5
64+
- _GlossyReflections: 1
65+
- _Metallic: 0
66+
- _Mode: 0
67+
- _OcclusionStrength: 1
68+
- _Parallax: 0.02
69+
- _SmoothnessTextureChannel: 0
70+
- _SpecularHighlights: 1
71+
- _SrcBlend: 1
72+
- _UVSec: 0
73+
- _ZWrite: 1
74+
m_Colors:
75+
- _Color: {r: 1, g: 1, b: 1, a: 1}
76+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Assets/AudioTexture/Examples/RMSVisualizer/RMSVisualizer.mat.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Shader "AudioTexture/RMSVisualizer"
2+
{
3+
Properties
4+
{
5+
_MainTex ("Texture", 2D) = "white" {}
6+
_SamplingFrequency ("Sampling Frequency", float) = 44100
7+
_Color ("Color", Color) = (1, 1, 1, 0)
8+
_Window ("Window Length (seconds)", float) = 0.01
9+
}
10+
SubShader
11+
{
12+
Tags { "RenderType"="Opaque" }
13+
LOD 100
14+
15+
Pass
16+
{
17+
CGPROGRAM
18+
#pragma vertex vert
19+
#pragma fragment frag
20+
// make fog work
21+
#pragma multi_compile_fog
22+
#pragma target 5.0
23+
24+
#include "UnityCG.cginc"
25+
26+
struct appdata
27+
{
28+
float4 vertex : POSITION;
29+
};
30+
31+
struct v2f
32+
{
33+
UNITY_FOG_COORDS(1)
34+
float4 vertex : SV_POSITION;
35+
};
36+
37+
UNITY_DECLARE_TEX2D(_MainTex);
38+
float _SamplingFrequency;
39+
fixed4 _Color;
40+
float _Window;
41+
42+
v2f vert (appdata v)
43+
{
44+
float width, height;
45+
_MainTex.GetDimensions(width, height);
46+
float startTime = _Time.y - _Window;
47+
float sum = 0.0;
48+
[unroll(_Window * 48000)]
49+
for (float audioSamplePos = startTime * _SamplingFrequency; audioSamplePos < _Time.y * _SamplingFrequency; audioSamplePos++) {
50+
float2 uv = float2(fmod(audioSamplePos, width) / width, audioSamplePos / width / height);
51+
float2 audio = _MainTex.SampleLevel(sampler_MainTex, uv, 0) * 2.0 - 1.0;
52+
sum += audio.x * audio.x;
53+
}
54+
float rms = sqrt(sum / (_Window * _SamplingFrequency));
55+
56+
v2f o;
57+
o.vertex = UnityObjectToClipPos(v.vertex * rms);
58+
UNITY_TRANSFER_FOG(o,o.vertex);
59+
return o;
60+
}
61+
62+
fixed4 frag (v2f i) : SV_Target
63+
{
64+
// sample the texture
65+
fixed4 col = _Color;
66+
// apply fog
67+
UNITY_APPLY_FOG(i.fogCoord, col);
68+
return col;
69+
}
70+
ENDCG
71+
}
72+
}
73+
}

Assets/AudioTexture/Examples/RMSVisualizer/RMSVisualizer.shader.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)