-
Notifications
You must be signed in to change notification settings - Fork 0
/
RayLightRenderer.cs
49 lines (44 loc) · 1.1 KB
/
RayLightRenderer.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
using UnityEngine;
using System.Collections;
public class RayLightRenderer : MonoBehaviour {
public
void Start()
{
Camera mc = Camera.main;
Camera c = GetComponent<Camera>();
c.aspect = mc.aspect;
c.orthographic = mc.orthographic;
c.orthographicSize = mc.orthographicSize;
}
//Draw dem triangles
void DrawTriangle(Vector3 v1, Vector3 v2, Vector3 v3, Material mat, float depth)
{
v1.z = depth;
v2.z = depth;
v3.z = depth;
GL.PushMatrix();
mat.SetPass(0);
GL.LoadOrtho();
GL.Color(mat.color);
GL.Begin(GL.TRIANGLES);
GL.Vertex(v1);
GL.Vertex(v2);
GL.Vertex(v3);
GL.End();
GL.PopMatrix();
}
//Get dem triangles
void OnPostRender()
{
foreach(RayLight l in FindObjectsOfType<RayLight>())
{
Vector3[] endpoints = l.endpoints;
int len = endpoints.Length;
for(int i = 0; i < len; i++)
{
Vector3 next = i >= len - 1 ? endpoints[0] : endpoints[i + 1];
DrawTriangle(Camera.main.WorldToViewportPoint(l.transform.position), Camera.main.WorldToViewportPoint(endpoints[i]), Camera.main.WorldToViewportPoint(next), l.mat, l.transform.position.z);
}
}
}
}