pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
65 lines (57 loc) • 2.24 kB
JavaScript
;
var Extensions = require('../extensions/Extensions.js');
var BlendModeFilter = require('../filters/blend-modes/BlendModeFilter.js');
;
class SoftLightBlend extends BlendModeFilter.BlendModeFilter {
constructor() {
super({
gl: {
functions: `
float softLight(float base, float blend)
{
return (blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend));
}
vec3 blendSoftLight(vec3 base, vec3 blend, float opacity)
{
vec3 blended = vec3(
softLight(base.r, blend.r),
softLight(base.g, blend.g),
softLight(base.b, blend.b)
);
return (blended * opacity + base * (1.0 - opacity));
}
`,
main: `
finalColor = vec4(blendSoftLight(back.rgb, front.rgb, front.a), blendedAlpha) * uBlend;
`
},
gpu: {
functions: `
fn softLight(base: f32, blend: f32) -> f32
{
return select(2.0 * base * blend + base * base * (1.0 - 2.0 * blend), sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend), blend < 0.5);
}
fn blendSoftLight(base:vec3<f32>, blend:vec3<f32>, opacity:f32) -> vec3<f32>
{
let blended: vec3<f32> = vec3<f32>(
softLight(base.r, blend.r),
softLight(base.g, blend.g),
softLight(base.b, blend.b)
);
return (blended * opacity + base * (1.0 - opacity));
}
`,
main: `
out = vec4<f32>(blendSoftLight(back.rgb, front.rgb, front.a), blendedAlpha) * blendUniforms.uBlend;
`
}
});
}
}
/** @ignore */
SoftLightBlend.extension = {
name: "soft-light",
type: Extensions.ExtensionType.BlendMode
};
exports.SoftLightBlend = SoftLightBlend;
//# sourceMappingURL=SoftLightBlend.js.map