Jump to content

Applying positional filters to display objects, even when partly off-bounds?


Ruskibloo
 Share

Recommended Posts

Hi all,

I'm stumped on a filter use case that I've distilled in the following example.
I have a Sprite with a CRTFilter on it. When the sprite is fully-visible in the canvas, it renders as expected, covering the entire Sprite.

full_render.jpg.1fc4757c2a05e9ea50c2a7d2a81beeba.jpg

However, when the Sprite is moved partially off-screen, the filter is squashed to render entirely within the visible portion of the Sprite.

bad_partial_render.jpg.ca24c8411e08f969bf31e951db729161.jpg

I'm wondering if there's a way to render the filter in a way that it looks like it's following the Sprite, and clipped where necessary? Basically like this (photoshop mockup):

desired_mock.jpg.b9be3213f12806c4abeaaa79e10192a2.jpg

I've tried looking at properties I can feed to the shader from overriding Filter.apply(), but there doesn't seem to be any good ones. What's the proper way to do this, if any?

Thanks for any help!

The code's pretty basic, but just to be thorough, here it is:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Pixi Experiment</title>
    <script src="https://pixijs.download/release/pixi.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/pixi-filters@latest/dist/browser/pixi-filters.min.js"></script>
  </head>
  <body>
	<script>
   const app = new PIXI.Application({
        width: 640,
        height: 480,
        backgroundColor: 0x2c3e50
    });
    document.body.appendChild(app.view);

    const cat = PIXI.Sprite.from('cat.jpg');
    const crtFilter = new PIXI.filters.CRTFilter();
    cat.filters = [crtFilter];

    // Center the sprite's anchor point
    cat.anchor.set(0.5);
    cat.x = 0; // app.renderer.width / 2;
    cat.y = app.renderer.height / 2;

    app.stage.addChild(cat);

  </script>
  </body>
</html>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...