65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
var Extensions = require('../extensions/Extensions.js');
|
|
var BlendModeFilter = require('../filters/blend-modes/BlendModeFilter.js');
|
|
|
|
"use strict";
|
|
class OverlayBlend extends BlendModeFilter.BlendModeFilter {
|
|
constructor() {
|
|
super({
|
|
gl: {
|
|
functions: `
|
|
float overlay(float base, float blend)
|
|
{
|
|
return (base < 0.5) ? (2.0*base*blend) : (1.0-2.0*(1.0-base)*(1.0-blend));
|
|
}
|
|
|
|
vec3 blendOverlay(vec3 base, vec3 blend, float opacity)
|
|
{
|
|
vec3 blended = vec3(
|
|
overlay(base.r, blend.r),
|
|
overlay(base.g, blend.g),
|
|
overlay(base.b, blend.b)
|
|
);
|
|
|
|
return (blended * opacity + base * (1.0 - opacity));
|
|
}
|
|
`,
|
|
main: `
|
|
finalColor = vec4(blendOverlay(back.rgb, front.rgb,front.a), blendedAlpha) * uBlend;
|
|
`
|
|
},
|
|
gpu: {
|
|
functions: `
|
|
fn overlay(base: f32, blend: f32) -> f32
|
|
{
|
|
return select((1.0-2.0*(1.0-base)*(1.0-blend)), (2.0*base*blend), base < 0.5);
|
|
}
|
|
|
|
fn blendOverlay(base: vec3<f32>, blend: vec3<f32>, opacity: f32) -> vec3<f32>
|
|
{
|
|
let blended = vec3<f32>(
|
|
overlay(base.r, blend.r),
|
|
overlay(base.g, blend.g),
|
|
overlay(base.b, blend.b)
|
|
);
|
|
|
|
return (blended * opacity + base * (1.0 - opacity));
|
|
}
|
|
`,
|
|
main: `
|
|
out = vec4<f32>(blendOverlay(back.rgb, front.rgb, front.a), blendedAlpha) * blendUniforms.uBlend;
|
|
`
|
|
}
|
|
});
|
|
}
|
|
}
|
|
/** @ignore */
|
|
OverlayBlend.extension = {
|
|
name: "overlay",
|
|
type: Extensions.ExtensionType.BlendMode
|
|
};
|
|
|
|
exports.OverlayBlend = OverlayBlend;
|
|
//# sourceMappingURL=OverlayBlend.js.map
|