How to make custom material? (NOT SHADER)

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Shinka
Posts: 2
Joined: Thu Jul 29, 2021 1:59 pm

How to make custom material? (NOT SHADER)

Post by Shinka »

Hello everyone!
I use Irrlicht 1.8.1
I want to make custom materials for my project, but without CG, GLSL and other shaders.

I found a way to do it inheriting the IMaterialRenderer class...
E.g. I need 2-layered material with sphere mapping and additive blending. To do this, I can do so:

Code: Select all

namespace irr
{
namespace video
{

class OGLMaterialAddRefl : public IMaterialRenderer
{
	public:
		void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
		bool resetAllRenderstates, IMaterialRendererServices* services) override
		{
			COpenGLDriver* driver = (COpenGLDriver*)services->getVideoDriver();
			driver->disableTextures(2);
			driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);

			if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
			{
				if (driver->queryFeature(EVDF_MULTITEXTURE))
				{
					driver->extGlActiveTexture(GL_TEXTURE1_ARB);
	#ifdef GL_ARB_texture_env_combine
					glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
					glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
					glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
					glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
	#else
					glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
					glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);
					glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
					glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
	#endif
				}
				glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
				glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
				glEnable(GL_TEXTURE_GEN_S);
				glEnable(GL_TEXTURE_GEN_T);
			}
		}
};

}
}
But I have a little small micro problem: I can not using the COpenGLDriver class outside the Irrlicht library without cheats!!!

How to solve this problem correctly without cheats and patching Irrlicht library?
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to make custom material? (NOT SHADER)

Post by CuteAlien »

Sorry, don't think there is a way around patching for this (or cheating by directly including Irrlicht classes from source folder and casting to the driver...).
Unfortunately Irrlicht tends to get in the way when trying work directly with OpenGL features :-(
And yeah... we hacked around it in a project once doing the - include source-folder files and cast to the opengl-driver. It's ugly and only works if Irrlicht is part of your project, but I have no other option for you unfortunately.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Shinka
Posts: 2
Joined: Thu Jul 29, 2021 1:59 pm

Re: How to make custom material? (NOT SHADER)

Post by Shinka »

I know how to make it an ugly way.
But maybe the Irrlicht has open classes and methods that allow to manipulate the applying textures?
Maybe can I do something like...

Code: Select all

IVideoDriver* driver = services->getVideoDriver();
const ITexture* firstTexture = material.getTexture(0);
const ITexture* secondTexture = material.getTexture(1);

driver->setTex...Method(firstTexture); // unknown for me method
glTex... // any OpenGL stuff
driver->setTex...Method(secondTexture); // unknown for me method
glTex... // any OpenGL stuff
Is it possible???

*OpenGL methods can be used without cheating.
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to make custom material? (NOT SHADER)

Post by CuteAlien »

Days like this I wonder why not just move every internal header to public. Some sub-folder called "internal interfaces" with a warning that there are no guarantees whatsoever when using those.
I had the same problem before with other c++ libraries - the code I want is in there, the interfaces exist - but I can't access them. All because it's "unclean" to open up internal interfaces. Which it probably is... but would allow people to get their job done.

I hope you find a way despite me being pretty sure it's not possible.

And yeah - setting textures directly would be nice, it's been long on my feature-wish-list. Mainly for other reasons (because that way we could break the stupid texture-limit caused by SMaterial and just set the textures not supported by those directly).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: How to make custom material? (NOT SHADER)

Post by netpipe »

reminds me to look and see if we have PBR based material system for irrlicht yet.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
Post Reply