Minimal RTSS init code for Fixed-Function emulation

Problems building or running the engine, queries about how to use features etc.
Post Reply
JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm
x 2

Minimal RTSS init code for Fixed-Function emulation

Post by JDX_John »

Looking at the wiki: http://www.ogre3d.org/tikiwiki/tiki-ind ... the_system

Code: Select all

if (Ogre::RTShader::ShaderGenerator::initialize())
{
	// Grab the shader generator pointer.
	mShaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
 
	// Add the shader libs resource location.
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(shaderLibPath, "FileSystem");
 
	// Set shader cache path.
	mShaderGenerator->setShaderCachePath(shaderCachePath);		
 
	// Set the scene manager.
	mShaderGenerator->addSceneManager(sceneMgr);
 
	// Add a specialized sub-render (per-pixel lighting) state to the default scheme render state
	RTShader::RenderState* pMainRenderState = 
		mShaderGenerator->createOrRetrieveRenderState(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME).first;
	pMainRenderState->reset();
 
	mShaderGenerator->addSubRenderStateFactory(new Ogre::RTShader::PerPixelLightingFactory);
	pMainRenderState->addTemplateSubRenderState(
		mShaderGenerator->createSubRenderState(Ogre::RTShader::PerPixelLightingFactory::Type));	
 
	return true;
}
Is the part about " specialized sub-render (per-pixel lighting)" needed as a core part of using RTSS, or can I do as little as make sure the resource path is added and the cache path set? Right now I just want my simple materials working so I see something rendered...
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Minimal RTSS init code for Fixed-Function emulation

Post by al2950 »

The PPL sub render state is not needed if you dont want it. Please note it is added as a TEMPLATE sub render state so it is added to all materials.

You do need, however, a couple more steps to get you up and running.
Firstly you need to set your viewport to use the default material scheme that the RTSS uses.

Code: Select all

ogreViewport->setMaterialScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
Secondly you need to set up a material listener to convert any materials which have not been setup for RTSS in the material script. If you have setup all materials using the rt_shader_system definition then you do not need to do this. Also note this will not convert any materials that have vertex or fragment shaders defined in the material.

Code: Select all

class RTSSDefaultTechniqueListener: public Ogre::MaterialManager::Listener
{
public:
	RTSSDefaultTechniqueListener::RTSSDefaultTechniqueListener(Ogre::RTShader::ShaderGenerator* pShaderGenerator)
	{
		m_ShaderGenerator = pShaderGenerator;
	}
	//---------------------------------------------------------------------------
	virtual RTSSDefaultTechniqueListener::~RTSSDefaultTechniqueListener()
	{
	}
	//-----

	/** This is the hook point where shader based technique will be created.
	It will be called whenever the material manager won't find appropriate technique
	that satisfy the target scheme name. If the scheme name is out target RT Shader System
	scheme name we will try to create shader generated technique for it. 
	*/
	virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex, 
		const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, 
		const Ogre::Renderable* rend)
	{	
		Ogre::Technique* generatedTech = NULL;

		// Case this is the default shader generator scheme.
		if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
		{
			bool techniqueCreated;

			// Create shader generated technique for this material.
			techniqueCreated = m_ShaderGenerator->createShaderBasedTechnique(
				originalMaterial->getName(), 
				Ogre::MaterialManager::DEFAULT_SCHEME_NAME, 
				schemeName);	

			// Case technique registration succeeded.
			if (techniqueCreated)
			{
				// Force creating the shaders for the generated technique.
				m_ShaderGenerator->validateMaterial(schemeName, originalMaterial->getName());
				
				// Grab the generated technique.
				Ogre::Material::TechniqueIterator itTech = originalMaterial->getTechniqueIterator();

				while (itTech.hasMoreElements())
				{
					Ogre::Technique* curTech = itTech.getNext();

					if (curTech->getSchemeName() == schemeName)
					{
						generatedTech = curTech;
						break;
					}
				}				
			}
		}

		return generatedTech;
	}

private:
	Ogre::RTShader::ShaderGenerator*	m_ShaderGenerator;			// The shader generator instance.		


};
We need to work on the documentation, so I would suggest a better place to to find information about the RTSS in the RTSS sample/demo.
JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm
x 2

Re: Minimal RTSS init code for Fixed-Function emulation

Post by JDX_John »

Thanks for your detailed answer, I will try this ASAP. I do find it a bit weird this isn't part of Ogre itself but then maybe RTSS is still in development.

One question:
If you have setup all materials using the rt_shader_system definition then you do not need to do this.
I don't know what this means, could you clarify? Is it something in the .material script maybe?
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Minimal RTSS init code for Fixed-Function emulation

Post by al2950 »

JDX_John wrote: One question:
If you have setup all materials using the rt_shader_system definition then you do not need to do this.
I don't know what this means, could you clarify? Is it something in the .material script maybe?
Yes....!

Using the above code you can quickly emulate the FFP, however RTSS is a lot more powerful than that :D. At the moment there is only a handful of Sub Render States (SRS) which can be applied to a render state or material. However these SRS allow you to very quickly add different types of materials. For example you might want have a material with a normal map and a reflection map in which case your material would look like this

Code: Select all

material TestMaterial 
{
	technique
	{
		pass
		{
			ambient 0.145 0.196 0.419 1.0
			diffuse 0.145 0.196 0.419 1.0		
			specular 0.1 0.1 0.1 0.1 10

			//this texture unit will be used as the diffuse texture by the RTSS
			texture_unit 
			{
				texture diffuse.dds
			}

			//RTSS material definition
			rtshader_system
			{
				lighting_stage normal_map normal.dds tangent_space 0 //adds normal mapped per pixel lighting
				rtss_ext_reflection_map cube_map reflect_mask.dds cloudy_noon.jpg 0.3 //adds reflection map
			}

		}

	}
}
NB. My first post was wrong its rtshader_system not rt_shader_system

