[Bug] Eihort and splatting via shaders

CABAListic

25-02-2007 16:07:33

So I was trying to get splatting to work with my Eihort + PLSM2 application. The non-shader versions worked, but whenever I used any of the shader versions (TextureFormat set to SplattingShader or PLSplattingShaderXX) I received a weird Ogre exception InvalidParametersException which complained about an unknown parameter splatSettings when executing a GPU program.

It took me some hours to figure out, but finally I found in the PLSM2 code in OgrePagingLandScapeTexture.cpp at line 130 the code line that set this parameter, even though none of the newer splatting shaders use it:

params->setNamedConstant("splatSettings", Vector4(opt->matHeight[1], opt->matHeight[2], opt->maxValue, 0));

I test compiled my code against a Dagon version, and voila, the error vanished. Since Dagon doesn't even know the InvalidParametersException class, I assume that Eihort became more restrictive with redundant shader parameters and throws when Dagon does not.

So unless I'm missing some point (still new to PLSM and Ogre), the whole line 130 needs to be removed. This fixed my problems, splatting is now working.

kungfoomasta

25-02-2007 19:10:21

CABAListic,

how hard is it to do terrain splatting? Is it possible you could point me in the right direction to be able to texture terrain, or throw me some code to give me a starting direction? I'm sure it will help others as well. :)

KungFooMasta

asmo

25-02-2007 21:14:40

@CABAListic
Thank you! (:
Someone should update the current CVS version, as it contains other bugs as well (which are covered in other posts along with solutions).

@kungfoomasta
It's trivial, look at how GOOFEd do it.

CABAListic

25-02-2007 21:44:18

@kungfoomasta: I'm only just in the process of learning how to do stuff with PLSM, so sorry, can't yet give you any insight. As I stated, it cost me hours just to get the example terrain loading with splatting ;)
Once I've worked my way through all the features, I'll see if I can write some sort of tutorial should I find the time (since the documentation is ... well ... mainly sparse or non-existant :D )

asmo

26-02-2007 13:50:19

@CABAListic

I'm still having problem with this. The problem is at line 339, which when removed shows blank terrain.

When using the normal splatting mode, splatting looks like this:

http://www.netherforce.com/images/weirdTerrain.png

I'm not sure if the splatting shader works differently or if I can solve this my using the normal splatting method?

tuan kuranes

28-02-2007 14:23:24

First Eihort PLSM2 code is incorrect about that for now, as patch author commented useful code.
I changed that in CVS. Should be soon visible for anon CVS.

Meanwhile correct code is

#ifdef PLSM2_EIHORT
GpuConstantDefinition const * const e = params->_findNamedConstantDefinition("splatSettings", false);

// use index to get RealConstantEntry
params->_writeRawConstant(e->physicalIndex + 0, opt->matHeight[1]);
params->_writeRawConstant(e->physicalIndex + 1, opt->matHeight[2]);
params->_writeRawConstant(e->physicalIndex + 2, float(opt->maxValue));
params->_writeRawConstant(e->physicalIndex + 3, 0.0f);

#else
GpuProgramParameters::RealConstantEntry * const e = params->getNamedRealConstantEntry ("splatSettings");
if (e)
{
e->val[0] = static_cast <float> (opt->matHeight[1]);
e->val[1] = static_cast <float> (opt->matHeight[2]);
e->val[2] = static_cast <float> (opt->maxValue);
e->val[3] = static_cast <float> (0.0);
e->isSet = true;
}
#endif

asmo

28-02-2007 19:36:37

@tuan kuranes
params->_findNamedConstantDefinition("splatSettings", false);
return null for me, so still a problem it seems :/

hotgloupi

03-06-2007 21:44:11

@tuan,

you gave this solution (that is not in CVS version) but as asmo said, this function ( ->_findNamedConstantDefinition("splatSettings", false) ) generate an error :evil: , maybe params wasnt not initialised correctly with p->getVertexProgramParameters() ...
Im so newbie in Ogre Structure so explain please or give something to try !!
bye !
First Eihort PLSM2 code is incorrect about that for now, as patch author commented useful code.
I changed that in CVS. Should be soon visible for anon CVS.

Meanwhile correct code is

#ifdef PLSM2_EIHORT
GpuConstantDefinition const * const e = params->_findNamedConstantDefinition("splatSettings", false);

// use index to get RealConstantEntry
params->_writeRawConstant(e->physicalIndex + 0, opt->matHeight[1]);
params->_writeRawConstant(e->physicalIndex + 1, opt->matHeight[2]);
params->_writeRawConstant(e->physicalIndex + 2, float(opt->maxValue));
params->_writeRawConstant(e->physicalIndex + 3, 0.0f);

#else
GpuProgramParameters::RealConstantEntry * const e = params->getNamedRealConstantEntry ("splatSettings");
if (e)
{
e->val[0] = static_cast <float> (opt->matHeight[1]);
e->val[1] = static_cast <float> (opt->matHeight[2]);
e->val[2] = static_cast <float> (opt->maxValue);
e->val[3] = static_cast <float> (0.0);
e->isSet = true;
}
#endif

