BECK Games


This might seem silly but here goes..

is there a way to set the default lighting for all objects

This is what im doing now..(taken after spacewars)

Matrix m_view = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
Matrix m_proj = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 20000.0f);

for (int i = 1; i < MAX_MODELS; i++)
{
foreach (ModelMesh mesh in EnemyIdea.C_Model_m.Meshes)
{
//This is where the mesh orientation is set, as well as our camera and projection
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
//effect.LightingEnabled = false;
effect.World = EnemyIdea.C_Actor_m;
effect.View = m_view;
effect.Projection = m_proj;
}
//Draw the mesh, will use the effects set above.
mesh.Draw();
}
}


When i do this my Frame rate takes a big hit... I narrowed the problem down to the line of code effect.EnableDefaultLighting();....... Its not so much the lighting, because if i shut the lighting off after this call i still get a crazy slow FPS. Is there anyway i can just EnableDefault lighting through out my game... so its not enableing it for every effect in every mesh of every model

Thanks,
-Wes


Re: Global lighting

parlance


As I understand it, the BasicEffect class mimics the functionality of a vertex and pixel 1.1 shader without the use of the fixed function pipeline. What this really means any changes to the shader beyond what could changed through shader parameters without the support of static or dynamic flow control would require a regeneration and recompilation of the shader itself, which is definately not something you would want to be doing in an internal rendering loop.

I would advise moving your code to enable default lighting for each effect to where the effects are created or loaded. The default lighting effect should persist with that BasicEffect instance so there is no need to re-enable it every time you refresh the screen.





Re: Global lighting

BECK Games

aaaahhh yes... thanks parlance... that definitly made a big difference.