Skip to content

feat: add VFXProps.overlay #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/vfx-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ export type VFXProps = {
*/
uniforms?: VFXUniforms;

/**
* The opacity for the original HTML element.
*
* By default, VFX-JS hides the original element by setting its opacity to 0.
* However, in some cases you might want not to hide the original element.
* `overlay` allows you to specify the opacity to be set explicitly.
*
* If you pass `true`, VFX-JS will preserve the original element's opacity.
*
* You can also specify the opacity by passing a number.
* For example, `overlay: 0.5` will set the opacity of the orignal element to 0.5.
*/
overlay?: true | number;

/**
* Allow shader outputs to oveflow the original element area.
* If true, REACT-VFX will render the shader in fullscreen.
Expand Down
10 changes: 8 additions & 2 deletions packages/vfx-js/src/vfx-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,14 @@ export class VFXPlayer {
texture.needsUpdate = true;

// Hide original element
const opacity = type === "video" ? "0.0001" : "0"; // don't hide video element completely to prevent jank frames
element.style.setProperty("opacity", opacity);
if (opts.overlay === true) {
/* Overlay mode. Do not hide the element */
} else if (typeof opts.overlay === "number") {
element.style.setProperty("opacity", opts.overlay.toString());
} else {
const opacity = type === "video" ? "0.0001" : "0"; // don't hide video element completely to prevent jank frames
element.style.setProperty("opacity", opacity.toString());
}

const uniforms: { [name: string]: THREE.IUniform } = {
src: { value: texture },
Expand Down
Loading