26 avril
BasicEffect: Lights / Part 1
BasicEffect is not that basic, if you take another look at it!
It has lots of properties and with addition of PerPixelLighting it's nice 'n' quick solution for rendering models.
This article was written to show you how just a few lines of code can make your render stand out..Of course as title suggest, we're going to stick to lighting, at least in this article..
So basicEffect.enableDefaultLighting() gives you standard lighting rig which, honestly, in lot of cases work just fine:
But what if you wanted to render a model at night, or scene with one source of light, what then? Using DirectionalLight would be ideal if you ask me, so why not try it..
basicEffect.DirectionalLight0.Enabled = true;
basicEffect.DirectionalLight0.Direction = new Vector3(0.2f, 0.0f, 0.5f);
basicEffect.DirectionalLight0.DiffuseColor = new Vector3(0.2f, 0.4f, 0.2f);
So after you've added these lines of code, which simply define diffuse color and light's source's direction..
As you can see it already looks much better, but for a final touch we're going to adjust specular power and color a bit.If you aren't sure what I'm talking about, Shawn's post might be good introduction to it
basicEffect.SpecularColor = new Vector3(0.5f, 0.5f, 0.5f);
basicEffect.SpecularPower = 8;
For the specular color I'm using a light white color, and I've set a specular power to 8..Something not to shiny and plastic, but not too flat either..
Not too much of a difference, but that's mostly because we have used white color both as a light's color as well as specular color..You can play around with values and see different results!