In D3D i can specify a flat lighting model (rather than gouraud), this mean si can check out the look of a flat shaded verison of models without having to mess with the normals. Is there an equivalent way to do this in Unity/shaderlab? Or do I have to split all my trianlges up so as not to share vertexes and assign them all their own (3 equal) normals?
hmm, im not sure you understand what im after.
I still need lighting. but i need a flat shading model, not an interpolated one.
ie every triangle is rendered with a single face normal for the light calculation.
I read that you suggest to use 'the import settings"?
Where can I set the import into Unity 3
I import assets from 3DS and Maya but I never found any settings for import ?
What did I miss here?
Thanks to lighten this to me and maybe others
Yves
SORRY I realize that the Editor is the importer settings…
Got it
yves
Then just don’t share vertices between faces that you want separated, as you suggested. You can of course share vertices across the triangles that you want to all have the same normal.
Ah ok then,
I just thought there might be a built in option to do it like there is in D3D.
Seems pretty inefficient to have to increase the Vertex Buffers when essentially every 3 normals is the same.
Hi Farfarer,
thank you for your reply. But I won’t be better of without flat shading.
I am doing some procedural vertex animation and my meshes hit the 65k Vertices limit. And I need flat normals for my artstyle.
Being able to get the normals by the provoking vertex would reduce my vertexcount almost by a factor of 3.
In normal HLSL Code you could just say “shademode = Flat;” and you will be good. But in unity I have yet to find that option.
Any ideas?
You are right, there should be that option in Unity, for style reasons and control over the appearence. It’s totally a missing feature from Unity, that people ask about, that i have looked for, and that is inconvenient. It should be possible by shader. I don’t believe that you can even get position of the 3 triangles of every vertex withing the shader, unless you are using a dx11 geometry shader, so you can’t even do it with advanced CG code unless using the geometry shader.
So yes, perhaps make a suggestion to Unity?
If your vertices are already 65k then you can’t duplicate them. obviously you have a setting that says make new mesh every 65k. you’d have to set that to 21k and duplicate them.
Using DX11, i think its possible with a geometry shader, and vertex positions, someone else would know, i dont really! Do you have to take the 3 vertices, make new normals for them, and pass the normals on to the color function with ambient lighting info, does the geometry shader arrive prior to the lighting options?
if they were less numerous, obviously you could write something like the following code and add it to wherever you have flat shading:
this code was inteded for only planes, which had normals generated afterwards. i dont know if it works forother things. i just added a line for normals just now. chances are that you can make 21k meshes, slap this code on them and they will become flat ones.
//---the following mesh code is an optional stylisation code
//---to make mesh force "flat shading"(flat retro shadows)....
var mesh : Mesh = pl.GetComponent(MeshFilter).mesh;
var myvertices : Vector3[]= mesh.vertices;
var mytriangles : int[] = mesh.triangles;
var mynormals : Vector3[]= new Vector3[mytriangles.Length];
var newvertices = new Vector3[mytriangles.Length];
var newUVs = new Vector2[mytriangles.Length];
for (var TR:int = 0; TR < mytriangles.length ; TR ++){
newvertices[TR] = myvertices[mytriangles[TR]];
mynormals[TR] = mesh.normals[mytriangles[TR]];
mytriangles[TR] = TR;
// sry i didnt reweite the UV's like for you, it should be possible to copy each uv from old vertex same as the nromals/
}
mesh.vertices = newvertices;
mesh.triangles = mytriangles;
mesh.normals = mynormals;
mesh.uv = newUVs;