Glow compositor problem

puso1990

21-03-2012 16:29:50

Hi there!

Has anyone tried to port this glow shader to Mogre? http://www.ogre3d.org/tikiwiki/Glow&structure=Cookbook

I have tried it, and I get stuck at MaterialManager.Listener.
The original code from Ogre:
#ifndef GLOWMATERIALLISTENER_H__
#define GLOWMATERIALLISTENER_H__

#include <Ogre.h>
#include <OgreMaterialManager.h>

class GlowMaterialListener : public Ogre::MaterialManager::Listener
{
protected:
Ogre::MaterialPtr mBlackMat;
public:
GlowMaterialListener()
{
mBlackMat = Ogre::MaterialManager::getSingleton().create("mGlowBlack", "Internal");
mBlackMat->getTechnique(0)->getPass(0)->setDiffuse(0,0,0,0);
mBlackMat->getTechnique(0)->getPass(0)->setSpecular(0,0,0,0);
mBlackMat->getTechnique(0)->getPass(0)->setAmbient(0,0,0);
mBlackMat->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,0);
}

Ogre::Technique *handleSchemeNotFound(unsigned short, const Ogre::String& schemeName, Ogre::Material*mat, unsigned short, const Ogre::Renderable*)
{
if (schemeName == "glow")
{
//LogManager::getSingleton().logMessage(">> adding glow to material: "+mat->getName());
return mBlackMat->getTechnique(0);
}
return NULL;
}
};

#endif //GLOWMATERIALLISTENER_H__


I have ported to Mogre this way:
using System;
using Mogre;

namespace U3DT.Engine.Engine_Objects
{
class GlowMaterialListener : MaterialManager.Listener
{
protected Mogre.MaterialPtr mBlackMat;

public GlowMaterialListener()
{
mBlackMat = MaterialManager.Singleton.Create("mGlowBlack", "Internal");
mBlackMat.GetTechnique(0).GetPass(0).SetDiffuse(0,0,0,0);
mBlackMat.GetTechnique(0).GetPass(0).SetSpecular(0,0,0,0);
mBlackMat.GetTechnique(0).GetPass(0).SetAmbient(0,0,0);
mBlackMat.GetTechnique(0).GetPass(0).SetSelfIllumination(0,0,0);
}

Technique HandleSchemeNotFound(ushort schemeIndex, string schemeName, Material originalMaterial, ushort lod, Renderable rend)
{
if (schemeName == "glow")
{
//LogManager::getSingleton().logMessage(">> adding glow to material: "+mat->getName());
return mBlackMat.GetTechnique(0);
}
return null;
}
}
}

... and I got stuck at HandleSchemeNotFound technique. I get error "U3DT.Engine.Engine_Objects.GlowMaterialListener' does not implement inherited abstract member 'Mogre.MaterialManager.Listener.HandleSchemeNotFound(ushort, string, Mogre.Material, ushort, Mogre.IRenderable)"

I have noticed, that in Mogre this technique is different. The MaterialManager.Listener is public abstract class and so the HandleSchemeNotFound is public abstract method. And in Ogre this technique is virtual. I have no idea, how this technique works, so I am desperate for help here. What do I have to do, to get this thing going.

Thanks for your help.

Cheers!

tafkag

21-03-2012 19:02:49

I tested this technique a while ago, but without using a MaterialListener. I put the glowing objects in one list and the non-glowing objects in another list. Each glowing object has two materials, the regular material and the glow material, marked by a '_glow' suffix in the material name. Then I switch them around in the RenderTarget events, so that only the glow part is visible in the render texture.


void RenderTexture0_PreRenderTargetUpdate(RenderTargetEvent_NativePtr evt)
{
// Turn non-glowing objects invisible.
foreach (SceneNode node in _nonGlowNodes)
SceneMgr.RootSceneNode.RemoveChild(node);

// Change materials of glowing objects to glow material by adding _glow suffix.
foreach (IGlowable glowObj in _glowObjects)
SwitchGlowMaterial(glowObj, true);

}

void RenderTexture0_PostRenderTargetUpdate(RenderTargetEvent_NativePtr evt)
{
// Put back the non-glowing into the scene graph.
foreach (SceneNode node in _nonGlowNodes)
SceneMgr.RootSceneNode.AddChild(node);

// Change materials of glowing objects back to render materials.
foreach (IGlowable glowObj in _glowObjects)
SwitchGlowMaterial(glowObj, false);
}


Probably not exactly what you wanted, but it worked pretty well in my little test game.

puso1990

21-03-2012 20:13:53

Ok now I have repaired the GlowMaterialListener to:
using System;
using Mogre;

