
you can use Replacement Shader to Displaying Mesh Normals
First attach this script to camera:
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class ReplacementShaderEffect : MonoBehaviour
{
public Shader ReplacementShader;
void OnEnable()
{
if (ReplacementShader != null)
GetComponent<Camera>().SetReplacementShader(ReplacementShader, "");
}
void OnDisable()
{
GetComponent<Camera>().ResetReplacementShader();
}
}
then use this shader in above script for Replacing shaders
Shader "Tutorial/Display Normals" {
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.color = v.normal * 0.5 + 0.5;
return o;
}
half4 frag (v2f i) : COLOR
{
return half4 (i.color, 1);
}
ENDCG
}
}
Fallback "VertexLit"
}
In your comments you mentioned that you need store result to Rendertexture and use it in shader for post-processing
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CaptureMe : MonoBehaviour {
public RenderTexture RT;
public Camera SecondCamera;//Second Camera Renders Normal that store to RenderTexture
public Shader shader;//shader that you want pass result to it
void Update(){
}
void OnRenderImage(RenderTexture source,RenderTexture target){
int resWidth = Screen.width;
int resHeight = Screen.height;
RT = new RenderTexture(resWidth, resHeight, 24);
SecondCamera.targetTexture = RT; //Create new renderTexture and assign to camera
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); //Create new texture
SecondCamera.Render();
RenderTexture.active = RT;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0); //Apply pixels from camera onto Texture2D
SecondCamera.targetTexture = null;
RenderTexture.active = null; //Clean
Material mat = new Material(shader);
mat.SetTexture ("_NormalScene", RT);
Graphics.Blit (source, target,mat);
Destroy(RT); //Free memory
}
}
Update

If you need better result you should be calculating the world normals.
Shader "Tutorial/DisplayNormal2"
{
SubShader
{
Tags { "RenderType" = "Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float4 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata_base v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv.xyz = UnityObjectToWorldNormal(v.normal);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 c = i.uv.xyz;
return float4(c, 1);
}
ENDCG
}
}
}