Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

@typegpu/gl: builtin.position in fragment shaders has a bottom-left origin (gl_FragCoord)

オープン
#3,215 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
backend

調査の方向性

Start by reading packages/typegpu-gl/src/glslGenerator.ts, especially glslInputForBuiltin, and trace how fragment position is translated for the GL fallback. Compare the coordinate behavior with WebGPU and inspect how draw targets expose their height; the proposal leaves the implementation choice open. Done means fragment position has consistent top-left coordinates across both backends, with coverage for the reported top-band repro.

索引モデルが issue の本文から書いたものです。

説明

bug

Description

In a fragment shader, d.builtin.position is translated directly to gl_FragCoord (glslInputForBuiltin in packages/typegpu-gl/src/glslGenerator.ts). The two use different origins:

  • WGSL @builtin(position): (0, 0) is the top-left of the framebuffer, +y down.
  • GLSL gl_FragCoord: (0, 0) is the bottom-left, +y up.

So any shader that works in pixel coordinates (dithering, pixel grids, textureLoad with the fragment position, screen-space effects) renders vertically flipped on the GL fallback compared to WebGPU.

Repro

const fragment = tgpu.fragmentFn({ in: { pos: d.builtin.position }, out: d.vec4f })(({ pos }) => {
  'use gpu';
  // Red band along the top 10 pixels.
  return std.select(d.vec4f(0, 0, 0, 1), d.vec4f(1, 0, 0, 1), pos.y < 10);
});
  • WebGPU root: the red band is at the top.
  • initWithGL() root: the red band is at the bottom.

Proposal

Emit a flipped coordinate, e.g. vec4(gl_FragCoord.x, u_targetHeight - gl_FragCoord.y, gl_FragCoord.zw). The target height would be a uniform set per draw from the color attachment. Alternatively, render upside down and flip on presentation, so the builtins and texture orientation match WebGPU everywhere.

Workaround

Derive pixel coordinates from an interpolated UV varying instead of the position builtin.


Found in @typegpu/gl 0.12.6. Related: #1637.

主要言語
TypeScript
スター
3.3k
フォーク
135
平均マージ
4日 1時間
マージ済み PR(30日)
64

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/TypeGPU のほかの issue

software-mansion/TypeGPU の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。