Default material properties and lighting

Started by
3 comments, last by Hodgman 10 years, 11 months ago

I am using assimp to import 3d models and I have a question on the default properties on materials, more specifically on the diffuse, ambient and specular material colors.

In assimp, if the model does not define any diffuse, ambient or specular colors, it defaults to black (vec3(0.0)) as specified by http://assimp.sourceforge.net/lib_html/materials.html

However as I understand it the typical lighting equation for each light is something like:


// for each light...
accumulatedLighting += ((material.ambientColor * light.ambientColor) +
(material.diffuseColor * light.diffuseColor * attenuation) +
(material.specularColor * light.specularColor * attenuation));

// final color output
finalColor = diffuseTexture * accumulatedLighting;

 

Now if for example one of material properties is null, the light property won't matter. So it brings me to the question - what should be the default values of material diffuse/ambient/specular colors be since assimp defaults to vec3(0.0)?

(I'm using opengl 3.3+, assimp 3.0, per-pixel lighting)

Advertisement
Well, yes, you are supposed to give sensible material properties to your materials, otherwise objects won't look right. For a green table, make the material.diffuseColor green. The ambientColor should be left white, imho, it's an "ambient" lighting and as such doesn't really have a preference in material color. As for specularColor, it's generally left white as I understand it as specular highlights do not generally depend much on the object's color but are dominated by the light's color.

I suppose "default" as in most reasonable would then be:
ambientColor = vec3(1)
diffuseColor = your material's diffuse color
specularColor = vec3(1)

But if you don't specify any material information at all there is really no "default" value. The values are supposed to be set according to the effect you want to achieve. A model without any material information is obviously not meant to be displayed on its own. Basically, I think the vec(0.0) defaulting done by assimp isn't a "sensible default" that you are to rely on, but more of a "I need to put something in this variable and I'm not given anything, so make it zero" kind of deal.

But if you must, I think vec(1.0) would make for a meaningful "default" value, in that the material would then not contribute anything to lighting. Dunno how useful that really is, though. As I said, assimp/opengl can't guess how you want your model to appear on screen, that's what material settings are for.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Sincerely? You're not supposed to use AssImp material properties. You're supposed to use material names to map a specific shader.

Previously "Krohm"

I did some digging around för example use, and I found this http://assimp.svn.sourceforge.net/viewvc/assimp/trunk/samples/SimpleOpenGL/Sample_SimpleOpenGL.c?revision=1347&view=markup which has a material parsing method like I was looking for, yet from what i gather you say thats not how you should assimp - do you have an example on how to use it properly?

Thanks

accumulatedLighting += ((material.ambientColor * light.ambientColor) +
(material.diffuseColor * light.diffuseColor * attenuation) +
(material.specularColor * light.specularColor * attenuation));

This is just one way to do lighting, and it's not particularly a way that reflects how the real world works. Just because this is a common generic model that's used by default in a lot of places, it doesn't mean your game has to work the same way.

Diffuse lighting is refracted and re-emitted light. Specular light is reflected light. Ambient light is a complete hack to compensate for the fact that you're only accounting for direct lighting, and not indirect reflections. It doesn't make any sense for a light to be both a direct light and an ambient light, your "lights" should probably be one or the other. It also doesn't make sense for a light to have one colour that's used for reflection and a different colour for refraction; that's impossible in the real world (only a material should have those properties, while a light should just have a colour and intensity).
In the real world, most materials have a "diffuse color" (albedo) of between 5% and 60%, and a "specular colour" (a property dependent on it's index-of-refraction) of around 4%. Ambient lighting is not a physical property, so in the real world you'd still just use the above two properties for ambient light ;)

This topic is closed to new replies.

Advertisement