Jon

03-06-2007 22:19:55

What is your material? Does it have splatSettings defined?

hotgloupi

04-06-2007 00:48:55

Yes I think material is defined because i dont speak about my program but about the demo, and texture format that i specified in hf_129_3.cfg is Base (i tried all of 14 possibilities ;)) so...

Jon

04-06-2007 02:21:18

A texture format is not a material, and the base texture material does not use splatSettings.

I am running the CVS demo without difficulties under Windows. So I feel there is something else you are not telling us.

hotgloupi

04-06-2007 08:48:17

no i dont !
Is splatting a method to apply material via shaders?
Did you need to specifie something (as a material) to launch demo?
should i change something in hf_129_3.cfg, or in PagingLandscape2 source code?

blinkeye

08-06-2007 12:13:55

I'm stuck with the same error. I too try to get the demo to run:

Parsing script DebugOverlay.overlay
Finished parsing scripts for resource group PLSM2
Initialising resource group PLSM2
Added resource location '../../../../../Media/paginglandscape2/terrains/hf129_3' of type 'FileSystem' to resource group 'PLSM2'
Initialising resource group PLSM2

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1232652624 (LWP 1745)]
_______________________________________________________________________________
eax:00000008 ebx:B7D9D2E8 ecx:00000000 edx:BFE34548 eflags:00010282
esi:08CA5D08 edi:00000000 esp:BFE344D0 ebp:BFE34518 eip:B7AE12BD
cs:0073 ds:007B es:007B fs:0000 gs:0033 ss:007B o d I t S z a p c
[007B:BFE344D0]---------------------------------------------------------[stack]
BFE34500 : 0D 00 00 00 0D 00 00 00 - 28 45 E3 BF 58 8E 9B B7 ........(E..X...
BFE344F0 : 0C 73 CD 08 AC 6E CD 08 - 2C 00 00 00 F4 8F CB B6 .s...n..,.......
BFE344E0 : 1A 00 00 00 AC 6E CD 08 - 08 45 E3 BF 23 08 B0 B6 .....n...E..#...
BFE344D0 : 1E 76 32 37 00 00 00 00 - 08 45 E3 BF 79 CE C8 B6 .v27.....E..y...
[007B:08CA5D08]---------------------------------------------------------[ data]
08CA5D08 : 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................
08CA5D18 : 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................
[0073:B7AE12BD]---------------------------------------------------------[ code]
0xb7ae12bd <_ZNKSt8_Rb_treeISsSt4pairIKSsN4Ogre21GpuConstantDefinitionEESt10_Select1stIS4_ESt4lessISsESaIS4_EE4findERS1_+11>: mov 0x8(%eax),%edx
0xb7ae12c0 <_ZNKSt8_Rb_treeISsSt4pairIKSsN4Ogre21GpuConstantDefinitionEESt10_Select1stIS4_ESt4lessISsESaIS4_EE4findERS1_+14>: add $0x4,%eax
0xb7ae12c3 <_ZNKSt8_Rb_treeISsSt4pairIKSsN4Ogre21GpuConstantDefinitionEESt10_Select1stIS4_ESt4lessISsESaIS4_EE4findERS1_+17>: mov %eax,0xffffffd8(%ebp)
0xb7ae12c6 <_ZNKSt8_Rb_treeISsSt4pairIKSsN4Ogre21GpuConstantDefinitionEESt10_Select1stIS4_ESt4lessISsESaIS4_EE4findERS1_+20>: mov %eax,0xffffffe4(%ebp)
0xb7ae12c9 <_ZNKSt8_Rb_treeISsSt4pairIKSsN4Ogre21GpuConstantDefinitionEESt10_Select1stIS4_ESt4lessISsESaIS4_EE4findERS1_+23>: test %edx,%edx
0xb7ae12cb <_ZNKSt8_Rb_treeISsSt4pairIKSsN4Ogre21GpuConstantDefinitionEESt10_Select1stIS4_ESt4lessISsESaIS4_EE4findERS1_+25>: je 0xb7ae134b <_ZNKSt8_Rb_treeISsSt4pairIKSsN4Ogre21GpuConstantDefinitionEESt10_Select1stIS4_ESt4lessISsESaIS4_EE4findERS1_+153>
------------------------------------------------------------------------------
0xb7ae12bd in std::_Rb_tree<std::string, std::pair<std::string const, Ogre::GpuConstantDefinition>, std::_Select1st<std::pair<std::string const, Ogre::GpuConstantDefinition> >, std::less<std::string>, std::allocator<std::pair<std::string const, Ogre::GpuConstantDefinition> > >::find () from /usr/lib/libOgreMain-1.4.1.so
gdb> bt
#0 0xb7ae12bd in std::_Rb_tree<std::string, std::pair<std::string const, Ogre::GpuConstantDefinition>, std::_Select1st<std::pair<std::string const, Ogre::GpuConstantDefinition> >, std::less<std::string>, std::allocator<std::pair<std::string const, Ogre::GpuConstantDefinition> > >::find () from /usr/lib/libOgreMain-1.4.1.so
#1 0xb7add87d in Ogre::GpuProgramParameters::_findNamedConstantDefinition () from /usr/lib/libOgreMain-1.4.1.so
#2 0xb7e6edb7 in Ogre::PagingLandScapeTexture::setOptions (this=0x8cde190) at OgrePagingLandScapeTexture.cpp:352
#3 0xb7e7960d in Ogre::PagingLandScapeTextureManager::load (this=0x8cd1550) at OgrePagingLandScapeTextureManager.cpp:357
#4 0xb7e5a047 in Ogre::PagingLandScapeSceneManager::loadScene (this=0x82abc78) at OgrePagingLandScapeSceneManager.cpp:288
#5 0xb7e5a4b8 in Ogre::PagingLandScapeSceneManager::setWorldGeometry (this=0x82abc78, stream=@0xbfe348c4, typeName=@0xb7dad090) at OgrePagingLandScapeSceneManager.cpp:206
#6 0xb7e5a9a0 in Ogre::PagingLandScapeSceneManager::setWorldGeometry (this=0x82abc78, filename=@0xbfe34950) at OgrePagingLandScapeSceneManager.cpp:237
#7 0x08058c94 in PagingLandScapeApplication::createScene (this=0xbfe34a00) at ../../../Samples/Common/include/PagingLandScape2Application.h:222
#8 0x0805cf62 in PagingLandScapeApplication::setup (this=0xbfe34a00) at ../../../Samples/Common/include/PagingLandScape2Application.h:70
#9 0x0804ea04 in main () at ../../../Samples/Common/include/ExampleApplication.h:89


This error obviously means that

GpuConstantDefinition const * const e = params->_findNamedConstantDefinition("splatSettings", false);

of OgrePagingLandScapeTexture.cpp doesn't find splatSettings.

The fixes for OgrePagingLandScapeTexture.cpp as provided in these forums have been applied:

#ifdef PLSM2_EIHORT
GpuConstantDefinition const * const e = params->_findNamedConstantDefinition("splatSettings", false);

if(e)
{
// use index to get RealConstantEntry
params->_writeRawConstant(e->physicalIndex + 0, opt->matHeight[1]);
params->_writeRawConstant(e->physicalIndex + 1, opt->matHeight[2]);
params->_writeRawConstant(e->physicalIndex + 2, float(opt->maxValue));
params->_writeRawConstant(e->physicalIndex + 3, 0.0f);
}
#else
GpuProgramParameters::RealConstantEntry * const e = params->getNamedRealConstantEntry ("splatSettings");
if (e)
{
e->val[0] = static_cast <float> (opt->matHeight[1]);
e->val[1] = static_cast <float> (opt->matHeight[2]);
e->val[2] = static_cast <float> (opt->maxValue);
e->val[3] = static_cast <float> (0.0);
e->isSet = true;
}
#endif


So, where is this Option "splatSettings" supposed to be defined and what should it read?

Jon

08-06-2007 22:25:29

Thanks for posting the stack trace, we can now get somewhere with this.

In my opinion, the problem is not that splatSettings isn't found, but that the container's find crashes. It looks like params->_findNamedConstantDefinition is designed to return NULL if the setting isn't found, in which case PLSM is supposed to go on its way.

To address the red herring, splatSettings is a shader parameter in certain materials (which is why I was asking what material was being used, earlier).
splatting5.material for example contains:


param_named splatSettings float4 22500.0 6500.0 95500.0 0.0


Please do not add this to other materials. Materials like base do not need this parameter. And its absence is not the problem.

Now, I'm running the Demo_PagingLandScape2 application without incident, so something may have changed in CVS recently.

I set a breakpoint on this line, and did not hit it until I selected "Splatting5" as the texture mode. I suggest setting a breakpoint there, and confirming which texture modes hit it.

The material being used was "Splatting5.2.4.s4", which is a copy of Splatting5. This was determined by moving up the stack to the texture load method and examining mMaterial.

blinkeye

11-06-2007 08:29:07

In my opinion, the problem is not that splatSettings isn't found, but that the container's find crashes.
Yes, I agree. Debug Pic1 and Debug Pic2 show that the problem is actually on line 348 of OgrePagingLandScapeTexture.cpp
GpuProgramParametersSharedPtr params = p->getVertexProgramParameters();

I added some printfs to see at what it's failing:

Finished parsing scripts for resource group PLSM2
Initialising resource group PLSM2
Added resource location '../../../../../Media/paginglandscape2/terrains/hf129_3' of type 'FileSystem' to resource group 'PLSM2'
Initialising resource group PLSM2

# Pass:
- Name: 0
- hasVertexProgram: 1

# Technique
- Name:
- SchemeName: Default
- ResourceGroup: PLSM2

# Material
- Name: InstantBaseDecompress
- Group: PLSM2
- Origin: BaseTexture.material

Segmentation fault


Not that this would help me at all ...

blinkeye

19-06-2007 14:32:35

An update: CVS got updated with some patches and building PLSM2 on GNU/Linux is no longer an issue. Another patch from hotgloupi is needed. Nevertheless I'm not yet able to run a demo.

I posted the errors here.