Lighting with BasicEffect seems way overexposed

Windows 10, DirectX, Visual Studio 2015, release Monogame 3.5 installer (from http://www.monogame.net/downloads/ not nuget or github.)

I’ve been trying to light my 3D geometry with the BasicEffect.
However, all the geometry has washed out to white.
Only when I set the DiffuseColor value to Vector3(0.01,0.01,0.01) or less do I get a reasonable amount of lighting.
I am turning off vertex colors, and using two directional lights and a scene ambient light color.

The setup looks like this:

        fx.Alpha = 255;
        fx.AmbientLightColor = CalcAmbientColor();
        fx.DiffuseColor = new Vector3(0.01f, 0.01f, 0.01f);
        fx.DirectionalLight0.Enabled = true;
        fx.DirectionalLight0.DiffuseColor = sunlight.ToVector3();
        fx.DirectionalLight0.Direction = -sunPosition;
        fx.DirectionalLight0.SpecularColor = sunlight.ToVector3();
        fx.DirectionalLight1.Enabled = true;
        fx.DirectionalLight1.DiffuseColor = skylight.ToVector3();
        fx.DirectionalLight1.Direction = new Vector3(0, -1, 0);
        fx.DirectionalLight1.SpecularColor = new Vector3(0, 0, 0);
        fx.DirectionalLight2.Enabled = false;
        fx.DirectionalLight2.DiffuseColor = new Vector3(0, 0, 0);
        fx.DirectionalLight2.Direction = new Vector3(0, 1, 0);
        fx.DirectionalLight2.SpecularColor = new Vector3(0, 0, 0);
        fx.EmissiveColor = new Vector3(0, 0, 0);
        fx.FogColor = fogColor.ToVector3();
        fx.FogEnabled = true;
        fx.FogStart = fogDistance * 0.1f;
        fx.FogEnd = fogDistance;
        fx.LightingEnabled = true;
        fx.PreferPerPixelLighting = true;
        fx.SpecularColor = new Vector3(0.005f, 0.005f, 0.005f);
        fx.SpecularPower = 40.0f;
        fx.TextureEnabled = true;
        fx.Texture = someTexture;
        fx.VertexColorEnabled = false;

The value of sunlight is in the 0.8f range, and the value of skylight is in the 0.2f range.
The texture is a beige cracked-stone texture.

        sunlight = new Color(new Vector3(0.85f, 0.8f, 0.7f));
        skylight = new Color(new Vector3(0.1f, 0.15f, 0.25f));
        sunPosition = new Vector3(1, 1, -3);
        sunPosition.Normalize();
        fogColor = Color.CornflowerBlue;
        fogDistance = 1000.0f;

CalcAmbientColor() returns a color value in the 0.2 range as well.

I’ve tried debugging the shader in Visual Studio Graphics Tools, but the way the shader is built for the installer does not include debug info and thus I can only step through the assembly. I can see it takes the SM4 path, not the DX9 path; that’s about it. (Well, and the sampler value of the texture looks OK)

It feels approximatly like there is an erroneous multiplication by 255 somewhere in the treatment of the diffusecolor and specularcolor material values?
What should I do to fix this? Is this a known bug? A patch/later release?

Was going to ask, if you have tried to set “DebugMode” to “Debug” for your shader in MonoGame Pipeline Tool… But then I realised you use the BasicEffect.

Sounds like a math or logic issue (forgot to divide by 255), or inconsistent expression schemes… You know, like when you are expressing colors as 0 to 255, and then suddenly a float value of 1 slips in, and you get something almost black though it was intended full-on white…

Yes, I agree! And I tracked it down to where it seems like it’s not my code, but instead somewhere in BasicEffect.

Combine this with the “importing a box in FBX gives no geometry” bug I just ran into, and I wonder if anyone is using this? Like, at all?

Are you using blender? There are a couple of threads on the forum about wrong import of blender-exported fbx models. What is the problem exactly?

I’ve used BasicEffect without running into this issue.

Oh yeah, I remember this! I had (what I remember as) the exact issue you speak of. It had to do with export settings in blender, even with the same file extensions, default export settings created files monogame couldn’t use.

On a side note, I’m pretty sure I’ve seen the same kind of thing with certain mp3 files, maybe a wrong bit-rate or something.

Anyone who finds this via google, the one thing missed in the original discussion was that BasicEffect.Alpha is a float between 0 and 1

The original poster set Alpha to 255 which was the base cause of the problem

2 Likes