namespace U3DT.Engine.Engine_Objects
{
class GlowMaterialListener : MaterialManager.Listener
{
protected Mogre.MaterialPtr mBlackMat;

public GlowMaterialListener()
{
mBlackMat = MaterialManager.Singleton.Create("mGlowBlack", "Internal");
mBlackMat.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 0, 0);
mBlackMat.GetTechnique(0).GetPass(0).SetSpecular(0, 0, 0, 0);
mBlackMat.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 0);
mBlackMat.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 0);
}

public override Technique HandleSchemeNotFound(ushort schemeIndex, string schemeName, Material originalMaterial, ushort lod, IRenderable rend)
{
if (schemeName == "glow")
{
//LogManager::getSingleton().logMessage(">> adding glow to material: "+mat->getName());
return mBlackMat.GetTechnique(0);
}
return null;
}
}
}

The problem was, that in OGRE the last argument for HandleSchemeNotFound is Renderable type, but in MOGRE it is IRenderable type. I don't get the compiler error. But It's still not working.

The following code, should add compositor to viewport and create material listener for glow:
{
CompositorManager.Singleton.AddCompositor(mViewport,"Glow");
CompositorManager.Singleton.SetCompositorEnabled(mViewport,"Glow",true);
Engine_Objects.GlowMaterialListener GlowListener = new Engine_Objects.GlowMaterialListener();
MaterialManager.Singleton.AddListener(GlowListener);
}


But it's still not working. And when I look at the LOG file I found this:
21:07:35: WARNING: material GlowCompositorMat/GlowB has no supportable Techniques and will be blank. Explanation:
Pass 0: Fragment program GlowB_fp cannot be used - not supported.

What could that possible mean?

Please help!

puso1990

21-03-2012 20:19:01

Since I am newbie at this stuff... Probably I need to add something to plugins.cfg? But I don't know how to do it.

tafkag

21-03-2012 20:32:25

Since I am newbie at this stuff... Probably I need to add something to plugins.cfg? But I don't know how to do it.

Since you are using the cg shader language, make sure you have the cg plugin in you plugins.cfg

Plugin=Plugin_CgProgramManager

puso1990

21-03-2012 20:49:58

yes, but I can't find a working CgProgramManager.dll anywhere. I have cg.dll. I have downloaded Mogre 1.7.1 SDK, and there is CgProgramManager_d.dll and it's not working. Where can I find the missing dll?

tafkag

21-03-2012 21:02:35

I have downloaded Mogre 1.7.1 SDK, and there is CgProgramManager_d.dll and it's not working. Where can I find the missing dll?

Should be in bin/Release

puso1990

21-03-2012 21:10:11

22:08:54: Loading library .\Plugin_CgProgramManager
22:08:54: OGRE EXCEPTION(7:InternalErrorException): Could not load dynamic library .\Plugin_CgProgramManager. System Error: %1 ni veljaven program Win32.

in DynLib::load at ..\..\ogre\OgreMain\src\OgreDynLib.cpp (line 91)

still not working... I don't know what to do. It's just not installing CG plugin

puso1990

22-03-2012 08:02:29

Ok this thing is now working. In a strange way but sure I have to polish it :)

So anyone who is strugling with this, the final code for MaterialManager.Listener for Glow composition listener, the following code works perfectly:
using Mogre;

namespace U3DT.Engine.Engine_Objects //My name space
{
class GlowMaterialListener : MaterialManager.Listener
{
protected Mogre.MaterialPtr mBlackMat;

public GlowMaterialListener()
{
mBlackMat = MaterialManager.Singleton.Create("mGlowBlack", "Internal");
mBlackMat.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 0, 0);
mBlackMat.GetTechnique(0).GetPass(0).SetSpecular(0, 0, 0, 0);
mBlackMat.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 0);
mBlackMat.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 0);
}

public override Technique HandleSchemeNotFound(ushort schemeIndex, string schemeName, Material originalMaterial, ushort lod, IRenderable rend)
{
if (schemeName == "glow")
{
//LogManager::getSingleton().logMessage(">> adding glow to maerial: "+mat->getName());
return mBlackMat.GetTechnique(0);
}
return null;
}
}
}


and don't forget to include cg.dll, Plugin_CgProgramManager.dll and don't forget to add "Plugin=Plugin_CgProgramManager" to your plugins.cfg file.

PS: Thanks for help :)

cheers

tafkag

22-03-2012 16:18:16

Glad you got it working and thanks for sharing the code!

Beauty

11-04-2012 13:22:04

the following code works perfectly
It would be nice to add it to the wiki.

Is "Internal" an Ogre default resource group?
If not (or unshure), it should be created before to avoid a crash.

if (ResourceGroupManager.Singleton.ResourceGroupExists("Internal") == false)
ResourceGroupManager.Singleton.CreateResourceGroup("Internal");