Painting terrain -> Crash

Xavyiy

06-09-2007 00:41:03

Hi!,
I'm writting a little terrain editor using PLSM2 and when I try to paint the terrain the program crash.
Deformations works very well, only painting the terrain crash my program.

There's the code:

float mPaintChannelValues[4];
for(int i = 0; i < 4; ++i)
{
if(i == 1) // Asign by default i == 1, only for try to paint.
mPaintChannelValues[i] = 1.0f;
else
mPaintChannelValues[i] = 0.0f;
}

mSceneManager->setOption("setPaintChannelValues", &mPaintChannelValues);

mMapa->SetBrocha(50,50);

mSceneManager->setOption("PaintCenter", &mMapa->GetCoordenadas(CEGUI::MouseCursor::getSingleton().getPosition()));


mMapa->SetBrocha(50, 50) only set the brush array. It isn't the problem beacuse the terrain deformations works fine.
The program crash at:

mSceneManager->setOption("PaintCenter", &mMapa->GetCoordenadas(CEGUI::MouseCursor::getSingleton().getPosition()));

Here is my .cfg terrain file:

GroupName=PLSM2

Width=1
Height=1

Data2DFormat=HeightField
LandScapeFileName=TMP

FileSystem=terrain
TextureStretchFactor=1

NumTextureFormatSupported=1

TextureFormatSupported0=ImagePaging
TextureFormat=ImagePaging
ImageFilename=TMP_texture

ScaleX=15000
ScaleY=1000
ScaleZ=15000

Deformable=yes
TextureModifiable=yes
VertexCompression=no
VertexProgramMorph=no
VertexNormals=yes
VertexLit=no
NormalMap=yes

NumMatHeightSplat=4
Height1=15
Height2=50
SplatFilename0=splatting_sand.png
SplatFilename1=splatting_grass.png
SplatFilename2=splatting_rock.png
SplatFilename3=splatting_snow.png


Can anyone help me? Thanks for all, and sorry for my little English!!

Xavyiy

09-09-2007 17:33:29

