Hi There,
I’m having some trouble figuring out how to apply a color to an object without the color preventing shading from occuring.
Currently I use a material like this:
Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat.setBoolean(“UseMaterialColors”, true);
mat.setColor(“Diffuse”, color);
mat.setColor(“Ambient”, color);
mat.setColor(“Specular”, color);
Which gives result to:
http://voxyforest.files.wordpress.com/2011/12/flat-shaded-chickens-21.png
But if I remove the line:
mat.setBoolean(“UseMaterialColors”, true);
I get something like this: (which is what I want - notice the shading)
http://voxyforest.files.wordpress.com/2011/12/shaded-chickens1.png
Anyone know how I can have both colors and shading at the same time? Using a material works, but I don’t want to save a lot of colors manually to use.
I’ve been trying to figure it out for the past few days now, so any help would be very much appreciated!
Cheers,
Dengke
You set your ambient color to the same as your diffuse. This is like making the object 100% lit everywhere… ie: you are throwing away any shading.
Ambient = color of the object where there is no light.
Diffuse = color of the object where there is light.
Hi pspeed,
Thanks a lot for your help, I toned down the intensity of the color for ambient light by a factor of 6 on each RGB and it’s looking great now.
I just wanted to ask for future reference, if the ambient material property shows color where there’s no light, is there any interaction of the ambient material property with the ambient light that I set for the scene?
For the specular component, is there anything I should take care about when setting it so that when specular reflection is enabled for a particular object, that it will be seen?
Thanks for your help once again,
Dengke
Regarding the mixing of ambient light and ambient material colors, I’m not sure. I actually haven’t looked at a recent version of Lighting.j3md in a long time as I forked my own off long ago. And my lighting is done kind of weird for Mythruna so I’m not a good source of knowledge.
Usually, I would leave diffuse as a medium tone and let lighting light the material. Real colors should come from the mesh anyway for most cases. Then specular would be set really bright (like white) and show as highlights depending on the shininess setting. I don’t really use specular at the moment so I have no direct experience.
Though in your case, if your meshes are “boxes” (though I hope you are at least batching them) then a diffuse color on the material is ok… though you end up with at least one material per color and that limits your ability to batch. It’s a trade off between that and including colors in the mesh and incurring that extra 4 floats per vertex.
That’s some useful things you mentioned there. About the batching, I haven’t been doing anything like that yet so displaying just five chickens reduces my frame rate down to 36 on my quad core with ATI Radeon HD 5650. When you say batching do you mean creating just one material to be used for each block? Or is it something else I can do? I’m keen to apply any optimization I can to speed the frame rate up. I’m also considering removing boxes that can’t be seen and possibly collapsing adjacent triangles on the same face (although I’m not sure I’d go about the second optimization). Any pro tips you can give me?
By the way I had a look at your project Mythruna that you mentioned. It just looks fantastic. I love how its not just all blocky. I believe I will be following its progress on facebook
Btw if I did choose to specify vertex colors with the 4 floats per vertex, would the shading be shown? I was hesitant to take that route because the example https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes seems to make it look like no shading occurs (but now that I think about it, it’s probably not possible to tell because all the meshes used in the example have the same normals…)
Vertex colors are treated pretty much just like texture colors, so yeah… they will be “lit”.
Batching = combining multiple meshes into one larger mesh. When each block is a separate object you kill GPU dispatch because every one of those objects had to be drawn separately. Also, I don’t know how you are drawing your chickens but if it’s really just hundreds of blocks then you are also drawing a bunch of faces that are inside the chicken. For proper performance, only draw the surfaces that are exposed and batch them into one shape… at least one per chicken if you can use the same material.
Batching the meshes will reduce your object count significantly. Eliminating the fully hidden sides will probably cut your polygon count in half or more depending on the size of the object.
@dengkesha said:
By the way I had a look at your project Mythruna that you mentioned. It just looks fantastic. I love how its not just all blocky. I believe I will be following its progress on facebook :)
Thanks! :)
Thanks for all that useful information. I’m going to get on to batching right away.
Cheers!