Skip to content
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

Transparent WebM videos do not clear previous alpha (Fix included!) #4089

Closed
kurozael opened this issue Jun 7, 2017 · 14 comments
Closed

Transparent WebM videos do not clear previous alpha (Fix included!) #4089

kurozael opened this issue Jun 7, 2017 · 14 comments
Labels
🕷 Bug Verified that it’s actually a legit bug that exists in the current release. Stale Previously “Won’t Fix”, bots should tag with this for inactive issues or pull-requests. 💾 v4.x (Legacy) Legacy version 4 support

Comments

@kurozael
Copy link

kurozael commented Jun 7, 2017

Please see #3526

It's urgent for our project to have this fix implemented into the latest Pixi.js release, we don't want to have to modify ourselves.

Thanks.

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Jun 7, 2017

I do that kind of fixes in GLTexture for every of my projects. There'll be a way to make your custom uploader in v5.

Right now the best strategy is DIY:

PIXI.glCore.GLTexture.prototype.upload = function(source)
{
	this.bind();

	var gl = this.gl;

	gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);

        var isVideo = !!source.videoWidth;
	var newWidth = isVideo ? source.videoWidth : source.width;
	var newHeight = isVideo ? source.videoHeight : source.height;

	if(newHeight !== this.height || newWidth !== this.width || isVideo)
	{
		gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, source);
	}
	else
	{
		gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.format, this.type, source);
	}

	this.width = newWidth;
	this.height = newHeight;

};

Put it in separate file in your project, name it "pixi-patch.js". I have tens of patches like that for different libs I use.

@ivanpopelyshev ivanpopelyshev added 🕷 Bug Verified that it’s actually a legit bug that exists in the current release. Type: Enhancement labels Jun 7, 2017
@ivanpopelyshev
Copy link
Collaborator

I suggest we add special flag for V5 default uploader, "always use texImage2D"

@ivanpopelyshev
Copy link
Collaborator

@kurozael ping

@kurozael
Copy link
Author

kurozael commented Jun 8, 2017

Hi, yes this is fine, or can we just detect if it is a video like your example?

@saschagehlich
Copy link

BTW, this issue is also causing video textures to be extremely slow:

http://codeflow.org/issues/slow_video_to_texture/

@zeh
Copy link

zeh commented Dec 12, 2017

@ivanpopelyshev Thank you so much for this. Was driving me crazy. Luckily patching upload worked, even on TypeScript. Hopefully something like this will be merged soon.

@themoonrat themoonrat added 🙏 Feature Request Community request for new features, APIs, packages. Version: v5.x labels Jul 8, 2018
@themoonrat
Copy link
Member

@englercj Can I just get your confirmation that you changed to using texImage2D for v5 please? Various different PRs refer each other, and I think this is solved for v5, and a workaround has been given for v4, and thus this can be closed! Thanks

@themoonrat themoonrat added 💾 v4.x (Legacy) Legacy version 4 support and removed 🙏 Feature Request Community request for new features, APIs, packages. Version: v5.x labels Jul 8, 2018
@neer2005
Copy link

neer2005 commented Nov 6, 2018

this patch doesn't work anymore on chrome 70 … additionally pixi5/chrome70 on windows reintroduces the original issue

@m4nuC
Copy link

m4nuC commented Nov 13, 2018

Confirmed that the solution above stopped working since Chrome 70 update on Window machine only. OSX still works fine. @ivanpopelyshev could this be reopened or should I create a new issue ?

@stale
Copy link

stale bot commented Feb 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Previously “Won’t Fix”, bots should tag with this for inactive issues or pull-requests. label Feb 24, 2019
@tlackemann
Copy link

In case it helps anyone still running into this problem, it most certainly is an issue with texSubImage2D and videos.

The link @saschagehlich posted was incredibly valuable to helping dig deeper into this.

The answer/patch above no longer works for PIXI v5, instead we patched BaseImageResource with a similar change.

import { resources } from 'pixi.js'

resources.BaseImageResource.prototype.upload = function(renderer, baseTexture, glTexture, source) {
  const gl = renderer.gl;
  const width = baseTexture.realWidth;
  const height = baseTexture.realHeight;

  source = source || this.source;

  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.premultiplyAlpha);

  // add this line, check for video
  const isVideo = !!source.videoWidth
  if (!isVideo && baseTexture.target === gl.TEXTURE_2D && glTexture.width === width && glTexture.height === height)
  {
    gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, baseTexture.format, baseTexture.type, source);
  }
  else
  {
    glTexture.width = width;
    glTexture.height = height;

    gl.texImage2D(baseTexture.target, 0, baseTexture.format, baseTexture.format, baseTexture.type, source);
  }

  return true
}

The results are really quite drastic.

Before
2019-09-11-082818_1058x748_scrot

After
2019-09-11-082725_1058x748_scrot

I know this issue is stale but I would like to throw my hat in the ring for an option to possibly bypass texSubImage2D for certain resource types. Otherwise I hope this solution helps anyone else dealing with performance issues and videos.

@bigtimebuddy bigtimebuddy reopened this Sep 12, 2019
@stale stale bot removed the Stale Previously “Won’t Fix”, bots should tag with this for inactive issues or pull-requests. label Sep 12, 2019
@stale
Copy link

stale bot commented Dec 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Previously “Won’t Fix”, bots should tag with this for inactive issues or pull-requests. label Dec 11, 2019
@kurozael
Copy link
Author

I'm just bumping this because it still needs addressing.

@stale stale bot removed the Stale Previously “Won’t Fix”, bots should tag with this for inactive issues or pull-requests. label Dec 18, 2019
@stale
Copy link

stale bot commented Mar 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Previously “Won’t Fix”, bots should tag with this for inactive issues or pull-requests. label Mar 17, 2020
@stale stale bot closed this as completed Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕷 Bug Verified that it’s actually a legit bug that exists in the current release. Stale Previously “Won’t Fix”, bots should tag with this for inactive issues or pull-requests. 💾 v4.x (Legacy) Legacy version 4 support
Projects
None yet
Development

No branches or pull requests

9 participants