Hello,
So I'm trying to create a lighting system on my XNA game, and I found a great shader on the internet:
But the problem is that my models have multiple textures, and this shader accept only one texture, so my models are finally drawn with one model on all their meshes.
Here's how I apply the effect on my model:
public void SetModelEffect(Effect effect, bool CopyEffect)
{
foreach (ModelMesh mesh in _model.Meshes)
foreach (ModelMeshPart part in mesh.MeshParts)
{
Effect toSet = effect;
// Copy the effect if necessary
if (CopyEffect)
toSet = effect.Clone();
MeshTag tag = ((MeshTag)part.Tag);
// If this ModelMeshPart has a texture, set it to the effect
if (tag.Texture != null)
{
setEffectParameter(toSet, "BasicTexture", tag.Texture);
setEffectParameter(toSet, "TextureEnabled", true);
}
else
setEffectParameter(toSet, "TextureEnabled", false);
// Set our remaining parameters to the effect
setEffectParameter(toSet, "DiffuseColor", tag.Color);
setEffectParameter(toSet, "SpecularPower", tag.SpecularPower);
part.Effect = toSet;
}
}
And here is how I draw my models with all their textures when the effect is not applied:
foreach (ModelMesh mesh in _model.Meshes)
{
Matrix localWorld = _modelTransforms[mesh.ParentBone.Index] * world;
foreach (ModelMeshPart meshPart in mesh.MeshParts)
{
Effect effect = meshPart.Effect;
if (effect is BasicEffect)
{
BasicEffect bEffect = (BasicEffect)effect;
bEffect.Texture = _textures[newName];
bEffect.World = localWorld;
bEffect.View = view;
bEffect.Projection = projection;
...
So what I thought to do is, I send on SetModelEffect all my model textures to the shader which will be stored in a texture array, and then in the shader I just do a loop through all the textures and apply the light effect. But I don't know how to do that.
I'm quite a newbie with shaders so tell me if my idea is bad...
Thank you!