No more than 4 textures in HLSL shader?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
scippie
Posts: 26
Joined: Sat Oct 13, 2007 3:35 pm
Location: Belgium
Contact:

No more than 4 textures in HLSL shader?

Post by scippie »

I need 6 textures in my shader, but for some reason, I can only use 4 of them.

To test it, I created a simple shader that maps one of the 6 textures on the mesh and switches between them every second. It works fine for tex0-3 but tex4-5 show black.

I am really sure that the textures are all correct (and non black) because when I show them on separate meshes without the shader on texture 0, they all show.

SceneNode:

Code: Select all

	vlak = SCN()->addMeshSceneNode(tngmesh);
	vlak->setName("vlak");
	vlak->setPosition(vector3df(0.0f, 0.0f, 0.0f));
	for (int i = 0; i < 6; ++i)
		vlak->setMaterialTexture(i, tex[i]);
	vlak->setMaterialFlag(EMF_LIGHTING, false);
	vlak->setMaterialType((E_MATERIAL_TYPE)myShaderMtrlType);
Shader callback (pixel part, vertex part isn't very interesting):

Code: Select all

...
	float idx = (float)(GetTickCount() % 6000) / 1000.0f;
	services->setPixelShaderConstant("idx", &idx, 1);
Pixel shader (vertex shader insn't very interesting)

Code: Select all

sampler2D tex0 : register(s0);
sampler2D tex1 : register(s1);
sampler2D tex2 : register(s2);
sampler2D tex3 : register(s3);
sampler2D tex4 : register(s4);
sampler2D tex5 : register(s5);
float idx;

float4 pixelMain(float2 Tex: TEXCOORD0) : COLOR
{
	float4 Color;
	float4 Color0 = tex2D(tex0, Tex);
	float4 Color1 = tex2D(tex1, Tex);
	float4 Color2 = tex2D(tex2, Tex);
	float4 Color3 = tex2D(tex3, Tex);
	float4 Color4 = tex2D(tex4, Tex);
	float4 Color5 = tex2D(tex5, Tex);

	if (idx < 1)
		Color = Color0;
	else if (idx < 2)
		Color = Color1;
	else if (idx < 3)
		Color = Color2;
	else if (idx < 4)
		Color = Color3;
	else if (idx < 5)
		Color = Color4;
	else
		Color = Color5;
	
	return Color;
}

Is this a bug in irrlicht? Or is it my fault?

D.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Irrlicht only supports 4 textures per material. There is a constant you can change in order to add more textures, but you will face many problems with it. Due to enums etc used elsewhere it's not really possible as of now to add more than 4 textures without changing also other parts of Irrlicht.
Post Reply