forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShaderDebugging.cs
48 lines (41 loc) · 1009 Bytes
/
ShaderDebugging.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
using UnityEngine;
public class ShaderDebugging : MonoBehaviour
{
public GameObject target;
private Material material;
private ComputeBuffer buffer;
private Vector4[] element;
private string label;
private Renderer render;
void Load ()
{
buffer = new ComputeBuffer(1, 16, ComputeBufferType.Default);
element = new Vector4[1];
label = string.Empty;
render = target.GetComponent<Renderer>();
material = render.material;
}
void Start ()
{
Load();
}
void Update ()
{
Graphics.ClearRandomWriteTargets();
material.SetPass(0);
material.SetBuffer("buffer", buffer);
Graphics.SetRandomWriteTarget(1, buffer, false);
buffer.GetData(element);
label = (element!=null && render.isVisible) ? element[0].ToString("F3") : string.Empty;
}
void OnGUI()
{
GUIStyle style = new GUIStyle();
style.fontSize = 32;
GUI.Label(new Rect(50, 50, 400, 100), label, style);
}
void OnDestroy()
{
buffer.Dispose();
}
}