-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTiltedSplitscreen.cs
More file actions
41 lines (34 loc) · 1.2 KB
/
TiltedSplitscreen.cs
File metadata and controls
41 lines (34 loc) · 1.2 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
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(Camera))]
public class TiltedSplitscreen : PostEffectsBase {
public Camera camera2;
public Transform followTarget1, followTarget2;
public Shader titledSplitscreenShader;
RenderTexture otherTexture;
Material m;
Vector3 direction;
float yDist, xDist;
public override void Start() {
//if(camera2.targetTexture == null || camera2.targetTexture.width != Screen.width)
camera2.targetTexture = new RenderTexture(Screen.width, Screen.height, 32);
otherTexture = camera2.targetTexture;
m = new Material(titledSplitscreenShader);
}
void Update () {
direction = (followTarget1.position - followTarget2.position).normalized;
yDist = followTarget1.position.y - followTarget2.position.y;
xDist = followTarget1.position.x - followTarget2.position.x;
}
void OnRenderImage(RenderTexture source, RenderTexture destination){
if(camera2.enabled){
m.SetTexture("_OtherTex", otherTexture);
m.SetVector("_Vector", new Vector4(-direction.x, direction.y, 0, 0));
m.SetFloat("_YDistance", yDist);
m.SetFloat("_XDistance", xDist);
Graphics.Blit(source, destination, m);
}else{
Graphics.Blit(source, destination);
}
}
}