-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve feedback about success of loading a shader
- Loading branch information
Jakub Hlusička
committed
Apr 18, 2020
1 parent
33fd866
commit 87bd196
Showing
4 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Configure builtin uniforms | ||
// These macros are optional, but improve the user experience | ||
#pragma shaderfilter set main__mix__description Main Mix/Track | ||
#pragma shaderfilter set main__channel__description Main Channel | ||
#pragma shaderfilter set main__dampening_factor_attack 0.0 | ||
#pragma shaderfilter set main__dampening_factor_release 0.0001 | ||
uniform texture2d builtin_texture_fft_main; | ||
uniform texture2d builtin_texture_fft_main_previous; | ||
|
||
float remap(float x, float2 from, float2 to) { | ||
float normalized = (x - from[0]) / (from[1] - from[0]); | ||
return normalized * (to[1] - to[0]) + to[0]; | ||
} | ||
|
||
float remap_amplitude(float fft_amplitude) { | ||
float fft_db = 20.0 * log(fft_amplitude / 0.5) / log(10.0); | ||
mat2 x = 1; | ||
|
||
return remap(fft_db, float2(-50, -0), float2(0, 1)); | ||
} | ||
|
||
bool below_db(float2 uv, float fft_amplitude) { | ||
return 1.0 - uv.y < remap_amplitude(fft_amplitude); | ||
} | ||
|
||
float4 render(float2 uv) { | ||
float3 color = image.Sample(builtin_texture_sampler, uv).rgb; | ||
float fft_frequency = uv.x; | ||
float fft_amplitude = builtin_texture_fft_main.Sample(builtin_texture_sampler, float2(fft_frequency, 0.5)).r; | ||
float fft_amplitude_previous = builtin_texture_fft_main_previous.Sample(builtin_texture_sampler, float2(fft_frequency, 0.5)).r; | ||
float value = float(below_db(uv, fft_amplitude)); | ||
float value_previous = float(below_db(uv, fft_amplitude_previous)); | ||
|
||
float difference = value - value_previous; | ||
float rising = float(difference > 0); | ||
float falling = float(difference < 0); | ||
|
||
float4 fft_color = float4(falling, rising, 0.0, abs(difference)); | ||
|
||
return float4(lerp(color, fft_color.rgb, fft_color.a), 1.0); | ||
} |
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