forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoiseTexture.cs
More file actions
50 lines (44 loc) · 1.11 KB
/
NoiseTexture.cs
File metadata and controls
50 lines (44 loc) · 1.11 KB
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
// Add script to quad and assign material with shader. Play.
using UnityEngine;
public class NoiseTexture : MonoBehaviour
{
public Material material;
RenderTexture RT;
int property;
void Blit(RenderTexture destination, Material mat)
{
RenderTexture.active = destination;
GL.PushMatrix();
GL.LoadOrtho();
GL.invertCulling = true;
mat.SetPass(0);
GL.Begin(GL.QUADS);
GL.MultiTexCoord2(0, 0.0f, 0.0f);
GL.Vertex3(0.0f, 0.0f, 0.0f);
GL.MultiTexCoord2(0, 1.0f, 0.0f);
GL.Vertex3(1.0f, 0.0f, 0.0f);
GL.MultiTexCoord2(0, 1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 0.0f);
GL.MultiTexCoord2(0, 0.0f, 1.0f);
GL.Vertex3(0.0f, 1.0f, 0.0f);
GL.End();
GL.invertCulling = false;
GL.PopMatrix();
}
void Start ()
{
RT = new RenderTexture(256, 256, 0, RenderTextureFormat.ARGBFloat);
RT.filterMode = FilterMode.Point;
GetComponent<Renderer>().material = material;
property = Shader.PropertyToID("_BufferA");
}
void Update ()
{
Blit(RT, material);
material.SetTexture(property, RT);
}
void OnDestroy ()
{
RT.Release();
}
}