FlatShader

  • 노말의 앵글을 없에므로 메쉬간 평평한(Flat)효과를 얻을 수 있다.
  • 속성을 변경하거나, 런타임에 변경할 수도 있다.

속성을 변경

  • https://gamedevelopment.tutsplus.com/articles/go-beyond-retro-pixel-art-with-flat-shaded-3d-in-unity--gamedev-12259
fbx> Normals & Tangents > Normals> Calculate
fbx> Normals & Tangents > Smoothing Angle> 0

런타임

void FlatShading ()
{
    MeshFilter mf = GetComponent<MeshFilter>();
    Mesh mesh = Instantiate (mf.sharedMesh) as Mesh;
    mf.sharedMesh = mesh;

    Vector3[] oldVerts = mesh.vertices;
    int[] triangles = mesh.triangles;
    Vector3[] vertices = new Vector3[triangles.Length];

    for (int i = 0; i < triangles.Length; i++) 
    {
        vertices[i] = oldVerts[triangles[i]];
        triangles[i] = i;
    }

    mesh.vertices = vertices;
    mesh.triangles = triangles;
    mesh.RecalculateNormals();
}

Shader

half3 x = ddx(IN.positionWS);
half3 y = ddy(IN.positionWS);

half3 N = normalize(-cross(x, y));