phandasm / waveform

Audio spectral analysis plugin for OBS
https://obsproject.com/forum/resources/waveform.1423/
GNU General Public License v3.0
512 stars 35 forks source link

add range mode for audio meter #56

Closed filiphanes closed 1 year ago

filiphanes commented 1 year ago

Hi, I am trying to create audio meter similar to sound mixer in obs and other software: green, yellow, red. In obs log there is shader compilation problem, but I dont see problem. Could you help me?

10:00:21.005: Error compiling shader:
10:00:21.005: ERROR: 0:35: Use of undeclared identifier 'vert'
10:00:21.005: ERROR: 0:37: Use of undeclared identifier 'vert'
10:00:21.005: 
10:00:21.005: 
10:00:21.005: device_pixelshader_create (GL) failed
10:00:21.005: Pass (0) <> missing pixel shader!
... other logs
10:00:21.112: effect_setval_inline: invalid param
10:00:21.112: No vertex shader specified
10:00:21.112: device_draw (GL) failed

Maybe I am not properly reinstalling new compilation? Thanks

filiphanes commented 1 year ago

it works now, only conditions in shader needs to be correctly adjusted

phandasm commented 1 year ago

Assuming this is meant to work the way I think, you can just copy the gradient pixel shader to normalize the texture coordinate to the range [0, 1]. i.e. something like this:

float4 PSRange(VertGrad vert_in) : TARGET
{
    float4 color = float4(1.0, 0.0, 0.0, 1.0);  // Default to red

    float ratio = saturate((distance(vert_in.tex.y, grad_center) - grad_offset) / grad_height);
    if (ratio < 0.75)
        color = float4(0.0, 1.0, 0.0, 1.0);  // Green
    else if (ratio < 0.9)
        color = float4(1.0, 1.0, 0.0, 1.0);  // Yellow

    return color;
}

Shader vars are set here. The gradient case pretty much does everything you need, except you probably want to set grad_height like this:

gs_effect_set_float(grad_height, cpos - channel_offset);
filiphanes commented 1 year ago

How do you debug shader faster than recompiling and reinstalling whole package and restarting obs?

filiphanes commented 1 year ago

ok, now I am happy with it, if you have any more ideas or expectations, I can update it

phandasm commented 1 year ago

Looks good, thanks!