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 using the BasicEffect class to do lighting. 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… |
No problems, just wanted to say what a fantastic job you've done with these tutorials. I come from a Flash to Silverlight to WPF to now XNA background, and you're tutorials are awesome. Very well written. Wish I would have found them 4 weeks ago, but reading them all as an "overview summary" and still finding things I've missed. Hope your Masters stuff works out great for you. Thanks for all this work, man. Much appreciated by everyone who uses it, I'm sure!
Thanks for the feedback Rick! It's always nice to know people are finding it useful!
Hi! Your tutorials are great, well detailed and explained.
Unfortunately, it doesn't work properly. When I use the command:
"effect.EnableDefaultLighting();"
My model is drawn as totally black. Even if I set DiffuseColor, it is still black.
Without that row, it is drawn well, with texture too, but I need to have some light too.
Can anyone explain how to resolve this problem?
Many thanks,
Benedek
I had the same problem for the ship2.x model (in tutorial ‘3 - Picking’ from series ‘5 - Input Tutorials’), and I have found a small workaround on this page (remove spaces):
community.monogame . net/t/black-textures-on-models/6836/2
It would still be nice to understand how EnableDefaultLighting works exactly and why it results in this, but the documentation does not seem to give many details about it.
PS: it turns out that you do not even need to set effect.AmbientLightColor, simply removing/disabling the EnableDefaultLighting instruction is enough.
PPS: having found out today (30/01/2022) what happens in a very similar case (when drawing with 3D primitives) and looking at whether someone addressed this in some comment, I stumble back here and can now provide a possible explanation!
The model has probably absent or incorrect normal vectors information, which is used by many lighting effects (as you can see if you delve into the ‘Effects and HLSL Tutorials’ here), except for ambient lighting.
This is why you can set some ambient color anyway if you wish so, but not anything more.
By the way, an important point when using 3D primitives instead of 3D models (which is my case and had me scratching my head for several days) is that you can set the normal vectors using the VertexPositionNormalTexture class. (There does not seem to be a VertexPositionNormalColor class nor VertexPositionNormal, strangely.)
Hello,
I applied tutorial ‘3 - Picking’ from series ‘5 - Input Tutorials’, reusing the code from the 3D tutorials; in particular, I had both the upward-moving small ship with lighting effects and the motionless small ship, with the same model.
It turned out that, although I used two different versions of DrawModel to draw them, both had the lighting effects applied to them; nevertheless, they were positioned correctly. This suggests that although the World, View and Projection properties are local to meshes, at least some lighting properties may be persistent/global/static!
Is my interpretation correct? If it is, do you have to reassign effect values each time you draw several copies of the same model with differing lightings, or is there any other more optimised way?
Thanks in advance to anyone that would have an idea about it.
PS: I have just conducted some tests, and I think it is sufficient to just turn off LightingEnabled and FogEnabled, instead of having to reset more values! :) Thus, in my DrawModelPicking method:
Post preview:
Close preview