/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/advanced-blend-modes/ColorBlend.ts
61 строка
2 KB
Zyie
chore: add standard/advanced tags to documentation (#11448)
03 июн 2025, 10:12
Не верифицирован
03 июн 2025, 10:12
7d91234
Код
Авторство
О чём код?
import { ExtensionType } from '../extensions/Extensions'; import { BlendModeFilter } from '../filters/blend-modes/BlendModeFilter'; import { hslgl } from '../filters/blend-modes/hls/GLhls'; import { hslgpu } from '../filters/blend-modes/hls/GPUhls'; import type { ExtensionMetadata } from '../extensions/Extensions'; /** * The final color has the hue and saturation of the top color, while using the luminosity of the bottom color. * The effect preserves gray levels and can be used to colorize the foreground. * * Available as `container.blendMode = 'color'` after importing `pixi.js/advanced-blend-modes`. * @example * import 'pixi.js/advanced-blend-modes'; * import { Sprite } from 'pixi.js'; * * const sprite = Sprite.from('something.png'); * sprite.blendMode = 'color' * @category filters * @noInheritDoc */ export class ColorBlend extends BlendModeFilter { /** @ignore */ public static extension: ExtensionMetadata = { name: 'color', type: ExtensionType.BlendMode }; constructor() { super({ gl: { functions: ` ${hslgl} vec3 blendColor(vec3 base, vec3 blend, float opacity) { return (setLuminosity(blend, getLuminosity(base)) * opacity + base * (1.0 - opacity)); } `, main: ` finalColor = vec4(blendColor(back.rgb, front.rgb,front.a), blendedAlpha) * uBlend; ` }, gpu: { functions: ` ${hslgpu} fn blendColorOpacity(base:vec3<f32>, blend:vec3<f32>, opacity:f32) -> vec3<f32> { return (setLuminosity(blend, getLuminosity(base)) * opacity + base * (1.0 - opacity)); } `, main: ` out = vec4<f32>(blendColorOpacity(back.rgb, front.rgb, front.a), blendedAlpha) * blendUniforms.uBlend; ` } }); } }