Created
July 15, 2018 18:37
-
-
Save Andersama/b130797d4351f905a78dc7f21e87f4e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uniform float4x4 ViewProj; | |
uniform texture2d image; | |
uniform float elapsed_time; | |
uniform float2 uv_offset; | |
uniform float2 uv_scale; | |
uniform float2 uv_pixel_interval; | |
sampler_state textureSampler { | |
Filter = Linear; | |
AddressU = Border; | |
AddressV = Border; | |
BorderColor = 00000000; | |
}; | |
sampler_state textureSampler_H { | |
Filter = Linear; | |
AddressU = Wrap; | |
AddressV = Border; | |
BorderColor = 00000000; | |
}; | |
sampler_state textureSampler_V { | |
Filter = Linear; | |
AddressU = Border; | |
AddressV = Wrap; | |
BorderColor = 00000000; | |
}; | |
struct VertData { | |
float4 pos : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
VertData mainTransform(VertData v_in) | |
{ | |
VertData vert_out; | |
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj); | |
vert_out.uv = v_in.uv * uv_scale + uv_offset; | |
return vert_out; | |
} | |
#define PI 3.141592653589793238462643383279502884197169399375105820974 | |
#define PIO3 1.047197551196597746154214461093167628065723133125035273658 | |
#define PI2O3 2.094395102393195492308428922186335256131446266250070547316 | |
float melScale(float freq){ | |
return 2595 * log10 (1 + freq / 700.0); | |
} | |
float hertzFromMel(float mel) { | |
return 700 * (pow(10, mel / 2595) - 1); | |
} | |
uniform texture2d audio <bool is_audio_source = true; bool is_fft = true; string window = "blackmann_harris";>; | |
uniform bool vertical; | |
uniform float px_shift <bool is_slider = true; float min = 0; float max = 1920; float step 2;>; | |
uniform bool show_fft; | |
uniform float sample_rate <string expr = "sample_rate";>; | |
uniform float mel_total <string expr = "mel_from_hz(sample_rate / 2)";>; | |
float4 mainImage(VertData v_in) : TARGET | |
{ | |
float2 px; | |
float mel; | |
float hz; | |
float4 color; | |
float px_2; | |
float2 shift; | |
float db; | |
if(vertical){ | |
px = float2((1 - distance(v_in.uv.y, 0.5) * 2), v_in.uv.x); | |
mel = (px.x * mel_total); | |
hz = hertzFromMel(mel); | |
px.x = hz / (sample_rate / 2); | |
color = audio.Sample(textureSampler_V, px); | |
if(show_fft) | |
return color; | |
db = ((log10( 1 / (2 * PI * 1024) * pow(color.r,2) )) + 12) / 12.0; | |
px_2 = (sin(color.r) * db * px_shift); | |
shift = float2(px_2 * uv_pixel_interval.x,0); | |
return image.Sample(textureSampler_H, v_in.uv + shift); | |
} else { | |
px = float2((1 - distance(v_in.uv.x, 0.5) * 2), v_in.uv.y); | |
mel = (px.x * mel_total); | |
hz = hertzFromMel(mel); | |
px.x = hz / (sample_rate / 2); | |
color = audio.Sample(textureSampler_H, px); | |
if(show_fft) | |
return color; | |
db = ((log10( 1 / (2 * PI * 1024) * pow(color.r,2) )) + 12) / 12.0; | |
px_2 = (sin(color.r) * db * px_shift); | |
shift = float2(0, px_2 * uv_pixel_interval.y); | |
return image.Sample(textureSampler_V, v_in.uv + shift); | |
} | |
} | |
technique Draw | |
{ | |
pass p0 | |
{ | |
vertex_shader = mainTransform(v_in); | |
pixel_shader = mainImage(v_in); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment