Limeth / obs-shaderfilter-plus

obs-shaderfilter rewritten in Rust and improved
Other
183 stars 19 forks source link

UVs with stacked shaders #5

Closed Froyok closed 4 years ago

Froyok commented 4 years ago

I have been trying out shaderfilter-plus for a few days now (and it's great !) and I stumbled upon a behavior that I'm not sure if it's a bug or by design.

I'm trying to build generic effects that I can re-use over different sources in OBS and also to make the shaders easier to manage and maintain. So I built a first shader that applies an animated gradient by manipulating the UV coordinates. Then I added a second shader to perform another kind of gradient/UV based animation.

Current behavior: When shaders are stacked, it seems the second shader inherit the UVs from the previous one (or something alike).

Expected behavior: When shaders are stacked, the given uv variable at the entry or render() should give the same values with or without stacked shaders.


The current behavior prevent the creation of effects based on multiple pass (like separable/box blurs) and make other effects difficult to build if you have to take into account previous shaders.

Demo of the behavior


Simple Shader code to replicate that behavior:

Shader 1

float4 render(float2 uv)
{
    vec4 Result = image.Sample(builtin_texture_sampler, uv);
    float Mask = fract( uv.x + builtin_elapsed_time * 2.0 );
    Mask = abs( Mask * 2.0 - 1.0 );

    Result.rgb *= Mask;
    return Result;
}

Shader 2

float4 render(float2 uv)
{
    return vec4( uv.x, uv.y, 0.0, 1.0 );
}
Limeth commented 4 years ago

Hello, can you please describe the behavior that you would expect? I'm not sure I understand the issue. Preceding shaders do not let you change the UV coordinates for the following shaders. The current behavior as shown in the demo seems correct to me.

Froyok commented 4 years ago

After looking more closely, following up your answer, I think I made a mistake. :)

I think I got confused by the UI and the order in which shaders are applied. I thought the shaders were stacked from bottom to top (like a layer stack), while in fact it's the opposite. So the first shader to be applied is the one at the top of the list. Now that I understand that, it seems there is indeed no issues.

Limeth commented 4 years ago

Glad to hear that, if you run into any other problems, feel free to make another issue. :)