Fair enough. We could add additional MRT options for targetType
(an array specifying 2D texture, 2D array texture, etc.), and faceIndexOrLayer
(an array specifying what component of the texture should be bound at each attachment).
I donāt think so? From WebGLRenderingContext: bindTexture() method - Web APIs | MDN
A gl.INVALID_ENUM
error is thrown if target
is not gl.TEXTURE_2D
, gl.TEXTURE_CUBE_MAP
, gl.TEXTURE_3D
, or gl.TEXTURE_2D_ARRAY
.
If it doesnāt exist in WebGL2 then a faceIndexOrLayer
array is sufficient to specify attachments for every other type of texture.
I have put my first attempt into a gitpod workspace: https://babylonjs-babylonjs-jah9qoqirrv.ws-us82.gitpod.io/. It should be backwards compatible.
The way this version works is by creating textures of the right type and attaching them at initialization, and modifying the .setInternalTexture
and related methods to be able to attach a diverse set of texture target types to a specified color attachment. It also adds the two options I described before. I also added target types to Constants
.
I modified /Babylon.js/packages/tools/babylonServer/src/createScene.js
to run some tests reproducing the aforementioned scenario. To sum it up;
- I create three textures
A: a 2D Texture
B: a 2D Array Texture
C: a Cube Map Texture
- I then bind
B.layer0 + C.face3 + A + B.layer1
- I finally render these textures to a plane
let mrt = new BABYLON.MultiRenderTarget(
"mrt",
{ width: 32, height: 32, layers: 32 },
4, // number of draw buffers
scene,
{
types: new Array(3).fill(BABYLON.Constants.TEXTURETYPE_FLOAT),
samplingModes: new Array(3).fill(BABYLON.Constants.TEXTURE_NEAREST_SAMPLINGMODE),
targetTypes: [BABYLON.Constants.TEXTURE_2D_ARRAY, BABYLON.Constants.TEXTURE_CUBE_MAP, BABYLON.Constants.TEXTURE_2D],
faceIndexOrLayer: [0, 3, 0, 1]
}
);
// Sets the attachment at index 3 to the 0th texture in the list
mrt.setInternalTexture(mrt.textures[0].getInternalTexture(), 3);
Also, does WebGL2 support rendering to 3D textures? From documentation I would expect to be able to bind a layer of a 3D texture by using gl.framebufferTextureLayer
but I wasnāt able to reproduce this.
[EDIT] Maybe we could also consider hard capping the value of count
to the value queried by gl.getParameter(gl.MAX_DRAW_BUFFERS)
@sebavan @Evgeni_Popov