title: Recalculate normal of flat surface shader in Unity
body: <p>I'm making low poly water and I'm unsuccessfully trying to make the lighting work.</p>
  
  <p>I have made a shader which sets a color to the model and moves its vertices along the z axis.</p>
  
  <p><a href="http://diary.conewars.com/vertex-displacement-shader/" rel="nofollow noreferrer">This tutorial</a> explains how to recalculate the normals in a shader. However it uses smooth shading which is explained very well in <a href="https://www.youtube.com/watch?v=PMgjVJogIbc" rel="nofollow noreferrer">this video</a>.</p>
  
  <p>For my low poly water I need flat shading which, based on my understanding of the video, requires me to split each vertices in 3 separate vertices that have the same position but a different normal.</p>
  
  <p>How can I achieve that?</p>
  
  <p>Here is how it looks in Unity for now. Don't mind the ugliness of the waves as I just started writing this. The problem is the smoothed shadow inbetween the waves.</p>
  
  <p><a href="https://i.stack.imgur.com/ChPhv.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ChPhv.gif" alt="enter image description here"></a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>Shader "Ramble/LowPolyWater" {
      Properties {
          _MainTex ("Texture", 2D) = "white" {}
          _Color ("Main Color", Color) = (1,1,1,1)
          _Emission ("Emission", Color) = (1,1,1,1)
          _ScrollYSpeed("Scroll y speed", Float) = 0.1
      }
      SubShader {
          Tags { "RenderType"="Opaque" }
          CGPROGRAM
  
          #pragma surface surf Lambert fullforwardshadows vertex:vert addshadow
  
          struct Input {
              float2 uv_MainTex;
          };
  
          sampler2D _MainTex;
          fixed4 _Color;
          fixed4 _Emission;
          float _ScrollYSpeed;
  
          float4 getNewVertPosition( float4 p ) {
              p.z += frac(sin( dot(p.xyz ,float3(12.9898,78.233,45.5432) )) * 43758.5453) * sin(_Time.y) * _ScrollYSpeed;;
              return p;
          }
  
          void vert (inout appdata_full v)
          {
  
              float4 bitangent = float4(cross( v.normal, v.tangent), 0);
  
              float4 position = getNewVertPosition( v.vertex );
              float4 positionAndTangent = getNewVertPosition( v.vertex + v.tangent * 0.01 );
              float4 positionAndBitangent = getNewVertPosition( v.vertex + bitangent * 0.01 );
  
              v.vertex.z = position.z;
  
              float4 newTangent = ( positionAndTangent - position ); // leaves just 'tangent'
              float4 newBitangent = ( positionAndBitangent - position ); // leaves just 'bitangent'
  
              float4 newNormal = float4(cross( newTangent, newBitangent), 0);
              v.normal = newNormal;
          }
  
          void surf (Input IN, inout SurfaceOutput o) {
              o.Albedo = (tex2D (_MainTex, IN.uv_MainTex) * _Color).rgb;
              o.Emission = _Emission.rgb;
          }
          ENDCG
      }
      Fallback "VertexLit"
  }
  </code></pre>