I'm using three.js to create an interactive web application, and I've run into a little stumbling block:
I have a number of canvases contained in draggable divs on the page. In each canvas I hope to display an unlit 3D object with a different material applied (each material is using custom shaders). All of those materials work off the same texture (one might be blue-tinted, one might be desaturated, etc.).
The number of canvases on the page can vary, but I expect the number to commonly reach/exceed 20 canvases, and as such sharing resources (particularly for large textures) would be very beneficial.
Up until now I have been using multiple renderers, cameras and scenes which has worked fine until I started trying to use the same texture in multiple scenes.
Most of the materials share uniforms and attributes to avoid having to duplicate the information, and also so that all of the materials stay in sync with one another (e.g. when some of the materials change over time they should all change in the same way).
I was wondering if there was a way I would be able to share textures between the scenes/renderers/canvases? When I try I get the following error:
WebGL: INVALID_OPERATION: bindTexture: object not from this context
In my research trying to find a solution for this problem I came across the suggestion that this could be solved by creating multiple viewports, however I do not know how to display different viewports over different canvases.
TL/DR;
Can I either:
- Show the same scene across different canvases?
- Use the same uniforms (including a texture uniform) across different scenes, renderers and/or canvases?
Thanks in advance!
Griffork
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…