Skip to content

BC7 color ramp interpolation #36

@lexaknyazev

Description

@lexaknyazev

Generation of color ramp uses different math than MSDN example.

Compare:
https://github.com/GPUOpen-Tools/Compressonator/blob/70d7d78f309f762b3c65fd112c2aa06e68ac06c6/Compressonator/Source/Codec/BC7/BC7_utils.cpp#L131-L142

and (from here):

UINT8 interpolate(UINT8 e0, UINT8 e1, UINT8 index, UINT8 indexprecision)
{
    if(indexprecision == 2)
        return (UINT8) (((64 - aWeights2[index])*UINT16(e0) + aWeights2[index]*UINT16(e1) + 32) >> 6);
    else if(indexprecision == 3)
        return (UINT8) (((64 - aWeights3[index])*UINT16(e0) + aWeights3[index]*UINT16(e1) + 32) >> 6);
    else // indexprecision == 4
        return (UINT8) (((64 - aWeights4[index])*UINT16(e0) + aWeights4[index]*UINT16(e1) + 32) >> 6);
}

The difference is that MSDN approach avoids floating-point calculations by using right-shift at the end.

This gives different results, e.g.:

mode 6:
color_bits = 7 + 1
ep0 = 1
ep1 = 82

index_bits = 4
index = 7 (30/64)

MSDN:
((64 - 30) * 1 + 30 * 82) >> 6 == 38

Compressonator:
1.0 * (1.0 - 0.46875) + 82.0 * 0.46875 + 0.5 == 39.46875

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