Skip to content

make GodrayFilter work with DropShadowFilter? #297

Open

Description

@andrewljohnson

Is it possible to have a GodrayFilter work with DropShadowFilter?

When I add them both to a sprite, the DropShadowFilter seems to reveal the black image used to create the GodRay effect.

Activity

  1. bigtimebuddy commented on May 6, 2021

    @bigtimebuddy
    Member

    Could you provide an example?

  2. andrewljohnson commented on May 7, 2021

    @andrewljohnson
    Author

    Thanks for following up. Here's code and video showing:

    • sprite with drop shadow
    • sprite with godray
    • sprite with both
    shadow-vs-godray-vs-together.mov

    Maybe I'm handling dragdrop wrong? Here's the code:

    var godray = new PIXI.filters.GodrayFilter();
    var incrementGodrayTime = () => {
        godray.time += gameUX.app.ticker.elapsedMS / 1000;
    }
    
    function onDragStart(event, card, gameUX) {
        gameUX.app.ticker.add(incrementGodrayTime)
        card.data = event.data;
        card.dragging = true;
        card.filters = [
            godray,   // using both filters together creates the black border
            new PIXI.filters.DropShadowFilter({ distance: 15, outerStrength: 2 }),
        ];
    
        gameUX.app.stage.addChild(gameUX.inPlay);
        gameUX.app.stage.toLocal(gameUX.inPlay.position, gameUX.inPlayAndMenuRow, gameUX.inPlay.position);
        gameUX.app.stage.addChild(card);
        gameUX.app.stage.toLocal(card.position, card.parent, card.newPosition);
        var newPosition = card.data.getLocalPosition(card.parent);
        card.position.x = newPosition.x;
        card.position.y = newPosition.y;
    }
    
  3. bigtimebuddy commented on May 7, 2021

    @bigtimebuddy
    Member

    I'd assume this is a problem with clear, right @SukantPal?

    apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void
    {
    const target = filterManager.getFilterTexture();
    this._tintFilter.apply(filterManager, input, target, 1);
    this._blurFilter.apply(filterManager, target, output, clear);
    if (this.shadowOnly !== true)
    {
    filterManager.applyFilter(this, input, output, 0);
    }
    filterManager.returnFilterTexture(target);
    }

    apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void
    {
    const { width, height } = input.filterFrame as Rectangle;
    this.uniforms.light = this.parallel ? this._angleLight : this.center;
    this.uniforms.parallel = this.parallel;
    this.uniforms.dimensions[0] = width;
    this.uniforms.dimensions[1] = height;
    this.uniforms.aspect = height / width;
    this.uniforms.time = this.time;
    this.uniforms.alpha = this.alpha;
    // draw the filter...
    filterManager.applyFilter(this, input, output, clear);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions