[SparkAR] How to use "Blend" (of textures) in script

Hey people, thank you for your attention.

I am studying for Spark Scripting API and I could not figure out how to blend two textures (the camTex and a png image of a frame) before I assign them to the same material.

Any help will be appreciated, good day.

Hey again,

I have found the Shaders module has the blend function.
I believe this is it.
Unfortunately, I still could not figure it out, I am having a hard time using textures to blend.

I can still use a hand!

Best :dancer:

Yeah, exactly. You can do some simple layering and compositing with material options, but if you want more control, then it needs to be done inside the material graph.

Here’s a quick example:

The thing that confused me the most is that panel on the right side. It can be minimized, which hides the node inspector. If you need to expand it, there is a tiny arrow on the right side of the material graph

1 Like

Hey Josh,

Could this visual be from some other platform? Never seen it on Spark Ar.

Also if you could enlighten me on how can i do that blending on script that will be great.

I could not use fromScript and toScript as well to import created (blend of 2) textures into script.

Thank you for reading and thank you for the response.

Best!

Hey everyone,

In case anybody is interested, here is the solution i found :dancer: :tada:

Shaders module has “blend” funciton, which takes "ShaderSignal"s.

You can use the “signal” attribute of your texture to get the ShaderSignal.

The usage is basically:

const blendedTexture = Shaders.blend(texture1.signal, texture2.signal, { mode: Shaders.BlendMode.NORMAL });

Later on when you want to give this tex to your material
you cannot just do: material.diffuse = blendedTexture
instead use: material.setTextureSlot('DIFFUSE', blendedTexture)

Best

Aha, yes! Sorry, I have been in lens studio all week so that’s where my mind was at :slight_smile:

Generally I try to do all of the shader work in the patch graph. I don’t think you can send textures to patches from script, but you could send an index to use in some option pickers, then do the blending after selecting the textures.

Anyway, thanks for sharing your solution!

1 Like

Hey Josh,

Thank you for the ideas.