-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathScanlinesEffect.cs
44 lines (37 loc) · 1.01 KB
/
ScanlinesEffect.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
using System;
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Image Effects/Camera/Scanlines Effect")]
public class ScanlinesEffect : MonoBehaviour {
public Shader shader;
private Material _material;
[Range(0, 10)]
public float lineWidth = 2f;
[Range(0, 1)]
public float hardness = 0.9f;
[Range(0, 1)]
public float displacementSpeed = 0.1f;
protected Material material {
get {
if (_material == null) {
_material = new Material(shader);
_material.hideFlags = HideFlags.HideAndDontSave;
}
return _material;
}
}
private void OnRenderImage(RenderTexture source, RenderTexture destination) {
if (shader == null)
return;
material.SetFloat("_LineWidth", lineWidth);
material.SetFloat("_Hardness", hardness);
material.SetFloat("_Speed", displacementSpeed);
Graphics.Blit(source, destination, material, 0);
}
void OnDisable() {
if (_material) {
DestroyImmediate(_material);
}
}
}