Is it possible to obtain a flat shader in Unity to gain some results like these:
Note: I would like to use this on my terrain and making it in a 3D program isn’t an option.
Is it possible to obtain a flat shader in Unity to gain some results like these:
Note: I would like to use this on my terrain and making it in a 3D program isn’t an option.
Here is an editor script that takes any game objects and produces a clone game object where the mesh does not share vertices. Create a C# script in the Assets/Editor folder named NoSharedVertices. Insert the following script. Then select the object you want to process and select ‘No Shared Vertices’ from the Window menu:
using UnityEngine;
using UnityEditor;
public class NoSharedVertices : EditorWindow {
private string error = "";
[MenuItem("Window/No Shared Vertices")]
public static void ShowWindow() {
EditorWindow.GetWindow(typeof(NoSharedVertices));
}
void OnGUI() {
//Transform curr = Selection.activeTransform;
GUILayout.Label ("Creates a clone of the game object where the triangles
" +
“do not share vertices”);
GUILayout.Space(20);
if (GUILayout.Button ("Process")) {
error = "";
NoShared();
}
GUILayout.Space(20);
GUILayout.Label(error);
}
void NoShared() {
Transform curr = Selection.activeTransform;
if (curr == null) {
error = "No appropriate object selected.";
Debug.Log (error);
return;
}
MeshFilter mf;
mf = curr.GetComponent<MeshFilter>();
if (mf == null || mf.sharedMesh == null) {
error = "No mesh on the selected object";
Debug.Log (error);
return;
}
// Create the duplicate game object
GameObject go = Instantiate (curr.gameObject) as GameObject;
mf = go.GetComponent<MeshFilter>();
Mesh mesh = Instantiate (mf.sharedMesh) as Mesh;
mf.sharedMesh = mesh;
Selection.activeObject = go.transform;
//Process the triangles
Vector3[] oldVerts = mesh.vertices;
int[] triangles = mesh.triangles;
Vector3[] vertices = new Vector3[triangles.Length];
for (int i = 0; i < triangles.Length; i++) {
vertices _= oldVerts[triangles*];*_
_ triangles = i;
* }
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateBounds();
mesh.RecalculateNormals();*_
* // Save a copy to disk*
* string name = “Assets/Editor/”+go.name+Random.Range (0, int.MaxValue).ToString()+“.asset”;*
* AssetDatabase.CreateAsset(mf.sharedMesh, name);*
AssetDatabase.SaveAssets();
* }*
}
Before and after using the built-in sphere and a directional light:
[33009-noshared.png|33009]
The look you are talking about is not just a shader trick. You actually have to create/process the mesh properly to get that look.
I would check out Polyworld: http://forum.unity3d.com/threads/polyworld-for-unity.239365/
It has a built in mesh processing tool to get that sort of look out of your exiting meshes and you can process terrain with it also.
First of all I know this post is old, but I might have found a better solution.
It is possible to do this with a shader, which will give (usually) better framerates and will also make it possible to create bigger models (Vertex limit: 65000)
Big credits to whomever wrote this: http://www.battlemaze.com/?p=153
as it is just a simplified version without the movement.
Shader:
Hey guys this is a old post but here is a great blog posting that I found.
Im using for my current project the HDRP and this little shader works like a charm.