Archive 17/01/2023.

Additional material texture unit

dakilla

Hi

I want to use a material builded manually at runtime that can have from 1 to 4 textures.
How to specify theses texture units using material->SetTexture(… I don’t know which TextureUnit enum to use.

thanks

jmiller

Hello.

dakilla

So for custom units index is this correct to do that ? :

material->SetTexture(TextureUnit(0), myNormalTexture );
material->SetTexture(TextureUnit(1), myUVTexture1 );
material->SetTexture(TextureUnit(2), myUVTexture2 );
material->SetTexture(TextureUnit(3), myUVTexture3 );
material->SetTexture(TextureUnit(4), myUVTexture4 );

jmiller

I think that should work; Terrain, for example, uses most of those for its detail textures.

Andre_B

(Note: using UrhoSharp) you can have as much indexes as you want.

On a shader i have

//previous texture
uniform sampler2D sLayer0;

//current texture
uniform sampler2D sLayer1;

When coding my materials i just use the following:

material->SetTexture(0, tex0 );
material->SetTexture(1, tex1);

The order is related to the sampler2D uniforms you have on your fragment shader.