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

High-end iPhone displays the image when alpha channel is 0 at runtime only, the screenshot is OK #27102

Closed
scarletsky opened this issue Nov 2, 2023 · 1 comment

Comments

@scarletsky
Copy link

scarletsky commented Nov 2, 2023

Description

This will happen when we try to draw a texture and set its alpha channel to 0 in the shader.

This is a very interesting bug.
It only occurs at runtime in high-end iPhone.
When we try to take a screenshot, the screenshot appears normal.

Here are my tested devices:

  • MacBook Pro (M2 Pro, MacOS 13.3.1), runtime is OK.
  • iPhone 8 (iOS 16.5), runtime is OK.
  • iPhone XR (iOS 15.4), runtime is OK.
  • iPhone SE2 (iOS 14.2), runtime is OK.
  • iPhone 12 Pro Max (iOS 14.8.2), runtime is NOT OK.
  • iPhone 12 Pro Max (iOS 16.1), runtime is NOT OK.
  • iPhone 13 mini (iOS 17.1), runtime is NOT OK.
  • iPhone 13 Pro Max (iOS 16.1), runtime is NOT OK.

Reproduction steps

  1. Open the live example below.
  2. You should see a white square, if you see firefox's logo, it is NOT OK.

Code

import * as THREE from "https://esm.sh/three";

const imgUrl = 'https://mdn.github.io/dom-examples/webgl-examples/tutorial/sample6/cubetexture.png';


const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 2;

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

const textureLoader = new THREE.TextureLoader();
textureLoader.load(imgUrl, (texture) => {
    const customShaderMaterial = new THREE.ShaderMaterial({
        uniforms: {
            u_texture: { value: texture }
        },
        vertexShader: `
            varying vec2 vUv;

            void main() {
                vUv = uv;
                gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
            }
        `,
        fragmentShader: `
            uniform sampler2D u_texture;
            varying vec2 vUv;

            void main() {
                vec4 texel = texture2D(u_texture, vUv);
                texel.a = 0.0;
                gl_FragColor = texel;
            }
        `
    });

    const geometry = new THREE.PlaneGeometry(2, 2);
    const mesh = new THREE.Mesh(geometry, customShaderMaterial);
    scene.add(mesh);
    renderer.render(scene, camera);
});

Live example

https://codepen.io/scarletsky/full/oNmzNPz

Screenshots

Runtime of iPhone XR (OK)
IMG_7561

Runtime of iPhone 12 Pro Max (NOT OK)
IMG_7562

Screenshot of iPhone 12 Pro Max (OK)
20231102-113642

Version

latest

Device

Mobile

Browser

Safari

OS

iOS

@scarletsky scarletsky changed the title High-end iPhone displays the image when alpha channel is 0 in custom shader High-end iPhone displays the image when alpha channel is 0 at runtime only, the screenshot is OK Nov 2, 2023
@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 2, 2023

Please report this issue at the Webkit bugtracker. We can't fix it in this repository.

https://bugs.webkit.org/

@Mugen87 Mugen87 closed this as completed Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants