-
Notifications
You must be signed in to change notification settings - Fork 212
/
NormalPostprocessing.cs
27 lines (22 loc) · 1.03 KB
/
NormalPostprocessing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using UnityEngine;
using UnityEngine.Serialization;
//behaviour which should lie on the same gameobject as the main camera
public class NormalPostprocessing : MonoBehaviour {
//material that's applied when doing postprocessing
[FormerlySerializedAs("postprocessMaterial"), SerializeField]
public Material PostprocessMaterial;
private Camera cam;
private void Start(){
//get the camera and tell it to render a depthnormals texture
cam = GetComponent<Camera>();
cam.depthTextureMode = cam.depthTextureMode | DepthTextureMode.DepthNormals;
}
//method which is automatically called by unity after the camera is done rendering
private void OnRenderImage(RenderTexture source, RenderTexture destination){
//get viewspace to worldspace matrix and pass it to shader
Matrix4x4 viewToWorld = cam.cameraToWorldMatrix;
PostprocessMaterial.SetMatrix("_viewToWorld", viewToWorld);
//draws the pixels from the source texture to the destination texture
Graphics.Blit(source, destination, PostprocessMaterial);
}
}