-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPixelCamDrawer.cs
55 lines (46 loc) · 1.21 KB
/
PixelCamDrawer.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using UnityEngine;
namespace SubjectNerd.Utilities
{
[ExecuteInEditMode]
[AddComponentMenu("")]
public class PixelCamDrawer : MonoBehaviour
{
/*
This class sits on a hidden camera that draws nothing, the pixel camera output
is being redirected to a render texture, so we need a camera context to draw into
*/
public PixelCamera SourceCamera { get; set; }
private void OnPostRender()
{
if (SourceCamera == null) return;
DrawQuad();
SourceCamera.CheckCamera();
}
public void DrawQuad()
{
if (SourceCamera == null || SourceCamera.CameraMaterial == null)
return;
Vector2 min = SourceCamera.QuadMin;
Vector2 max = SourceCamera.QuadMax;
float zOffset = -0.1f;
Material renderMat = SourceCamera.CameraMaterial;
GL.PushMatrix();
GL.LoadOrtho();
for (int i = 0; i < renderMat.passCount; i++)
{
renderMat.SetPass(i);
GL.Begin(GL.QUADS);
GL.TexCoord2(0.0f, 0.0f);
GL.Vertex3(min.x, min.y, zOffset);
GL.TexCoord2(0.0f, 1.0f);
GL.Vertex3(min.x, max.y, zOffset);
GL.TexCoord2(1.0f, 1.0f);
GL.Vertex3(max.x, max.y, zOffset);
GL.TexCoord2(1.0f, 0.0f);
GL.Vertex3(max.x, min.y, zOffset);
GL.End();
}
GL.PopMatrix();
}
}
}