Can anyone help me?please its realy important. I cant go on until i solve this. I tried all.
I have too donwloaded a GOOF binary (from: http://sourceforge.net/project/platform ... _id=202941 ) but painting the terreain doesn't work, the program crash at painting the terrain. it's my computer or is GOOF?
Please help me!!

Thanks.

bibiteinfo

19-10-2007 04:24:12

I'm working on finding what is causing the bug in GOOF ... actually no improvement, help from Tuan would be greatly appreciate.

Line where it crash


mSceneMgr->setOption("PaintCenter", &mBrushPos);


It crash in the function paint because of an out of bound exception in the paint function on line


BaseData[ currImagePos + j ] =
static_cast <uchar> (
((*channelModifList)[currChannel]) * paintForce * bScale
+ BaseData[ currImagePos + j ] * invPaintForce
);


My feeling is that the problem is not there, but in a splatting file, or something like this ... Don't know how to check this, I don't understand what's going on in those file.

tuan kuranes

19-10-2007 13:10:00

Either coverage texture are not at same size (texturescale problem), either material is using several coverage file (not sure painting in that case was done)

try testing on those two direction to file the best bug report possible.

bibiteinfo

19-10-2007 16:05:54

ok I've done debugging. I can make it work, but it's a Hack and it will probably crash if I change anything.

Firstly, Falagard noted that


BaseData[ currImagePos + j ] = static_cast <uchar> (((*channelModifList)[currChannel]) * paintForce * bScale + BaseData[ currImagePos + j ] * invPaintForce);


The (((*channelModifList)[currChannel]) should be (((*channelModifList)[j])

Here's the complete function :

void PagingLandScapeTexture::paintPoint (const unsigned int imagePos,
const Real paintForce)
{
assert (mNumTexture > 0);
assert(mParent->channelModifList);
const std::vector<Real> *channelModifList = mParent->channelModifList;
const uchar bScale = 255;
const Real invPaintForce = 1.0f - paintForce;
unsigned int currChannel = 0;
for (unsigned int k = 0; k < mNumTexture; k++)
{
uchar * const BaseData = mImages[k].getData();
assert (BaseData && "PagingLandScapeTexture::paint()");
const unsigned int currImagePos = imagePos * mNumChannelperTexture[k];
assert (currImagePos < mImages[k].getSize ());
assert (mNumChannelperTexture[k]*8 == mImages[k].getBPP ());

for (unsigned int j = 0; j < mNumChannelperTexture[k]; j++)
{
BaseData[ currImagePos + j ] =
static_cast <uchar> (
((*channelModifList)[j]) * paintForce * bScale
+ BaseData[ currImagePos + j ] * invPaintForce
);
currChannel++;
}
doTextureNeedUpdate[k] = true;
}
}



Secondly, the mNumTexture is 3. When debugging, there's 2 of them which are coming from coverage texture and one is coming from base texture. It seems like it's this last one which is making trouble. The mImage[2] which is the base is never loaded, so it's a NULL pointer.

With the code

for (unsigned int k = 0; k < mNumTexture - 1; k++)


it work, but this is a hack and I don't want to use that, it's too much dirty.

I've tried in my .cfg files the value 1 to 4 for the TextureStretchFactor and it didn't change anything.

Here's my .cfg file

GroupName=PLSM2
LandScapeFileName=DefaultGOOFEdMap
LandScapeExtension=raw
Width=2
Height=2
PageSize=129
TileSize=65
ScaleX=258
ScaleY=1024
ScaleZ=258
MaxRenderLevel=5
MaxPixelError=6
Deformable=yes
VertexCompression=yes
VertexProgramMorph=yes
VisibleRenderables=256
CameraThreshold=1
AvgColorsExists=yes
TextureFormat=PLSplattingShaderLit
NumMatHeightSplat=4
TextureFormatSupported0=PLSplattingShaderLit
NumTextureFormatSupported=1
TextureStretchFactor=2
TextureModifiable=yes
MaterialDistanceLod=256
VertexLit=yes
VertexNormals=yes
SplatFilename0=Terrain_Dirt1.jpg
SplatFilename1=Terrain_Rock1.jpg
SplatFilename2=Terrain_Grass1.jpg
SplatFilename3=Terrain_Cobble1.jpg
MaxNumRenderables=256
MaxNumTiles=256
MaxAdjacentPages=8
FileSystem=../../../Media/paginglandscape2/terrains/LandScapeFileName



and this is the material where base and coveraged are loaded; where the mNumTexture is taken from.


material PLSplattingShaderLitDecompress
{
//doesn't matter what we put here for lod_distances, the paging landscape system uses the configuration setting in the terrain config file for material lod distances
lod_distances 1
technique
{
lod_index 0

//Ambient pass
//This is the first pass that runs before all other passes
//In fact, Ogre knows this is an ambient only pass because ambient is 1, 1, 1, 1
//and therefore all ambient passes on all materials first before continuing on to other passes
//This allows early z out by laying down the depth buffer so that the expensive pixel shaders don't have to attempt
//to render to pixels that are going to end up occluded

pass AmbientPass
{
// These base colors identify the pass to Ogre as an ambient only pass
// but are ignored by the shaders
ambient 1 1 1
emissive 0 0 0
diffuse 0 0 0
specular 0 0 0 0

// Ambient and emissive pass vertex program
vertex_program_ref PLDecompressAmbientVPCG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto globalAmbient ambient_light_colour
param_named matAmbient float4 1 1 1 1
param_named matEmissive float4 0 0 0 0
param_named compressionSettings float4 90000.0 1.37331 90000.0 0.0
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}
}

//Directional light pass - run for each directional light that affects this
//renderable.
//
pass DirectionalLightPass
{
iteration once_per_light directional

// These base colors are ignored by the shaders but
// identify this non ambient pass
ambient 0 0 0
diffuse 1 1 1
specular 1 1 1 1

fog_override true none

scene_blend add

vertex_program_ref PLDecompressDirectionalVP2CG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto lightPosition light_position_object_space 0
param_named_auto lightDiffuse light_diffuse_colour 0
param_named matDiffuse float4 1 1 1 1
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

fragment_program_ref PLSplatDirectionalFP2CG
{
param_named splatScales float4 20 20 20 20
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

texture_unit
{
// coverage texture : rgba handling alpha for each splat
texture Coverage
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}
}

//Point light pass - run for each point light that affects this
//renderable.
//
pass PointLightPass
{
iteration once_per_light point

// These base colors are ignored by the shaders but
// identify this non ambient pass
ambient 0 0 0
diffuse 1 1 1
specular 1 1 1 1

fog_override true none

scene_blend add

//If you want high quality point light (per pixel for all calculations)
//change this to PLDecompressPointVP2HighCG and remove light position parameter below
vertex_program_ref PLDecompressPointVP2MedCG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto lightPosition light_position_object_space 0
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

//If you want high quality point light (per pixel for all calculations)
//change this to PLPointFP2HighCG and add light position parameter below
//param_named_auto lightPosition light_position_object_space 0
//
fragment_program_ref PLSplatPointFP2MedCG
{
param_named_auto lightDiffuse light_diffuse_colour 0
param_named_auto lightAttenuation light_attenuation 0
param_named matDiffuse float4 1 1 1 1
param_named splatScales float4 20 20 20 20
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

texture_unit
{
// coverage texture : rgba handling alpha for each splat
texture Coverage
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}

// Normalization cube map for speeding up
// normalization in the fragment program instead of using normalize()
texture_unit
{
cubic_texture nm.png combinedUVW
tex_coord_set 1
tex_address_mode clamp
}
}
}
technique
{
lod_index 1

//Ambient pass
//This is the first pass that runs before all other passes
//In fact, Ogre knows this is an ambient only pass because ambient is 1, 1, 1, 1
//and therefore all ambient passes on all materials first before continuing on to other passes
//This allows early z out by laying down the depth buffer so that the expensive pixel shaders don't have to attempt
//to render to pixels that are going to end up occluded

pass AmbientPass
{
// These base colors identify the pass to Ogre as an ambient only pass
// but are ignored by the shaders
ambient 1 1 1
emissive 0 0 0
diffuse 0 0 0
specular 0 0 0 0

// Ambient and emissive pass vertex program
vertex_program_ref PLDecompressAmbientVPCG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto globalAmbient ambient_light_colour
param_named matAmbient float4 1 1 1 1
param_named matEmissive float4 0 0 0 0
param_named compressionSettings float4 90000.0 1.37331 90000.0 0.0
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}
}

//Directional light pass - run for each directional light that affects this
//renderable.
//
pass DirectionalLightPass
{
iteration once_per_light directional

// These base colors are ignored by the shaders but
// identify this non ambient pass
ambient 0 0 0
diffuse 1 1 1
specular 1 1 1 1

fog_override true none

scene_blend add

vertex_program_ref PLDecompressDirectionalVP2CG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto lightPosition light_position_object_space 0
param_named_auto lightDiffuse light_diffuse_colour 0
param_named matDiffuse float4 1 1 1 1
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

fragment_program_ref PLDirectionalFP2CG
{
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

texture_unit
{
texture Base
}
}

//Point light pass - run for each point light that affects this
//renderable.
//
pass PointLightPass
{
iteration once_per_light point

// These base colors are ignored by the shaders but
// identify this non ambient pass
ambient 0 0 0
diffuse 1 1 1
specular 1 1 1 1

fog_override true none

scene_blend add

//If you want high quality point light (per pixel for all calculations)
//change this to PLDecompressPointVP2HighCG and remove light position parameter below
vertex_program_ref PLDecompressPointVP2MedCG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto lightPosition light_position_object_space 0
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

//If you want high quality point light (per pixel for all calculations)
//change this to PLPointFP2HighCG and add light position parameter below
//param_named_auto lightPosition light_position_object_space 0
//
fragment_program_ref PLPointFP2MedCG
{
param_named_auto lightDiffuse light_diffuse_colour 0
param_named_auto lightAttenuation light_attenuation 0
param_named matDiffuse float4 1 1 1 1
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

texture_unit
{
texture Base
}

// Normalization cube map for speeding up
// normalization in the fragment program instead of using normalize()
texture_unit
{
cubic_texture nm.png combinedUVW
tex_coord_set 1
tex_address_mode clamp
}
}
}
}

Falagard

19-10-2007 16:13:32

It's probably because there are multiple passes, each having a coverage texture. That might mess up with the latest version PLM2 (it was working at one time though).

I'd suggest trying to remove all passes except the ambient pass just for testing purposes and see if that fixes it.

bibiteinfo

19-10-2007 16:19:40

In that case, mNumTexture = 0 so it crash because there's no texture.


what I've tried :


material PLSplattingShaderLitDecompress
{
//doesn't matter what we put here for lod_distances, the paging landscape system uses the configuration setting in the terrain config file for material lod distances
lod_distances 1
technique
{
lod_index 0

//Ambient pass
//This is the first pass that runs before all other passes
//In fact, Ogre knows this is an ambient only pass because ambient is 1, 1, 1, 1
//and therefore all ambient passes on all materials first before continuing on to other passes
//This allows early z out by laying down the depth buffer so that the expensive pixel shaders don't have to attempt
//to render to pixels that are going to end up occluded

pass AmbientPass
{
// These base colors identify the pass to Ogre as an ambient only pass
// but are ignored by the shaders
ambient 1 1 1
emissive 0 0 0
diffuse 0 0 0
specular 0 0 0 0

// Ambient and emissive pass vertex program
vertex_program_ref PLDecompressAmbientVPCG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto globalAmbient ambient_light_colour
param_named matAmbient float4 1 1 1 1
param_named matEmissive float4 0 0 0 0
param_named compressionSettings float4 90000.0 1.37331 90000.0 0.0
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}
}
}
technique
{
lod_index 1

//Ambient pass
//This is the first pass that runs before all other passes
//In fact, Ogre knows this is an ambient only pass because ambient is 1, 1, 1, 1
//and therefore all ambient passes on all materials first before continuing on to other passes
//This allows early z out by laying down the depth buffer so that the expensive pixel shaders don't have to attempt
//to render to pixels that are going to end up occluded

pass AmbientPass
{
// These base colors identify the pass to Ogre as an ambient only pass
// but are ignored by the shaders
ambient 1 1 1
emissive 0 0 0
diffuse 0 0 0
specular 0 0 0 0

// Ambient and emissive pass vertex program
vertex_program_ref PLDecompressAmbientVPCG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto globalAmbient ambient_light_colour
param_named matAmbient float4 1 1 1 1
param_named matEmissive float4 0 0 0 0
param_named compressionSettings float4 90000.0 1.37331 90000.0 0.0
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}
}
}
}

Falagard

19-10-2007 18:24:31

Oops, what you want to test is removing the second LOD index where it uses "Base" and only have the directional light pass (so there's one coverage map).

Ambient should be ok left in.

bibiteinfo

19-10-2007 18:48:45

Thank you, removing LOD worked well.

final result :


PLSplattingShaderLitDecompress.material

material PLSplattingShaderLitDecompress
{
//doesn't matter what we put here for lod_distances, the paging landscape system uses the configuration setting in the terrain config file for material lod distances
//lod_distances 1
technique
{
//lod_index 0

//Ambient pass
//This is the first pass that runs before all other passes
//In fact, Ogre knows this is an ambient only pass because ambient is 1, 1, 1, 1
//and therefore all ambient passes on all materials first before continuing on to other passes
//This allows early z out by laying down the depth buffer so that the expensive pixel shaders don't have to attempt
//to render to pixels that are going to end up occluded

pass AmbientPass
{
// These base colors identify the pass to Ogre as an ambient only pass
// but are ignored by the shaders
ambient 1 1 1
emissive 0 0 0
diffuse 0 0 0
specular 0 0 0 0

// Ambient and emissive pass vertex program
vertex_program_ref PLDecompressAmbientVPCG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto globalAmbient ambient_light_colour
param_named matAmbient float4 1 1 1 1
param_named matEmissive float4 0 0 0 0
param_named compressionSettings float4 90000.0 1.37331 90000.0 0.0
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}
}

//Directional light pass - run for each directional light that affects this
//renderable.
//
pass DirectionalLightPass
{
iteration once_per_light directional

// These base colors are ignored by the shaders but
// identify this non ambient pass
ambient 0 0 0
diffuse 1 1 1
specular 1 1 1 1

fog_override true none

scene_blend add

vertex_program_ref PLDecompressDirectionalVP2CG
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto lightPosition light_position_object_space 0
param_named_auto lightDiffuse light_diffuse_colour 0
param_named matDiffuse float4 1 1 1 1
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

fragment_program_ref PLSplatDirectionalFP2CG
{
param_named splatScales float4 20 20 20 20
}

shadow_receiver_vertex_program_ref DecompressVertexShadowReceiver/VP
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto worldMatrix world_matrix
param_named_auto texViewProjMatrix texture_viewproj_matrix

// Config settings are;
// x scale
// y (height) start
// z scale
//
param_named compressionSettings float4 90000.0 1.37331 90000.0 50000.0
}

texture_unit
{
// coverage texture : rgba handling alpha for each splat
texture Coverage
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}

texture_unit
{
texture Splatting
}
}
}
}

Falagard

19-10-2007 19:48:01

While you're at it, you could add the ambient color to the directional lighting pass, remove the ambient pass altogether and change the iterate once per light to ... well whatever setting makes it just do it once.

That might take some investigation into shaders and Ogre's material script syntax but it would be well worth it.

Just add param_named_auto globalAmbient ambient_light_colour to the directional pass, add it to the directional light shader and as a value that's passed in, then set the color to the ambient before adding the lighting color to it. Also make sure that you change ambient 0 0 0 to ambient 1 1 1 in the pass, and obviously remove the ambient pass altogether like I mentioned at the start.

People were complaining about having a high ambient color looking like crap, and that will fix it (but also means you only get to have a single directional light affecting the terrain).

The alternative is to simply do the splatting additionally in the ambient pass - which will fix the problem people were having as well and allow additional lights. However, it looks like PLM has a problem with multiple light passes each using the "Coverage" texture and painting, so ... that will only work if you fix the problem that caused the crash you were looking at originally.