我正在製作遊戲,受到卡坦移民的啓發。 (www.facebook.com/Expanze) 我正在優化我的代碼,呈現相同模型的數百個實例。XNA 4.0共享基本效果變量?
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.Alpha = 1.0f;
effect.LightingEnabled = true;
effect.DirectionalLight0.Direction = GameState.LightDirection;
effect.DirectionalLight0.DiffuseColor = GameState.LightDiffusionColor;
effect.DirectionalLight0.SpecularColor = GameState.LightSpecularColor;
effect.DirectionalLight0.Enabled = true;
effect.View = GameState.view;
effect.Projection = GameState.projection;
for (int loop1 = 0; loop1 < validItems; loop1++)
{
if (instance[loop1].Visible)
{
instance[loop1].UpdateEffect(effect, meshNumber);
effect.World = transforms[mesh.ParentBone.Index] * instance[loop1].World;
mesh.Draw();
if(loop1 > 4)
break;
}
}
}
meshNumber++;
}
在: instance[loop1].UpdateEffect(effect, meshNumber);
我改變環境色:effect.AmbientLightColor = playerAmbientLightColor;
我的問題是,改變顏色的影響應已繪製早期實例的顏色。
兩個圖像,一個具有如(LOOP1> 4)斷裂,所述第二無這些2行: http://i.imgur.com/DxSKA.jpg
它真的只有靈感 - 遊戲機制真的不同 – user1671710
然而,你是對的問題。我通過爲每個實例更改所有3種淺色(環境,漫反射)來解決它。在此之前,我在某些情況下只改變環境顏色。 – user1671710