How do I pass a texture array to a NME CustomBlock function?

Hello!

I am trying to pass a texture array to a NME CustomBlock function, and I can’t get it to work. I keep getting the error “cannot connect these two connectors”.

I will elaborate: I have a CustomBlock containing a shader function that takes a sampler2DArray, for example:

const code = `void SurfaceShader(vec2 uv, sampler2DArray tex, out vec3 rgb) 
{ 
	rgb = texture2D(tex, vec3(uv.x, uv.y, 0)).rgb; 
}`;
const codeBlock = new BABYLON.CustomBlock("codeBlock");
codeBlock.options = {
	"name": "codeBlock",
	"target": "Neutral",
	"inParameters": [
		{ 'name': 'uv', 'type': 'Vector2' },
		{ 'name': 'tex', 'type': 'sampler2DArray' }
	],
	"outParameters": [{"name": "rgb", "type": "Vector3" }],
	"functionName": "SurfaceShader",
	"code": [code]
};

So I believe I need to create and pass a RawTexture2DArray object into the input to this code block. However I can’t figure out how to properly do this.

I tried using an ImageSourceBlock, assigning the RawTexture2DArray to the texture, and connecting it to the CustomBlock, but I get the error “cannot connect these two connectors”. Here’s a playground link showing this attempt: Babylon.js Playground

I thought that perhaps I should be using an InputBlock instead, so I tried creating an InputBlock, assigning the RawTexture2DArray to the value, but unfortunately I get the same error. Here’s a playground link showing this attempt: Babylon.js Playground

Just for completeness, here’s a playground link showing a normal (non-array) texture, which works properly. Another way to phrase my question is: How can I convert this working sample to use a texture array instead of a single texture?: Babylon.js Playground

Thank you for any assistance, it’s very appreciated!

Unfortunately this is not supported as the CustomBlock only emits sampler2D / samplerCube

This is the relevant code:

I’ll check to see if I can add a sampler2dArray

1 Like

oki doki!
Add sampler2dArray support to ImageSourceBlock by deltakosh · Pull Request #16933 · BabylonJS/Babylon.js

This will make your PG works :slight_smile: ( ReproWithImageSourceBlock | Babylon.js Playground)

3 Likes

It works! Thank you so much for your quick fix, amazing!

1 Like