Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Black opaque background on transparent Phaser.Text textures in Phaser 4.2.1 on older iOS WebGL

Đang mở Phù hợp với người mới
#7,392 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript
Lĩnh vực
game-dev

Hướng nghiên cứu

Tìm tệp shader WebGL ApplyTint.glsl trong cây mã nguồn Phaser. Thêm điều kiện bảo vệ trả về sớm được cung cấp cho các texel có alpha bằng không trước phép chia khử tiền nhân, để khắc phục vấn đề nền đen đục trên các thiết bị iOS WebGL cũ. Xác minh bản sửa bằng mã mẫu kết xuất văn bản đi kèm và xác nhận văn bản trong suốt được kết xuất chính xác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version

  • Phaser Version: 4.2.1
  • Operating system: iPad OS 16.4

Description

Problem
In our game Tvers (www.nrk.no/spill/tvers) we got reports from people playing on older iPads that there were black backgrounds behind out letter tiles after we upgraded to Phaser 4.2.1. We spent a lot of time trying to debug the behaviour and traced it to a division by zero issue in ApplyTint.glsl.

On older iOS devices (<= iPad OS 16.4), Phaser Text objects with black fill rendered on top of a transparent background show as black rectangles with faint aliased edges. On newer devices the transparency works as expected. In Phaser 3.8 this was not a problem.

Cause

The WebGL tint shader (ApplyTint.glsl) performs an unpremultiply of the text texture:

vec3 unpremultTexture = texture.rgb / texture.a;

Outside the character glyph, the canvas-generated texture stores pixels with RGB = 0 and alpha = 0. Dividing zero by zero results in undefined behavior (NaN or Infinity). How the shader handles that NaN varies between GPUs/drivers. On the affected devices it propagates, producing a visible opaque black rectangle instead of transparent.

Fix

Guard the division by returning early for zero-alpha texels:

if (texture.a <= 0.0) {
return vec4(0.0);
}
vec3 unpremultTexture = texture.rgb / texture.a;

Example Test Code

const textStyling = {

  fontSize: '80px',

color: 'black',

fontFamily: 'sans-serif',

fontStyle: 'bold',

padding: { x: 10, y: 10 },

}
const background = this.scene.add

      .image(0, 0, 'tile')

      .setTint(palette.boardSquare)

      .setTintMode(Phaser.TintModes.FILL)

const letter = this.scene.add.text(0, 0, this.letter, textStyling)

Phaser.Display.Align.In.Center(letter, background)
Ngôn ngữ chính
JavaScript
Star
40.5k
Fork
7.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của phaserjs/phaser

Tất cả issue của phaserjs/phaser

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.