zturtleman / mm3d

Maverick Model 3D is a 3D model editor and animator for games.
https://clover.moe/mm3d
GNU General Public License v2.0
110 stars 22 forks source link

Material/light parameters are backward, should be swapped #173

Open m-7761 opened 2 years ago

m-7761 commented 2 years ago

MM3D has a lighting set up that makes no sense, it's especially bad in the texture view where lighting pretty much washes out completely so it's as if there's none.

I noticed that when a new material is made it has 20% ambient and 80% diffuse, which is not how materials work. It should be 100% on both, and the lighting should be 20/80.

I'm going to try to reverse this relationship and see if it still looks the same or not. I'm making this issue to have a URL to cite.

m-7761 commented 2 years ago

Here's the numbers with 100/100 default material. I recommend disabling GL_LIGHT_MODEL_AMBIENT to make things simpler, even though it might cause things to appear black in debugging. I had to use glLightModelfv with a pointer to zero it.

GL_LIGHT_0 (modelviewport.cc)

    GLfloat ambient[]  = { 0.2f, 0.2f, 0.2f, 1.0f }; //(0.8+0.2)*0.2
    GLfloat diffuse[]  = { 0.72f, 0.72f, 0.72f, 1.0f }; //0.9*0.8

GL_LIGHT_1 (modelviewport.cc)

    GLfloat ambient[]  = { 0.2f, 0.12f, 0.12f, 1.0f }; //(0.4+0.2)*0.2
    GLfloat diffuse[]  = { 0.72f, 0.4f, 0.4f, 1.0f }; //0.5*0.8 

The added 0.2 term is GL_LIGHT_MODEL_AMBIENT. Edited: Note it's important the lights don't sum to 100% so wire frames remain visible over polygons.

m-7761 commented 2 years ago

BTW this does look much better in texture mode, and the red face selection is visible (as long as the texture isn't red) for a change. I have to get used to seeing models darker with lighting, but it looks correct.

EDITED: In texwidget.cc the material preview uses 0.8 for ambient because it's compensating for GL_LIGHT_MODEL_AMBIENT which defaults to 0.2. I also felt that texture mode was a bit too dark because of the need for the solid mode to not overpower the wireframes (which is still a problem in texture mode for untextured materials, or very bright textures) so I had the modelviewport.cc code to add 0.1 ambient to GL_LIGHT_MODEL_AMBIENT. Not sure if that's best since it still leaves diffuse down around 90% but it looks alright for materials with high to 100% ambient. I'm thinking about adding a something to control the lights and background color. The bright background is too strong working with additive blending modes.