Page 1 of 1

7 layers material problem

Posted: Thu Jul 03, 2008 9:57 am
by Xplod
Hi all,

I'm currently doing a 7-layers material for my shader (OpenGL/GLSL). Here's the Material class code :

Code: Select all


//! Solid 7 layer material renderer
class COpenGLMaterialRenderer_SOLID_7_LAYER : public COpenGLMaterialRenderer
{
public:

	COpenGLMaterialRenderer_SOLID_7_LAYER(video::COpenGLDriver* d)
		: COpenGLMaterialRenderer(d) {}

	virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
		bool resetAllRenderstates, IMaterialRendererServices* services)
	{
		Driver->disableTextures(7);
		Driver->setTexture(6, material.getTexture(6));
		Driver->setTexture(5, material.getTexture(5));
		Driver->setTexture(4, material.getTexture(4));
		Driver->setTexture(3, material.getTexture(3));
		Driver->setTexture(2, material.getTexture(2));
		Driver->setTexture(1, material.getTexture(1));
		Driver->setTexture(0, material.getTexture(0));
			

		Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);

		if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
		{
			if (Driver->queryFeature(EVDF_MULTITEXTURE))
			{
				Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
				Driver->extGlActiveTexture(GL_TEXTURE1_ARB);
				Driver->extGlActiveTexture(GL_TEXTURE2_ARB);
				Driver->extGlActiveTexture(GL_TEXTURE3_ARB);
				Driver->extGlActiveTexture(GL_TEXTURE4_ARB);
				Driver->extGlActiveTexture(GL_TEXTURE5_ARB);
				Driver->extGlActiveTexture(GL_TEXTURE6_ARB);

				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
				glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
				glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
				glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE);
				glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
				glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
				glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR);
				/*glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE3_RGB_EXT, GL_TEXTURE);
				glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE4_RGB_EXT, GL_TEXTURE);
				glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE5_RGB_EXT, GL_TEXTURE);
				glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE6_RGB_EXT, GL_TEXTURE);*/
				glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);
			}
		}
	}

	virtual void OnUnsetMaterial()
	{
		if (Driver->queryFeature(EVDF_MULTITEXTURE))
		{
			Driver->extGlActiveTexture(GL_TEXTURE6_ARB);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
			Driver->extGlActiveTexture(GL_TEXTURE0_ARB);
		}
	}
};

I also did the modifications in the materials enums, and did the "addAndDropMaterial..;" thing (or something like that).

And the problem is that only the 4 first layers are working... Can someone help me?

Posted: Thu Jul 03, 2008 10:07 am
by JP
Irrlicht only supports 4 layers of materials.

Posted: Thu Jul 03, 2008 10:19 am
by Xplod
That's why I created a new material. I also changed the "MAX_MATERIAL_LAYERS" constant from SMaterial.h.
It must be possible to do it! Or a way to pass more than 4 textures to a shader at least

Posted: Thu Jul 03, 2008 10:42 pm
by Halifax
The reason Xplod is looking to do this is because I think the TSTerrainSceneNode did it. He used 7 textures per layer for texture splatting. And if I recall correctly, he did say that he modified the engine to support 7 textures or something.