blakjak44 Posted February 28, 2021 Share Posted February 28, 2021 This is related to my previous question: I have my meshes rendering perfectly. Each of my meshes are using two uint16 textures in a custom shader and I pass the textures as uniforms with a sampler type of "usampler2D". Now when I try to render any other PIXI.Graphics objects, the graphics objects will not render and I receive an error complaining that the texture being sampled is not of the correct format for the sampler type. If I remove one of the textures and only render one texture, then the graphics object will display. I'm sure my code is creating some issue with the WebGL state and bound textures but rather than spend more time digging through the source, I figure it would be faster if someone experienced can take a look. Hopefully it's a simple fix. I've reproduced the issue in the demo below: https://www.pixiplayground.com/#/edit/xpLx-ElnpPPPXFJUkxoRa Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 4, 2021 Share Posted March 4, 2021 (edited) Yep, that's the actual bug of multisampler Edited March 4, 2021 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 4, 2021 Share Posted March 4, 2021 PR for v6 is here: https://github.com/pixijs/pixi.js/pull/7273 Maybe we'll cherry-pick it for v5.3.9 Workaround for now: add extra mesh with two textures that uses two PIXI.Texture.WHITE with standard shader. It will reset current state of bound textures. Quote Link to comment Share on other sites More sharing options...
blakjak44 Posted March 5, 2021 Author Share Posted March 5, 2021 @ivan.popelyshev Thanks for the quick PR! It would be much appreciated if this fix could be bundled into v5.3.9 As for the workaround, I've tried implementing what you suggested but can't get it to work. I'm not sure what is the correct way to pass the 2 textures. I have tried the 2 methods below. const arrayResource = new PIXI.resources.ArrayResource([PIXI.Texture.WHITE, PIXI.Texture.White]) const arrayBase = new PIXI.BaseTexture(arrayResource) const arrayTex = new PIXI.Texture(arrayBase) const dummyUniforms = PIXI.UniformGroup.from({ uSampler: arrayTex }) const dummyShader = PIXI.Shader.from(null, null, dummyUniforms ) const dummyGeometry = new PIXI.MeshGeometry( new Float32Array([0, 0, 300, 0, 300, 300, 0, 300]), new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), new Uint16Array([0, 1, 2, 0, 3, 2]) ) const dummyMesh = new PIXI.Mesh(dummyGeometry, dummyShader) const dummyUniforms = PIXI.UniformGroup.from({ uSampler: PIXI.Texture.WHITE, uSampler1: PIXI.Texture.WHITE }) const dummyShader = PIXI.Shader.from(null, null, dummyUniforms ) const dummyGeometry = new PIXI.MeshGeometry( new Float32Array([0, 0, 300, 0, 300, 300, 0, 300]), new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), new Uint16Array([0, 1, 2, 0, 3, 2]) ) const dummyMesh = new PIXI.Mesh(dummyGeometry, dummyShader) Would you mind pointing out what I am doing wrong? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 5, 2021 Share Posted March 5, 2021 (edited) maybe it doesnt actually rebind textures because shader doesnt have them in uniform list. Lets try direct approach. const dummy = new PIXI.Container(); dummy._render = (renderer) => { renderer.texture.bind(PIXI.Texture.WHITE.baseTexture, 0); renderer.texture.bind(PIXI.Texture.WHITE.baseTexture, 1); } containerWithMeshes.addChild(dummy); I checked in playground, it works. Edited March 5, 2021 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
blakjak44 Posted March 5, 2021 Author Share Posted March 5, 2021 Beautiful, that did the trick! Thanks! One other related question: Currently I am setting the textures in my mesh each with their own individual sampler name (e.g. sampler1, sampler2). I would prefer accessing the textures in my shader using index notation (e.g. samplers[i]). How should I set my textures to accomplish this? I know this is what's done for batch rendering but I couldn't quite figure out where the textures are set. Would the ArrayResource be the proper way to do this? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 5, 2021 Share Posted March 5, 2021 I dont remember whether pixi can auto-map samplers like that, probably `uniforms: { uSamplers: new Float32Array([0, 1]) }` and manual binding of those two textures in Mesh in corresponding slots should work. Like i did with dummy, you can override _render and add texture binding there. No, ArrayResource is not related to the case. Quote Link to comment Share on other sites More sharing options...
blakjak44 Posted March 6, 2021 Author Share Posted March 6, 2021 Interesting. I'll give it a try, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.