Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add range mode for audio meter #56

Merged
merged 2 commits into from Sep 2, 2023
Merged

add range mode for audio meter #56

merged 2 commits into from Sep 2, 2023

Conversation

filiphanes
Copy link
Contributor

@filiphanes filiphanes commented Sep 1, 2023

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
Copy link
Contributor Author

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

@phandasm
Copy link
Owner

phandasm commented Sep 1, 2023

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
Copy link
Contributor Author

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

@filiphanes
Copy link
Contributor Author

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

@phandasm
Copy link
Owner

phandasm commented Sep 2, 2023

Looks good, thanks!

@phandasm phandasm merged commit d1065f5 into phandasm:master Sep 2, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants