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

Flip the page like a book for foldable phone? #29

Open
Andersonong-github opened this issue Dec 29, 2021 · 1 comment
Open

Flip the page like a book for foldable phone? #29

Andersonong-github opened this issue Dec 29, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@Andersonong-github
Copy link

Screenshot_20211229-223006_Photo Editor.jpg

Add on the flip feature to support foldable phone like a real book?

@gsioteam gsioteam added the enhancement New feature or request label Jan 3, 2022
@gsioteam
Copy link
Owner

gsioteam commented Jan 9, 2022

This is a pretty challenging task. I have been researching how to implement this effect for serval days. and I already have some results, see flip_widget.

I think we can implement the effect through a single shader. My shader is here:

precision mediump float;
uniform sampler2D texture;
uniform float percent;
uniform float tilt;
varying vec2 uv;
void main()
{
    float x1 = uv.x;
    float y1 = 1.0 - uv.y;
    if (tilt * (x1 - percent) > y1) {
        gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
    } else {
        float x0 = (x1 / tilt + y1 + percent * tilt) / (tilt + 1.0/tilt);
        float x2 = 2.0 * x0 - x1;
        float dis = abs(x1 - x0);
        float y2 = 2.0 * (x1 - x0) / tilt + y1 - max(0.0, x2 - percent) * (1.0 - x2) / (1.0 - percent);
        if (y2 > 0.0 && x2 < 1.0) {
            vec4 val = mix(vec4(0.6, 0.6, 0.6, 1.0), vec4(0.98, 0.98, 0.98, 1.0), min(1.0, dis/0.1));
            gl_FragColor = texture2D(texture, vec2(x2, 1.0 - y2)) * val;
        } else {
            gl_FragColor = texture2D(texture, vec2(x1, 1.0 - y1));
        }
    }
}

If someone could give some advice on the shader, it would be a great help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants