RTShader setup Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
eventhorizon
Kobold
Posts: 25
Joined: Wed Oct 20, 2010 4:56 am
x 6

RTShader setup

Post by eventhorizon »

Ogre Version: :?: 1.12
Operating System: :?: Windows and Linux
Render System: :?: OpenGL mainly

Hi, I'm currently trying to modernize an old software project of mine called Skyscraper, and currently have it running on Ogre 1.12. I'm trying to see if I can use the DirectX11 (on windows) and OpenGL3+ renderers, but I'm having some trouble figuring out how to enable the RTSS support. I also wanted to see if I could eventually enable per-pixel lighting.

When trying to use OpenGL3, the app dies with

"RenderSystem does not support FixedFunction, but technique of 'data/menu.png' has no Vertex Shader. Use the RTSS or write custom shaders."

In my code, I added some basic initialization:

Code: Select all

//Enable the RT Shader System
Ogre::RTShader::ShaderGenerator::initialize();
Ogre::RTShader::ShaderGenerator* shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
shaderGenerator->addSceneManager(mSceneMgr);

//set up default material shader scheme
mViewport->setMaterialScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);

I'm assuming that I have to create a listener in order for RTSS to work with the materials (I tried some code I found on the forum here, but it didn't compile correctly due to some issues), but since most of my materials are manually created, is there a way to make a material RTSS-enabled via code?

If you want to see the raw code file for the app frontend, here it is on GitHub:
https://github.com/eventhorizon5/skyscr ... craper.cpp

eventhorizon
Kobold
Posts: 25
Joined: Wed Oct 20, 2010 4:56 am
x 6

Re: RTShader setup

Post by eventhorizon »

For an update on this, I found a way to add an RTSS shader to manually-created meshes, that solves part of my problem, but not the one for objects that are not manually created.

Code: Select all

	//create RTSS shader
	Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(*mMat, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);

paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: RTShader setup

Post by paroj »

eventhorizon
Kobold
Posts: 25
Joined: Wed Oct 20, 2010 4:56 am
x 6

Re: RTShader setup

Post by eventhorizon »

Thanks, I tried using the ShaderResolver code in OgreBites too, and it appears to be working for me.

eventhorizon
Kobold
Posts: 25
Joined: Wed Oct 20, 2010 4:56 am
x 6

Re: RTShader setup

Post by eventhorizon »

This was working fine for me on Ogre 1.12, but with the switch to 13, it appears to have broken again. I verified that I'm initializing RTSS correctly, and am using the OgreBites library for the shader resolver:

Code: Select all

//Enable the RT Shader System
if (Ogre::RTShader::ShaderGenerator::initialize())
{
	Ogre::RTShader::ShaderGenerator* shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
	shaderGenerator->addSceneManager(mSceneMgr);

// forward scheme not found events to the RTSS
OgreBites::SGTechniqueResolverListener* schemeNotFoundHandler = new OgreBites::SGTechniqueResolverListener(shaderGenerator);
Ogre::MaterialManager::getSingleton().addListener(schemeNotFoundHandler);
}

mViewport->setMaterialScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);

For the resources.cfg, I'm loading the RTSS components:

[OgreInternal]
FileSystem=./media/ShadowVolume
FileSystem=./media/RTShaderLib/materials
FileSystem=./media/RTShaderLib/GLSL
FileSystem=./media/RTShaderLib/HLSL_Cg
FileSystem=./media/Terrain

Error messages I'm getting for shaders:

20:25:04: Error: RTSS: failed to create GpuPrograms for Pass 0 of 'data/button_triton.png'
20:25:04: Error: RTSS: failed to create GpuPrograms for Pass 0 of 'data/button_glasstower.png'

20:25:04: Unhandled OGRE exception:

InvalidParametersException: Named constants have not been initialised, perhaps a compile error in getConstantDefinitions at /data/src/ogre-13.4.3/OgreMain/src/OgreGpuProgramParams.cpp (line 1335)

paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: RTShader setup

Post by paroj »

eventhorizon
Kobold
Posts: 25
Joined: Wed Oct 20, 2010 4:56 am
x 6

Re: RTShader setup

Post by eventhorizon »

Thanks for that, it looks like I was missing the "Main" folder for some reason. It appears to work now.

simonschmeisser
Gnoblar
Posts: 4
Joined: Fri Apr 28, 2023 8:58 pm

Re: RTShader setup

Post by simonschmeisser »

I tried following the advice given in this thread but could not get things to work for RViz in https://github.com/ros-visualization/rviz/pull/1733

Is there a minimal sample code for how to combine RTShader with simple objects where the material is created from code?

paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: RTShader setup

Post by paroj »

simonschmeisser wrote: Sun Apr 30, 2023 11:39 am

I tried following the advice given in this thread but could not get things to work for RViz in https://github.com/ros-visualization/rviz/pull/1733

Is there a minimal sample code for how to combine RTShader with simple objects where the material is created from code?

for the RTSS, it does not matter whether the material comes from script or from code.
In the linked PR, it looks like all the RTSS initialization is in place.

If it does work for some materials already, likely the materials where it does not work are created too early i.e. before viewport_->setMaterialScheme

simonschmeisser
Gnoblar
Posts: 4
Joined: Fri Apr 28, 2023 8:58 pm

Re: RTShader setup

Post by simonschmeisser »

paroj wrote: Sun Apr 30, 2023 2:03 pm

If it does work for some materials already, likely the materials where it does not work are created too early i.e. before viewport_->setMaterialScheme

The materials are created in a plugin that I load manually once rviz has started so it is most likely something different. I found some more places that create Materials and added createShaderBasedTechnique there as well.

Can shaders be outdated by changes to the material (eg colors being changed)?

Can I somehow see which shaders were created or for which materials shaders where created and why they do not match?

paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: RTShader setup

Post by paroj »

simonschmeisser wrote: Mon May 01, 2023 10:50 am

The materials are created in a plugin that I load manually once rviz has started so it is most likely something different. I found some more places that create Materials and added createShaderBasedTechnique there as well.

if SGTechniqueResolverListener is working, you should not need to call createShaderBasedTechnique manually at all

simonschmeisser wrote: Mon May 01, 2023 10:50 am

Can shaders be outdated by changes to the material (eg colors being changed)?

there ara conditions, but colors are not part of that. A different color does not need a new shader.

simonschmeisser wrote: Mon May 01, 2023 10:50 am

Can I somehow see which shaders were created or for which materials shaders where created and why they do not match?

https://github.com/OGRECave/ogre/blob/f ... e.cpp#L132

this will also enable logging of the material -> shader mappings.

simonschmeisser
Gnoblar
Posts: 4
Joined: Fri Apr 28, 2023 8:58 pm

Re: RTShader setup

Post by simonschmeisser »

Thanks for your explanations, the theory sounds good and how I would love it to work. Unfortunately something is still amiss:

I enabled writing of shader cache to disk and indeed it now gives more debug output.

Code: Select all

[INFO] [1682961180.923146852]: RTSS: using 79903ded0e5ecbb5f1f5d64bdb373a31_VS for Pass 0 of 'robot link gripper_cables_frame:silver'
[INFO] [1682961180.923160117]: RTSS: using 0c6406765d7f117faa2fe9816e871421_FS for Pass 0 of 'robot link gripper_cables_frame:silver'

and then later it throws this exception on every frame:

Code: Select all

Ogre exception:  RenderSystem does not support FixedFunction, but technique of 'robot link gripper_cables_frame:silver' has no Vertex Shader. Use the RTSS or write custom shaders.
Attachments
log.txt
Full log
(60.81 KiB) Downloaded 18 times
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: RTShader setup

Post by paroj »

then the remaining explanation is that the wrong technique is used.
Do you do material->getTechnique(0) somewhere? That should be material->getBestTechnique()

simonschmeisser
Gnoblar
Posts: 4
Joined: Fri Apr 28, 2023 8:58 pm

Re: RTShader setup

Post by simonschmeisser »

So I finally got things to render. I first tried using

Code: Select all

maerial->getBestTechnique()

but that crashes in most places.
I then noticed that I can set most parameters directly on the material instead of the Technique. Then I was back to "no vertex shader"

Finally I looked at how rviz::Shapes other than Mesh are handled and those actually use a "box.mesh" etc. Replacing this by

Code: Select all

scene_manager->createEntity(name, Ogre::SceneManager::PT_CUBE);

finally made it render.

Now I need to clean up, fix the scale (milimeters vs meters?) and figure out what to do with Cylinder and Cone?

I'm also confused why displaying cubes ("box.mesh") as Marker worked but not as RobotLink.

Thanks for your help and hints!!!

paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: RTShader setup

Post by paroj »

uhh.. it sounds like you are throwing out the baby with the bathwater..

material->getBestTechnique() will return NULL, if material->load() was not called yet.
There are also valid usages of material->getTechnique(0) with the RTSS - notably before loading the material.
See this for details:
https://ogrecave.github.io/ogre/api/lat ... l#rtssTech

I think by switching to PT_CUBE, you merely switched to the "BaseWhite" Material, that happens to be already loaded..

Post Reply