ShaderLab: #define macro not expanded in swizzle position

Aperta
#2,952 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
typescript

Direzione di ricerca

The payload gives no file names, so start by finding where ShaderLab's preprocessor handles #define and where swizzle tokens after . are parsed. Use the reproduction snippet with res.OCCLUSION_CHANNEL as the failing case. Done means that snippet compiles and produces the same output as res.r, and the existing shader tests still pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

ShaderLab's compiler does not expand #define macros when used in swizzle position (after .). This is valid in standard GLSL but fails in ShaderLab.

Reproduction

#define OCCLUSION_CHANNEL r
#define ROUGHNESS_CHANNEL g
#define METALLIC_CHANNEL b

vec4 res = texture2D(pbrMap, v.v_uv);
pbr.x *= res.OCCLUSION_CHANNEL;   // ❌ CompilationError: Unexpected token OCCLUSION_CHANNEL
pbr.y *= res.ROUGHNESS_CHANNEL;
pbr.z *= res.METALLIC_CHANNEL;

Expected behavior

The preprocessor should expand OCCLUSION_CHANNEL to r before the compiler parses the swizzle, resulting in res.r — which is valid GLSL.

Actual behavior

CompilationError: Unexpected token OCCLUSION_CHANNEL

The compiler encounters OCCLUSION_CHANNEL as an unknown identifier in swizzle position because macro expansion did not occur before swizzle parsing.

Workaround

Replace macro-based swizzle with literal channel names:

pbr.x *= res.r;   // occlusion
pbr.y *= res.g;   // roughness
pbr.z *= res.b;   // metallic

Context

Discovered during Cocos Creator → Galacean ShaderLab migration. Cocos shaders commonly use #define to abstract channel selection (e.g., #pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b])), which works in standard GLSL but breaks in ShaderLab.

Lingua principale
TypeScript
Stelle
5.9k
Fork
413
Merge medio
16h 17m
PR unite (30g)
41

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di galacean/engine

Tutte le issue di galacean/engine

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.