Mesh Lighting and Shadows (AccessViolationException)

bvagis

27-08-2010 16:11:16

I am creating a mesh of a terrain and trying to get shadows to appropriately show up on it. I have thus far had little success. My mesh is quite large, over 100,000 vertices. I am not sure If I am doing it correctly, because shadows do not seem to show up correctly, if at all.

I am first creating a ManualObject out of my pre-triangulated ground data, then converting it to a MeshPtr and setting the CastShadows attribute to true.

int counter = 0;
foreach (var subTriangleArray in subTriangles)
{
name = subCloud.Name;
name = name.Replace("PointCloud_", "Mesh_" + (counter++) + "_");
manualObject = m_SceneManager.CreateManualObject(name);
manualObject.Begin("ReferenceData", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
ushort j = 0;
foreach (Triangle triangle in subTriangleArray)
{
if (j + 3 > ushort.MaxValue)
{
break;
}

foreach (int vertex in triangle.vertecies)
{
ColorPosition cp = subCloud.ColorPositions[tPoints[vertex].nVertexID];
manualObject.Position(cp.Position);
manualObject.Colour(cp.Colour);
manualObject.Index(j++);
}
}
manualObject.End();

if (tPoints.Length < 3)
{
return;
}

MeshPtr mesh = manualObject.ConvertToMesh(name);
name = mesh.Name.Replace("Mesh_", "Entity_");
Entity entity = m_SceneManager.CreateEntity(name, mesh.Name);
entity.CastShadows = true;
m_Meshes.Add(name);
m_MeshNode.AttachObject(entity);
}


The mesh shows up fine, but the shadows do not show up correctly. Moving the camera around will cause the program to crash with an AccessViolation exception. Is there something wrong with my indexing? Is there something special that should be in my material? Maybe I just have too many points in my mesh?

Here is my material:
material ReferenceData
{
technique
{
pass
{
scene_blend alpha_blend
diffuse vertexcolour
specular vertexcolour
ambient vertexcolour
}
}
}


Any tips would be appreciated!

AndroidAdam

27-08-2010 22:25:16

While I'm sure someone would be able to help you here, I recommend posting the problem on the actual OGRE forums. You'll get more and faster responses there. They'll be fine with you posting C#, although they might give their own snippets in C++

Beauty

17-09-2010 10:47:39

I also had exceptions when I used shadows in my main application.
Interesting to know that the problem is still not fixed.
There is an old discussion about in this thread, but as far as I remember there was no solution.
My personal problems I posted in this post of the same thread.

Good would be "deep" debugging, which also debuggs the unmanages Ogre C++ code.
But I never tried and my C++ knowledge is bad.
Also there is the problem, that it's difficult to reproduce the crash at a specific time. So you can't debug line by line until the crash happens.
Maybe there is a little chance for reproducing:
The problems never happened when the mesh was not visible by the aperture angle of the camera. There was not always a crash when the mesh was displayed. It seems so that the crashes happenes in specific constellations (positon, orientation) of the camera and mesh. If you can find such a constellation, which immediately throws the exception at the next RenderOneFrame(), then it would be a good starting point for "deep" debugging.

If you find out such a constellation, maybe you can puplish a "crash demonstrator" application, where the crash happens directly after application start. Then also somebody else could try to debug it. (We have some people with very good technical knowledge.)


If you start a discussion about this bug in the Ogre main forum, please give us a link.