I’ve been experimenting with DrawMesh to try and get some performance improvements and I can’t understand why it’s not working properly.
My code almost works but the object doesn’t light properly. If I draw the object using the built in “mesh renderer” it renders fine. But when I use my code all the faces in the model which face the scenes main directional light, the sun, burn out to bright white. If I turn off the light (or move it or adjust it’s brightness to be very low or zero) the object looks perfect. As I turn down the lights intensity the burn out fades down right at the very end of the lights range. So it’s almost as if the object is getting lit many times by the same light but I can’t imagine why that would be?
Here is the code I use. It’s hard coded to only draw the church, 60 units north of the original object, and to display the material name because I thought maybe that was the problem. but the material seems to be correct:
void LateUpdate()
{
renderObjectManually();
}
void renderObjectManually()
{
if (name == "Church")
{
int layer = 0;
MeshFilter meshFilter= (MeshFilter)GetComponent(typeof(MeshFilter));
Matrix4x4 thisMatrix = new Matrix4x4();
thisMatrix.SetTRS(transform.position + new Vector3(60,0,0),transform.rotation,transform.localScale);
Debug.Log(renderer.material.name);
Graphics.DrawMesh (meshFilter.sharedMesh,thisMatrix,renderer.material,layer);
}
}
I’ve tried moving the code to Update(),and all the renderupdate calls but it doesn’t work there either. Am I doing something, or missing something, simple? Seems like it should work? ALl the objects in my scene render the same way, with bright white edges facing the sun, when I try to use this code.
Also, and I appologise because this is a bit of a nube question, how to I use the DrawMesh call to render objects which contain multiple materials?
regards,
Tony[/code]
further experiment shows that changing the shader from diffuse to vertex lit, stops the faces from burning out but it doesn’t appear to be lighting properly even then.
Anyone got any thoughts on this or have used DrawMesh succesfully in their code and are willing to share some tips?
regards,
Tony
Here is a screen grab showing the problem.
The church on the right is rendered in the normal way. The one on the left is rendered using the code I list above. Note how the one on the left has bright white faces where facing the sun but the one on the right doesn’t. If I dim or remove the sun light both meshes render the same.
Someone else must have seen this? Can anyone shed some light on the subject (pun intended
)
regards,
Tony
Can nobody help me with this? Surely someone must have used Graphics.DrawMesh() ? Just knowing whether it does or does not work for other people would help me.
still no replies… I feel so lonely and unloved.
Maybe if I shout?
HAS ANYONE USED THE GRAPHICS.DRAWMESH() FUNCTION? DID THEY GET IT TO WORK PROPERLY? BECAUSE IT DON’T WORK FOR ME…

could this be a problem with the material I am using? I got the material from the original renderer. Is that the right thing to do?
regards,
Tony
BTW I think I now know how to render objects made of different materials. Presumably I need to itterate through all teh submeshes getting the material to each and calling DrawMesh() with the submesh index set correctly…
I’ve had the same problem today, and found that it’s due to the matrix you supply being scaled.
This means the normals are being scaled and upsettin gthe lighting calculations
In my case it was the opposite… no lighting because my model needed shrinking. Is there an option to turn on Auto Normalise for Normals in unity shader stuff? Would be handy…
Elton
Wow thanks Elton 
I guess I can scale the models in the importer. Most of my models only appear at one scale in the game. although some of them are instanced at different scales to get a bit of variety and save on space. I’ll try this later.
I agree that there should be a way to stop the normals being scaled.
Thanks again for taking the time to provide feedback,
Regards,
tony Oakden
I’m still having a few issues with this. I’ve got meshes rendering and lighting correctly using Drawmesh but now I want some meshes to not be effected by shadows and not create shadows. How do I do this? All the references I can find in the manual refer to the functions in the MeshRender component for controlling shadows but drawmesh doesn’t use meshrenderer as far as I know? Currently the mesh it renders is making and using shadows by default. Presumably there is some way to change this but I don’t know how. Can anyone advise please?