Once again I would highly recommend you look at the sample as it will make more sense when you do!
JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm
x 2

Re: Minimal RTSS init code for Fixed-Function emulation

Post by JDX_John »

Cool, it works. Well actually it doesn't :(

I'm using MyGUI (I got it working nicely with GLES 1 to my surprise) and nothing MyGUI is getting rendered. I added logging to the Material listener and I can see all my materials are being processed for RTSS, but nothing is getting triggered for MyGUI. And no errors are being logged anywhere by Ogre or MyGUI about anything. It just doesn't render.

I probably should ask on the MyGUI forum but any ideas anyone?
User avatar
altren
Gnome
Posts: 329
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
x 24
Contact:

Re: Minimal RTSS init code for Fixed-Function emulation

Post by altren »

MyGUI doesn't use overlays. It use vertex buffers.

So you won't get any materials from MyGUI, because it doesn't use materials as well.
Image
Blender+C++
Gremlin
Posts: 171
Joined: Tue Jan 03, 2012 1:38 am
Location: Brazil
x 3

Re: Minimal RTSS init code for Fixed-Function emulation

Post by Blender+C++ »

Would someone happen to know how to implement RTSS using the Artifex terra 3d terrain loader? lets say i created a terrain map in Artifex terra 3d ,added a couple trees and a couple of houses and i loaded it from ogre but as im still a newbie ,ive been digging in the ogre samples and another sample posted in the artifex thread but i still didnt figure out how to add shadows , so not sure if this is a bad place to ask the regarded question but any help here is greatly appreciated!!
thx in advance for any reply,
Romulo Romero
PS: i wanted to cast shadows on the houses and trees and my character..
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Minimal RTSS init code for Fixed-Function emulation

Post by drwbns »

I'm lost on this. How do you use RTSSDefaultTechniqueListener? my techniqueCreated var is always false. I'm trying to use this with the terrain component and DX11 render system.

Here's my init code -

Code: Select all

bool BaseApplication::initRTSS() {
	if (Ogre::RTShader::ShaderGenerator::initialize())
	{
		// Grab the shader generator pointer.
		mShaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
 
		// Add the shader libs resource location.
		Ogre::ResourceGroupManager::getSingleton().addResourceLocation("libpath", "FileSystem");
 
		// Set shader cache path.
		mShaderGenerator->setShaderCachePath("cache");		
 
		// Set the scene manager.
		mShaderGenerator->addSceneManager(mSceneMgr);
 
		// Add a specialized sub-render (per-pixel lighting) state to the default scheme render state
		Ogre::RTShader::RenderState* pMainRenderState = 
			mShaderGenerator->createOrRetrieveRenderState(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME).first;
		pMainRenderState->reset();

		//added
		mTechniqueListener = new RTSSDefaultTechniqueListener(mShaderGenerator);
		Ogre::MaterialManager::getSingleton().addListener(mTechniqueListener);
 
		return true;
	}
	else return false;
}
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Minimal RTSS init code for Fixed-Function emulation

Post by al2950 »

I am currently putting together a basic tutorial for RTSS which I think will help you. However I have to admit I have not tested anything with DX11 yet.
gerymate
Gnoblar
Posts: 1
Joined: Fri Sep 19, 2014 8:52 am
Location: Budapest

Re: Minimal RTSS init code for Fixed-Function emulation

Post by gerymate »

al2950 wrote:I am currently putting together a basic tutorial for RTSS which I think will help you. However I have to admit I have not tested anything with DX11 yet.
I'm trying the same thing as drwbns, setting up a minimal RTSS system for Fixed-function emulation. I try to do this on the Intermediate Tutorial 7 code. The scene is rendered well with fixed function pipeline on DX9, but black with the above code on DX11 (although the OGRE tutorial's FPS counter is there).

Can I find your basic tutorial somewhere, al2950? Or any other easy-to-follow resource?
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Minimal RTSS init code for Fixed-Function emulation

Post by al2950 »

gerymate wrote:
al2950 wrote:I am currently putting together a basic tutorial for RTSS which I think will help you. However I have to admit I have not tested anything with DX11 yet.
I'm trying the same thing as drwbns, setting up a minimal RTSS system for Fixed-function emulation. I try to do this on the Intermediate Tutorial 7 code. The scene is rendered well with fixed function pipeline on DX9, but black with the above code on DX11 (although the OGRE tutorial's FPS counter is there).

Can I find your basic tutorial somewhere, al2950? Or any other easy-to-follow resource?
I am afraid I never published the tutorials I was working on, mainly because of the talk about what to do about RTSS at the time and because of the upcoming Ogre 2.0, where RTSS will most likely be phased out in favour of HLMS.

As for your issues its possible RTSS is not working properly with the Dx11 and the version of Ogre you have. There has been a lot of Dx11 based activity recently in the default branch, but released versions of Ogre have a relatively limited Dx11 renderer which I have not tested with RTSS. So I would get it working with Dx9 then try with Dx11.

For tutorials I would look at the sample code found in the ShaderSystem sample. Other than that there is plenty of forum posts with questions and answers.
However if you have the patience and dont have any immediate deadlines I would recommend you wait for Ogre 2.0 and its HLMS (High Level Material System)
Post Reply