I created an effect and just want to use lightning but in default effect that XNA create we should do texture mapping or the model appears 'RED', because of this lines of code in the effect file:
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float4 output = float4(1,0,0,1);
return output;
}
If I want to see my model, I must do texture mapping by UV coordinates. But my model does not have UV coordinates assigned or its UV coordinates are not exported.
I do texture mapping by this line of code in vertexshaderfunction
:
output.UV= input.UV
When I use BasicEffect I have no problem and model appears correctly.
How can I use "just" lightings in my custom effects?
here is inside of my Model Using BasicEffect
This is my code for drawing with or without BasicEffect inside of my draw() method:
Matrix baseWorld = Matrix.CreateScale(Scale) * Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z)
* Matrix.CreateTranslation(Position);
foreach(ModelMesh mesh in Model.Meshes)
{
Matrix localWorld = ModelTransforms[mesh.ParentBone.Index] * baseWorld;
foreach(ModelMeshPart part in mesh.MeshParts)
{
Effect effect = part.Effect;
if (effect is BasicEffect)
{
((BasicEffect)effect).World = localWorld;
((BasicEffect)effect).View = View;
((BasicEffect)effect).Projection = Projection;
((BasicEffect)effect).EnableDefaultLighting();
}
else
{
setEffectParameter(effect, "World", localWorld);
setEffectParameter(effect, "View", View);
setEffectParameter(effect, "Projection", Projection);
setEffectParameter(effect, "CameraPosition", CameraPosition);
}
}
mesh.Draw();
}
setEffectParameter is another method that sets effect parameter if i use my custom effect.