Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

BC7 encoder could convert completely transparent block (alpha=0) to non-transparent #15

Description

@GregSlazinski

The problem lies in the 'ep_quant0367'
https://github.com/GameTechDev/ISPCTextureCompressor/blob/master/ISPC%20Texture%20Compressor/ispc_texcomp/kernel.ispc#L973

If the pixels have fully transparent alpha=0, but there's smaller RGB error in "b=1" mode, then alpha would get converted to 4 (in 0..255 scale).
This kind of alpha is fairly visible when drawing 2D images on the screen, so this means that you could see noticable artifacts in places which should be completely transparent.

A simple workaround, is to always force "b=0" mode, when the alpha is zero:

replace code:

		for (uniform int p=0; p<4; p++)
			qep[i*4+p] = (err0<err1) ? qep_b[0+p] : qep_b[4+p];

with:

        if(channels==4 && ep[i*4+3]<=0.5f)err0=-1; // ESENTHEL CHANGED, BC7 allows to encode end points in 2 quantized modes, #1 standard, #2 add "0.5*levels" to all channels (1 extra bit precision, however it affects all channels at the same time, so if we have alpha=0, but RGB channels have smaller error with the extra 0.5 value, then alpha would get the +0.5 too, and it could destroy complete transparency, so this code always forces #1 version if we have alpha=0)

		for (uniform int p=0; p<4; p++)
			qep[i*4+p] = (err0<err1) ? qep_b[0+p] : qep_b[4+p];

Probably you could optimize it more in aspect to dynamic branching.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions