-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectorInputUdon.cs
49 lines (45 loc) · 1.75 KB
/
ProjectorInputUdon.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 UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class ProjectorInputUdon : UdonSharpBehaviour
{
[System.NonSerialized]public Matrix4x4 viewMatrix;
[System.NonSerialized]public Matrix4x4 projectionMatrix;
[System.NonSerialized]public Vector4 projectorPos;
[System.NonSerialized] public Vector4 color;
[System.NonSerialized] public Vector4 scaleOffset;
[System.NonSerialized] public Material Presetted_material;
[System.NonSerialized] public Material material;
public void Update()
{
if(Presetted_material != null)
{
MeshRenderer target = transform.parent.gameObject.GetComponent<MeshRenderer>();
int index = 0;
foreach (Material mat in target.sharedMaterials)
{
if(mat == Presetted_material)
{
target.sharedMaterial = material;
MaterialPropertyBlock properties = new MaterialPropertyBlock();
properties.SetMatrix("_ProjectorMatrixVP", projectionMatrix * viewMatrix);
properties.SetVector("_ProjectorPos", projectorPos);
//properties.SetVector("_Color", color);
properties.SetVector("_InstancedMainScaleOffset", scaleOffset);
target.SetPropertyBlock(properties, index);
}
index++;
}
}
else
{
material.SetMatrix("_ProjectorMatrixVP", projectionMatrix * viewMatrix);
material.SetVector("_ProjectorPos", projectorPos);
//material.SetVector("_Color", color);
material.SetVector("_InstancedMainScaleOffset", scaleOffset);
}
this.enabled = false;
}
}