Creating custom material renderer

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!
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Reading that part of API was where I got started. Problem is I can't derive new class from IMaterialRenderer. Eighter IDirect3DDevice9 or COpenGLDriver gave compiler error. I described problem at the begining of this post.

What do you mean by cast involved involved? I don't se casting there...

Thanks
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

arras wrote:I am trying to create custom material renderer. Since it's the firsth time, just to get started somewhere, I try to coppy one of the Irrlicht own material renderers.
Here's code:
...
...
I think you only need:

Code: Select all

video::SExposedVideoData data = driver->getExposedVideoData();

...

if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
      {
         data.D3D9.D3DDev9->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);
data.D3D9.D3DDev9->Set...
...
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Well, this realy looked promising belfegor. And so I did:

Code: Select all

class MyMaterialRenderer : public video::IMaterialRenderer
{
public:

	MyMaterialRenderer(video::IVideoDriver* driver)
	{
        Driver = driver;
        
	}
	
	virtual bool setVariable(bool vertexShader, const c8* name, const f32* floats, int count)
	{
		return false;
	}

	virtual void OnSetMaterial(video::SMaterial& material, const video::SMaterial& lastMaterial,
		bool resetAllRenderstates, video::IMaterialRendererServices* services)
	{
		if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
		{
         video::SExposedVideoData Data = Driver->getExposedVideoData();
            
			Data.D3D9.D3DDev9->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);
			Data.D3D9.D3DDev9->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
			Data.D3D9.D3DDev9->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
			Data.D3D9.D3DDev9->SetTextureStageState (0, D3DTSS_ALPHAOP,  D3DTOP_SELECTARG1);
			Data.D3D9.D3DDev9->SetTextureStageState (0, D3DTSS_ALPHAARG1,  D3DTA_DIFFUSE);

			Data.D3D9.D3DDev9->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
			Data.D3D9.D3DDev9->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

			Data.D3D9.D3DDev9->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
			Data.D3D9.D3DDev9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
			Data.D3D9.D3DDev9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		}

		material.ZWriteEnable = false;
		services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
	}

	virtual bool isTransparent()
	{
		return true;
	}

protected:

	video::IVideoDriver* Driver;
};
Compiled and get errors:
main.cpp In member function `virtual void MyMaterialRenderer::OnSetMaterial(irr::video::SMaterial&, const irr::video::SMaterial&, bool, irr::video::IMaterialRendererServices*)':
75 main.cpp invalid use of undefined type `struct IDirect3DDevice9'
10 irrlicht-1.3\include\SExposedVideoData.h forward declaration of `struct IDirect3DDevice9'
75 main.cpp `D3DTSS_COLOROP' undeclared (first use this function)
...and so on...
This is strange. Can you try to compile it on your computer just to weryfi it?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

arras you need to link and include the DirectX SDK because the device Irrlicht is returning is undefined normally.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

OK, thanks BlindSide.
What in case of OpenGL, what to link in order to get COpenGLDriver?
Post Reply