Light on every model and not in the whole scene

Posted by alecnash on Game Development See other posts from Game Development or by alecnash
Published on 2012-10-18T10:17:47Z Indexed on 2012/10/18 11:15 UTC
Read the original article Hit count: 212

Filed under:
|
|

I am using a custom shader and try to pass the effect on my Models like that:

foreach (ModelMesh mesh in Model.Meshes)
{
       foreach (ModelMeshPart part in mesh.MeshParts)
       {
           part.Effect = effect;
       }
       mesh.Draw();
}

My only issue is that every Model now has its own light source in it. Why is this happening and is this a problem of my shader?


Edit:

These are the parameters passed to the shader:

      private void Get_lambertEffect()
            {
                if (_lambertEffect == null) _lambertEffect = Engine.LambertEffect;

                //Lambert technique (LambertWithShadows, LambertWithShadows2x2PCF, LambertWithShadows3x3PCF)
                _lambertEffect.CurrentTechnique = _lambertEffect.Techniques["LambertWithShadows3x3PCF"];
                _lambertEffect.Parameters["texelSize"].SetValue(Engine.ShadowMap.TexelSize);

                //ShadowMap parameters
                _lambertEffect.Parameters["lightViewProjection"].SetValue(Engine.ShadowMap.LightViewProjectionMatrix);
                _lambertEffect.Parameters["textureScaleBias"].SetValue(Engine.ShadowMap.TextureScaleBiasMatrix);
                _lambertEffect.Parameters["depthBias"].SetValue(Engine.ShadowMap.DepthBias);
                _lambertEffect.Parameters["shadowMap"].SetValue(Engine.ShadowMap.ShadowMapTexture);

                //Camera view and projection parameters
                _lambertEffect.Parameters["view"].SetValue(Engine._camera.ViewMatrix);
                _lambertEffect.Parameters["projection"].SetValue(Engine._camera.ProjectionMatrix);
                _lambertEffect.Parameters["world"].SetValue(
                Matrix.CreateScale(Size) *
                world
            );
                //Light and color
                _lambertEffect.Parameters["lightDir"].SetValue(Engine._sourceLight.Direction);
                _lambertEffect.Parameters["lightColor"].SetValue(Engine._sourceLight.Color);
                _lambertEffect.Parameters["materialAmbient"].SetValue(Engine.Material.Ambient);
                _lambertEffect.Parameters["materialDiffuse"].SetValue(Engine.Material.Diffuse);
                _lambertEffect.Parameters["colorMap"].SetValue(ColorTexture.Create(Engine.GraphicsDevice, Color.Red));

            }

© Game Development or respective owner

Related posts about XNA

Related posts about models