Stuck trying to get Materials to work in V2.1

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
PontiusPirate
Gnoblar
Posts: 7
Joined: Mon Dec 12, 2016 9:03 pm

Stuck trying to get Materials to work in V2.1

Post by PontiusPirate » Tue Apr 25, 2017 10:50 pm

Hello everyone

A few months back I briefly looked into using Ogre 1.9 and was pleasantly surprised at the quality and depth of the tutorials and example projects. I was quickly able to get a basic scene up and working, so thanks!

I've begun a new project now using Ogre3D and decided to go straight into using version 2.1 but I've frequently become stuck and after 1.5 days of working on my project I'm still yet to render an object onto the screen (it isn't that bad, I've spent most of my time working on base classes etc.).
I'm stuck at the moment when trying to get a material to render on an object. I have taken the slightly weird route of working from a barebone project with none of the included example media/content etc. so that when I start adding custom assets it is easy to differentiate between what is mine and what came with Ogre.

However, I'm rather stuck getting a material to work on an object and was wondering if someone could give me an absolute idiots guide on how to get a material together and rendered on an object.
For some background context, I am manually building a mesh to use as a simple 3d background for my gameworld as the Terrain system was not working for me in 2.1.

My problems, in chronological order are:

1.

Code: Select all

	
Ogre::SubMesh* sub = mMesh->createSubMesh();
sub->mVao[Ogre::VpNormal].push_back(vao);
sub->mVao[Ogre::VpShadow].push_back(vao);

Ogre::Item *item = getSceneManager()->createItem(mMesh, Ogre::SCENE_DYNAMIC);
Ogre::SceneNode *sceneNode = getSceneManager()->getRootSceneNode(Ogre::SCENE_DYNAMIC)->createChildSceneNode(Ogre::SCENE_DYNAMIC);
sceneNode->attachObject(item);

Was throwing an exception saying that the material name for the submesh was a nullpointer. To get around this I manually named to 'empty' with:

Code: Select all

sub->mMaterialName = "Empty";
2.
I then made a basic material as shown below and referenced it's fileSystem in my resources.cfg as to be expected.

Code: Select all

material Empty
{
	technique
	{
		pass
		{
			ambient 0.8 0.8 0.8
		}
	}
}
However, I was then given this error message:
OGRE EXCEPTION(3:RenderingAPIException): Fixed Function pipeline is no longer allowed nor supported. The material Empty must use shaders in HlmsLowLevel::calculateHashFor at E:\Ogre_3D_2_1\OgreMain\src\OgreHlmsLowLevel.cpp (line 155)
I guess this means the old material types are incompatible, no worries, so I made this (Ensuring that the texture files were also correctly pathed):

Code: Select all

hlms Empty pbs
{
	roughness	1.0
	detail_map0				MRAMOR6X6.jpg
	detail_offset_scale0 	0 0 5 5
	roughness_map			MRAMOR-bump.jpg
}
However, now I just get the following exception:

Code: Select all

Can't assign material Empty because this Material does not exist. Have you forgotten to define it in a .material script?
I'm assuming this is because I didn't make the material correctly... or perhaps I didn't load it properly?
I'm just really stuck when it comes to the new material system, please help! :)

Thanks

PontiusPirate
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3458
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
Contact:

Re: Stuck trying to get Materials to work in V2.1

Post by dark_sylinc » Tue Apr 25, 2017 11:20 pm

Hi!

Did you register the PBS Hlms?

Initialization has changed considerably in Ogre 2.1; you can see how to setup the Hlms PBS in the samples provided (tick OGRE_BUILD_SAMPLES2; needs SDL2 to have been found across the dependencies); the specific function is GraphicsSystem::registerHlms. The Hlms must be initialized before parsing the scripts.

You may find a lot of questions answered in the Ogre 2.1 FAQ.
0 x

PontiusPirate
Gnoblar
Posts: 7
Joined: Mon Dec 12, 2016 9:03 pm

Re: Stuck trying to get Materials to work in V2.1

Post by PontiusPirate » Tue Apr 25, 2017 11:22 pm

Wow that was fast, thank you so much dark_sylinc.

I most certainly did not register the HLMS and will look at that now :)
0 x

PontiusPirate
Gnoblar
Posts: 7
Joined: Mon Dec 12, 2016 9:03 pm

Re: Stuck trying to get Materials to work in V2.1

Post by PontiusPirate » Tue Apr 25, 2017 11:50 pm

Looks like it's fixed the issue, thanks!

Now to work out why my manual mesh is crashing D3D11VaoManager::createDelayedImmutableBuffers method.... :D
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3458
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
Contact:

Re: Stuck trying to get Materials to work in V2.1

Post by dark_sylinc » Wed Apr 26, 2017 12:07 am

If you're having trouble creating a mesh by hand, try looking at the DynamicGeometry sample (Samples\2.0\ApiUsage\DynamicGeometry\) which shows how to create mesh programmatically and update it every frame.
0 x

PontiusPirate
Gnoblar
Posts: 7
Joined: Mon Dec 12, 2016 9:03 pm

Re: Stuck trying to get Materials to work in V2.1

Post by PontiusPirate » Wed Apr 26, 2017 12:40 am

Will do, thanks!
0 x

Post Reply