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
Combining a Pixi.js canvas and a three.js canvas #1366
Comments
If three.js supports a canvas as a texture then you could render pixi to an offscreen canvas and use that as a texture in your three.js scene. |
Spot on! thats exactly how we do it! On Wed, Jan 21, 2015 at 4:45 PM, Chad Engler notifications@github.com
Mat Groves Technical Partner Telephone: 07708 114496 :: www.goodboydigital.com |
Wahou ... Thanks a Lot guys ! :) This is what i call as Fast Feedback ! |
I am just thinking about a small detail. I need to have the ability to draw 2D UI panel (Pixi.js) that will be rendered on Top of a 3D World (Three.js).
If i use the tricks of rendering my canvas and apply it as a texture. I am afraid that the Blur of the background will not be possible ? |
Do the blur on the Three.js side? Just make the pixi object transparent and then blend the texture into your 3D scene however you want. |
Thanks again for your Help ! Now that you said it ... it's definitely the most logical path ! :) Cheers E |
I EDIT the post as a i have solve my issue, i post the working code just in case someone hit the same problem and need an exemple.
|
We are doing something like this in a project. It gets a little tricky since both engines (pixi and ThreeJS) keep track of GL state to minimize redundant calls. This means that they don't play nicely with each other, so you need to reset their flags before starting the renderers. With new versions of ThreeJS you can use In PIXI, it's a bit more complicated. Things like this would be useful to have as a method in WebGLRenderer. These are needed before gl.disable(gl.DEPTH_TEST)
gl.enable(gl.BLEND)
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.disable(gl.STENCIL_TEST)
gl.disable(gl.CULL_FACE)
gl.frontFace( gl.CCW )
gl.cullFace( gl.FRONT )
gl.colorMask(true, true, true, true)
gl.activeTexture(gl.TEXTURE0)
var shaderManager = session.shaderManager
shaderManager._currentId = undefined
for (var i=0; i<shaderManager.attribState.length; i++)
shaderManager.attribState[i] = false
shaderManager.setShader(shaderManager.currentShader)
var blend = session.blendModeManager.currentBlendMode
if (blend in PIXI.blendModesWebGL) {
session.blendModeManager.currentBlendMode = undefined
session.blendModeManager.setBlendMode(blend)
} This allows you to render the UI on top of the 3D scene without any frame buffer switching. Achieving the blur underneath your UI is significantly more complicated. You would need to:
|
Thank you for this very precise and documented feedback Matt ! :) As i'm pretty new to WebGL programming this is extremely helpful. But the excellent exemples , the very focus point of the dev on 2D, really convinced me to use pixi for gl2d calls. As you look to have chosen a Mix approach too, i guess it confirm that Pixi is definitely a more efficient choice for drawing 2D elements with WebGL. Cheers E |
Well, maybe. In most cases the extra performance is moot (how often do you need 3000 buttons animating at once?), and things like robust text rendering, text input, and scroll events can be incredibly challenging in WebGL. The easiest route is just to use DOM/CSS for UI. If you absolutely need to choose WebGL (i.e. for certain effects, depth testing, etc) then Pixi will probably be easier than ThreeJS for 2D UI. |
Going to close this up since it seems answered. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi Guys !
First of all Thanks for Pixi.js, it's a great tool , I Love it ! the perfect counter part of three.js for the 2D world.
I am working on a project where i would like to have this configuration :
How would you proceed to encapsulate a Pixi.js Canvas inside a Three.js Canvas ?
Thanks for your time !
Cheers
Emmanuel
The text was updated successfully, but these errors were encountered: