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

Fix BC3 alpha compression of some constant color blocks showing weird artifacts #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ISPC Texture Compressor/ispc_texcomp/kernel.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,15 @@ inline void CompressBlockBC3_alpha(float block[16], uint32 data[2])
ep[1] = max(ep[1], block[k]);
}

if (ep[0] == ep[1]) ep[1] = ep[0]+0.1f;
const int ep0int = clamp((int)ep[0], 0, 255);
const int ep1int = clamp((int)ep[1], 0, 255);
data[0] = ep0int * 256 + ep1int;

if (ep0int == ep1int) // constant color block, so just set all indices to 0
{
data[1] = 0;
return;
}

uint32 qblock[2] = { 0, 0 };
float scale = 7f/(ep[1]-ep[0]);
Expand All @@ -581,7 +589,6 @@ inline void CompressBlockBC3_alpha(float block[16], uint32 data[2])

// (could be improved by refinement)

data[0] = clamp((int)ep[0], 0, 255)*256+clamp((int)ep[1], 0, 255);
data[0] |= qblock[0]<<16;
data[1] = qblock[0]>>16;
data[1] |= qblock[1]<<8;
Expand Down