7 layers material problem

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
Xplod
Posts: 32
Joined: Sat Mar 29, 2008 5:48 pm
Contact:

7 layers material problem

Post 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?
I'm Ouverta on the chat |
Project leader/Lead Developer of Ouverta project.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Irrlicht only supports 4 layers of materials.
Image Image Image
Xplod
Posts: 32
Joined: Sat Mar 29, 2008 5:48 pm
Contact:

Post 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
I'm Ouverta on the chat |
Project leader/Lead Developer of Ouverta project.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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.
TheQuestion = 2B || !2B
Post Reply