Skip to content

Transparency modes review - #333

Merged
Bigfoot71 merged 15 commits into
masterfrom
pass-review
Aug 19, 2026
Merged

Transparency modes review#333
Bigfoot71 merged 15 commits into
masterfrom
pass-review

Conversation

@Bigfoot71

Copy link
Copy Markdown
Owner

Transparency Modes

This PR revises the transparency modes, introducing three modes: OPAQUE, HYBRID, and BLEND:

typedef enum R3D_TransparencyMode {
    R3D_TRANSPARENCY_OPAQUE,        ///< Fully opaque in G-Buffer (supports hard alpha cutoff/masking). Ignores blend mode.
    R3D_TRANSPARENCY_HYBRID,        ///< Two-pass rendering: opaque cutoff in G-Buffer + forward blending.
    R3D_TRANSPARENCY_BLEND,         ///< Blended only (forward pass, no depth write / shadow casting).
} R3D_TransparencyMode;

The behavior is similar to the previous modes, but the internal logic is now clearer and more efficient.

The HYBRID mode first renders an opaque pass for fragments above the alpha cutoff, followed by a blended pass for fragments below the cutoff.

It's also worth noting that the hybrid logic naturally works with unlit materials without requiring any additional logic. There isn't much practical benefit to using it for unlit materials though, so it's preferable to render them directly using BLEND.

Blend Modes

Blend modes are now only applied to BLEND and to the below-cutoff portion of HYBRID. Previously, there was a special case for ADDITIVE when transparency was DISABLED, which resulted in a different blend mode. This was somewhat unclear, so I introduced the ADD_ALPHA blend mode and kept ADDITIVE as a straightforward ONE, ONE blend.

Complete enum with the new ADD_ALPHA:

typedef enum R3D_BlendMode {
    R3D_BLEND_ALPHA,                ///< Standard alpha blending: source color is blended using its alpha channel.
    R3D_BLEND_ADDITIVE,             ///< Pure additive blending: source color is added directly to destination (ignores alpha).
    R3D_BLEND_ADD_ALPHA,            ///< Alpha-modulated additive blending: source color scaled by alpha before adding to destination.
    R3D_BLEND_MULTIPLY,             ///< Multiply blending: source color is multiplied with destination, darkening the image.
    R3D_BLEND_PREMULTIPLIED_ALPHA   ///< Premultiplied alpha blending: assumes source color is already multiplied by its alpha.
} R3D_BlendMode;

Shader Usages

For shader #pragma usage, the prepass mode has been removed, and transparent has been renamed to blend for consistency with R3D_TransparencyMode.

Alpha Cutoff

The default material alpha cutoff has also been changed from 0.01f to 0.5f. This makes the behavior more natural in most cases and also matches the standard behavior expected for glTF models when no explicit alpha cutoff is defined.

Internal Rendering Changes

I also made a few adjustments to the internal rendering-pass logic. These changes helped facilitate the new transparency system and will also serve as preliminary groundwork for the future scene/context architecture and transparent background support.

@Bigfoot71
Bigfoot71 merged commit 920ff34 into master Aug 19, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant