-
Notifications
You must be signed in to change notification settings - Fork 43
WaveformProvider
WaveConductor receives the texture and the size of the waveform as input and returns the texture of the waves to be updated as the output.
Input is done with WaveConductor.Input.
//Get the WaveConductor, give input.
GetComponent<WaveConductor>().Input(...)The output can be set and acquired from WaveConductor.Output.
//set output
GetComponent<WaveConductor>().Output = new RenderTexture(...)
//get output
var output = GetComponent<WaveConductor>().Output;If you can acquire the waveform with WaveConductor, you can use it with a customized shader. To pass the texture of the output waveform to the customizing shader, obtain the material and use Material.SetTexture.
//An example of passing a texture to Shader.
GetComponent<Renderer>().material.SetTexture(...)There are libraries in which several macro processes are defined so that the output result of WaveConductor can be easily used by shaders.
When using a macro with a custom shader, declare it with the shader as follows.
//include wave utility.
#include "Assets/WaveformProvider/Shader/Lib/WaveUtil.cginc"Then use a macro that automatically declares waveform texture data to be used by Shader in variable declaration.
//wave texture definition.
WAVE_TEX_DEFINE(_WaveTex)Expect that the result of WaveConductor.Output will come in '_WaveTex'. The necessary declaration is complete so far. Then you can use the following macro with Vertex / Fragment shader.
WAVE_HEIGHT(waveTex, uv) //Get the height of the wave.
WAVE_NORMAL(waveTex, uv) //Get the normal of the wave.
WAVE_NORMAL_ADJ(waveTex, uv, parallaxScale, normalScale) //Get the normal of the wave. It is possible to set parameters that adjust the intensity of the normal line.For example, the shader that acquires the normal of the waveform and displays it as it is will be as follows.
Shader "Es/WaveformProvider/Sample/WaveNormal"
{
Properties
{
//this property is populated with the wave's RenderTexture.
_WaveTex("Wave",2D) = "gray" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Assets/WaveformProvider/Shader/Lib/WaveUtil.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
//wave texture definition.
WAVE_TEX_DEFINE(_WaveTex)
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _WaveTex);
return o;
}
float4 frag (v2f i) : SV_Target
{
//compute wave normal.
return float4(WAVE_NORMAL(_WaveTex, i.uv), 1);
}
ENDCG
}
}
}The result of WaveConductor.Output comes in '_WaveTex'. With this shader, we output the normal of the wave as it is.