Troubleshooting this TutorialSometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with the tutorial on the diffuse lighting shader. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used. If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it. If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more. |
Common MistakesNone listed yet… |
Frequently Asked QuestionsNone listed yet… |
What is the reason for multiplying input.Normal * WorldInverseTranspose?
if you comment out that line and replace it with:
float4 normal = input.Normal;
everything still works fine. I'm sure there is some more advanced reason why this will be important down the road, but I'm having trouble understanding its purpose at this time.
Thanks!
If your world matrix is an identity matrix (which will be the case if you are keeping your object unrotated, unscaled, and untranslated/unmoved), the inverse of that will still be an identity matrix, and the transpose of that will also still be an identity matrix.
So taking out that line shouldn't make a change, in the specific case of having your object essentially unmoved from the start point. Once you move your object, the world matrix won't be an identity any more, and neither will the world-inverse-transpose matrix, so things will be different in that case. That's the reason we need this particular line of code.
Honestly, though, that's a great question. Thanks for asking it!
I think the reason is that when comparing input.Normal and DiffuseLightDirection (through the dot product), both need to be set in the same coordinate ‘base’; since DiffuseLightDirection is given as an absolute while input.Normal is relative to its vertex, you need to compute an absolute version of input.Normal, and that is what normal is: you can see WorldInverseTranspose as the ‘detransforming’ operation.
I just realized that when i scale model up it is drawing dimmer than normal. You know what may be the cause of this?
Regards
Hi there!
Great tutorial you've done. ^^ Anyway, I too have a little problem with the shader. when I draw the helicopter plus the beachball, both models get a little bit transparent…
Here is my code for the drawing:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
DrawModelWithEffect(helicopter, Matrix.CreateScale(2));
DrawModelWithEffect(beachBall, Matrix.CreateTranslation(new Vector3(5, 5, -10)));
base.Draw(gameTime);
}
private void DrawModelWithEffect(Model model, Matrix transformation)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (ModelMeshPart part in mesh.MeshParts)
{
part.Effect = effect;
effect.Parameters["wvp"].SetValue(world * mesh.ParentBone.Transform * transformation * camera.viewMatrix * projection);
effect.Parameters["wit"].SetValue(Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world)));
}
mesh.Draw();
}
}
Regards
Post preview:
Close preview