Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Alphatest transparency #956

Open
SirYodaJedi opened this issue Jan 9, 2023 · 3 comments
Open

[Feature] Alphatest transparency #956

SirYodaJedi opened this issue Jan 9, 2023 · 3 comments
Labels

Comments

@SirYodaJedi
Copy link
Contributor

SirYodaJedi commented Jan 9, 2023

Blurb

Would alphatest transparency for brush textures a feature that is within the scope of this source port? Currently the only way in YQ2 to have a texel be fully transparent is to flag a texture as TRANS33 or TRANS66, which results in the rest of the texture being translucent. Supporting an alphatest surface flag would solve this, while also making the given surface cheaper to render (no need for translucency sorting).

Quake2Max and FTEQW treat having both TRANS33 and TRANS66 enabled as "TRANS99", denoting an alphatested texture. While convenient for mappers, this breaks many legacy textures that were improperly flagged.

KMQuake2 and Quake2Pro use the custom 0x02000000 surface flag to denote a texture that should be alphatested. This ensures that existing textures created for Vanilla Quake II maps aren't improperly rendered, while adding support for exisiting textures designed for the aforementioned source ports.

Alphatesting works well for stuff like grates, fences, and foliage, and I think using the surface flag from KMQuake2 would avoid breaking vanilla engine stuff.

Implementation

Detecting which texels are transparent differs slightly between paletted and true color images.

  • 8-bit textures (WAL and M8) detect use the same method as Half-Life and most Quake 1 source ports: index 255 is transparent, whereas all other texels are opaque.
  • 32-bit textures (TGA and PNG) use the alpha channel. Any texels with less than 127 alpha are transparent, whereas texels with greater than or exactly 127 alpha are opaque. This also should "just work" for 8-bit PNGs, looking at the code used to load them.

In theory, SURF_ALPHATEST should be able to be combined with SURF_TRANS33 or SURF_TRANS66, doing an alpha clip in addition to the regular translucency.

@Yamagi Yamagi added the feature label Jan 21, 2023
@SirYodaJedi
Copy link
Contributor Author

Looks like the new Kex remaster supports alphatest as well.
https://github.com/id-Software/quake2-rerelease-dll#surfflags_t

@0lvin
Copy link
Contributor

0lvin commented Oct 15, 2023

@SirYodaJedi Could you please check with yquake2/yquake2remaster@83a3197 ?

@Yamagi This issue looks as good candidate to https://github.com/yquake2/yquake2remaster What do you think?

Updated state of renders

@SirYodaJedi
Copy link
Contributor Author

@SirYodaJedi Could you please check with yquake2/yquake2remaster@83a3197 ?

Looks like it should be functional, but I think it'd be preferable to have the non-masked texels be completely opaque instead of 99.9% opaque.

0lvin added a commit to yquake2/yquake2remaster that referenced this issue Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants