Translucent entities render in opaque pass instead of transparent pass #46

Closed
opened 2026-03-20 06:16:49 +00:00 by kit · 0 comments
Owner

Problem

Entities with translucent materials (refract, translucent props, etc.) render during the opaque pass (layer 0) instead of the transparent pass (layer 2). This means only the skybox is visible through them — opaque entities and BSP geometry behind them are not composited correctly.

Visible in

shader_test_01 ground truth vs our render — the bottom two rows of cubes should show the caution tape and wall through them, but instead appear opaque or show only skybox.

Root cause

The layer 2 assignment in _loadMaterialTexture (loader.js) only applies to BSP world meshes. For entities, _applyEntityTransparency (scene.js) only checks entity color alpha — it doesn't account for materials that are inherently transparent (via $translucent, $alphatest, refract shader, etc.).

When an entity's model has a transparent material but entity color alpha is 1.0, the mesh stays on layer 0 and renders during the opaque pass.

Fix

After entity materials are resolved (model loading + material overrides), check if any mesh material has transparent = true and assign those meshes to layer 2 regardless of entity color alpha. This needs to happen in:

  • _replaceWithModel (scene.js) — when a model template replaces a placeholder
  • _refreshMaterialOverrides (scene.js) — when materials are swapped at runtime
  • Potentially in the model loader itself when materials are first applied
  • #42 (closed) — BSP transparent render ordering (fixed, but entity path incomplete)
## Problem Entities with translucent materials (refract, translucent props, etc.) render during the opaque pass (layer 0) instead of the transparent pass (layer 2). This means only the skybox is visible through them — opaque entities and BSP geometry behind them are not composited correctly. ## Visible in `shader_test_01` ground truth vs our render — the bottom two rows of cubes should show the caution tape and wall through them, but instead appear opaque or show only skybox. ## Root cause The layer 2 assignment in `_loadMaterialTexture` (loader.js) only applies to BSP world meshes. For entities, `_applyEntityTransparency` (scene.js) only checks entity color alpha — it doesn't account for materials that are inherently transparent (via `$translucent`, `$alphatest`, refract shader, etc.). When an entity's model has a transparent material but entity color alpha is 1.0, the mesh stays on layer 0 and renders during the opaque pass. ## Fix After entity materials are resolved (model loading + material overrides), check if any mesh material has `transparent = true` and assign those meshes to layer 2 regardless of entity color alpha. This needs to happen in: - `_replaceWithModel` (scene.js) — when a model template replaces a placeholder - `_refreshMaterialOverrides` (scene.js) — when materials are swapped at runtime - Potentially in the model loader itself when materials are first applied ## Related - #42 (closed) — BSP transparent render ordering (fixed, but entity path incomplete)
kit closed this issue 2026-03-20 06:24:31 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kit/gmod-web-stream#46
No description provided.