How to use the @pixi/utils.premultiplyTint function in @pixi/utils

To help you get started, we’ve selected a few @pixi/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pixijs / pixi.js / packages / graphics / src / GraphicsGeometry.js View on Github external
addColors(colors, color, alpha, size)
    {
        // TODO use the premultiply bits Ivan added
        const rgb = (color >> 16) + (color & 0xff00) + ((color & 0xff) << 16);

        const rgba =  premultiplyTint(rgb, alpha);

        while (size-- > 0)
        {
            colors.push(rgba);
        }
    }
github pixijs / pixi.js / packages / sprite / src / SpriteRenderer.js View on Github external
// xy
                float32View[index + 10] = vertexData[4];
                float32View[index + 11] = vertexData[5];

                // xy
                float32View[index + 15] = vertexData[6];
                float32View[index + 16] = vertexData[7];
            }

            uint32View[index + 2] = uvs[0];
            uint32View[index + 7] = uvs[1];
            uint32View[index + 12] = uvs[2];
            uint32View[index + 17] = uvs[3];
            /* eslint-disable max-len */
            const alpha = Math.min(sprite.worldAlpha, 1.0);
            const argb = alpha < 1.0 && nextTexture.premultiplyAlpha ? premultiplyTint(sprite._tintRGB, alpha)
                : sprite._tintRGB + (alpha * 255 << 24);

            uint32View[index + 3] = uint32View[index + 8] = uint32View[index + 13] = uint32View[index + 18] = argb;

            float32View[index + 4] = float32View[index + 9] = float32View[index + 14] = float32View[index + 19] = textureId;
            /* eslint-enable max-len */

            index += 20;
        }

        currentGroup.size = i - currentGroup.start;

        if (!settings.CAN_UPLOAD_SAME_BUFFER)
        {
            // this is still needed for IOS performance..
            // it really does not like uploading to the same buffer in a single frame!
github pixijs / pixi.js / packages / core / src / batch / AbstractBatchRenderer.js View on Github external
{
        const {
            uint32View,
            float32View,
        } = attributeBuffer;

        const packedVertices = aIndex / this.vertexSize;
        const uvs = element.uvs;
        const indicies = element.indices;
        const vertexData = element.vertexData;
        const textureId = element._texture.baseTexture._batchLocation;

        const alpha = Math.min(element.worldAlpha, 1.0);
        const argb = (alpha < 1.0
            && element._texture.baseTexture.alphaMode)
            ? premultiplyTint(element._tintRGB, alpha)
            : element._tintRGB + (alpha * 255 << 24);

        // lets not worry about tint! for now..
        for (let i = 0; i < vertexData.length; i += 2)
        {
            float32View[aIndex++] = vertexData[i];
            float32View[aIndex++] = vertexData[i + 1];
            float32View[aIndex++] = uvs[i];
            float32View[aIndex++] = uvs[i + 1];
            uint32View[aIndex++] = argb;
            float32View[aIndex++] = textureId;
        }

        for (let i = 0; i < indicies.length; i++)
        {
            indexBuffer[iIndex++] = packedVertices + indicies[i];
github pixijs / pixi.js / packages / particles / src / ParticleRenderer.js View on Github external
uploadTint(children, startIndex, amount, array, stride, offset)
    {
        for (let i = 0; i < amount; ++i)
        {
            const sprite = children[startIndex + i];
            const premultiplied = sprite._texture.baseTexture.alphaMode > 0;
            const alpha = sprite.alpha;
            // we dont call extra function if alpha is 1.0, that's faster
            const argb = alpha < 1.0 && premultiplied ? premultiplyTint(sprite._tintRGB, alpha)
                : sprite._tintRGB + (alpha * 255 << 24);

            array[offset] = argb;
            array[offset + stride] = argb;
            array[offset + (stride * 2)] = argb;
            array[offset + (stride * 3)] = argb;

            offset += stride * 4;
        }
    }
github pixijs / pixi.js / packages / core / src / batch / AbstractBatchRenderer.js View on Github external
const source = element[attributeDefinitions[i].property];

                attributeSources.push(source);
                highestAttributeLength = Math.max(
                    highestAttributeLength, source.length / attribute.size);
            }
            else
            {
                switch (attributeDefinitions[i])
                {
                    case 'aColor':
                    {
                        const alpha = Math.min(element.worldAlpha, 1.0);
                        const argb = (alpha < 1.0
                        && element._texture.baseTexture.premultiplyAlpha)
                            ? premultiplyTint(element._tintRGB, alpha)
                            : element._tintRGB + (alpha * 255 << 24);

                        attributeSources.push([Math.round(argb)]);
                        highestAttributeLength
                            = Math.max(highestAttributeLength, 1);
                        break;
                    }
                    case 'aTextureId':
                    {
                        attributeSources.push(null);
                        break;
                    }
                    default:
                    {
                        throw new Error(`Unknown built-in attribute `
                          + `given to AbstractBatchRenderer: `