Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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));

            }

Image:

enter image description here

share|improve this question
    
By "own light source" do you mean, that each model is illuminated by a different light source and you only want one light source in the scene? Need to see your shader... –  Ken Oct 18 '12 at 10:31
    
That's exactly what I mean. The shader was working fine when I was working with primitives but now that I switched to Models I am having this issue. I'll take a look at it. –  alecnash Oct 18 '12 at 10:36
    
maybe we could have a look at the parameters passed to the shader –  Ken Oct 18 '12 at 10:54
    
Just uploaded them –  alecnash Oct 18 '12 at 11:00
    
Can you post a screenshot of what this looks like? I can't figure out what you mean by "each model has its own light source" –  melak47 Oct 18 '12 at 13:21
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.