blob: 0c53fa7f91404424b00df4b61664ffb70a0a0a72 (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#if UDONSHARP
using UdonSharp;
using UdonSharp.Video;
using UnityEngine;
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class LTCGI_USharpVideoAdapter : UdonSharpBehaviour
{
const string MATERIAL_PARAM_TEX = "_MainTex";
const string MATERIAL_PARAM_OVERLAY_OPACITY = "_OverlayOpacity";
const string MATERIAL_PARAM_GAMMA = "_Gamma";
const string MATERIAL_PARAM_FLIPUV = "_FlipUV";
public USharpVideoPlayer VideoPlayer;
public CustomRenderTexture CRT;
[Tooltip("Place the same Standby Texture as in your VideoScreenHandler here if you want it to reflect too. Should be black if unset.")]
public Texture StandbyTexture;
private Material sharedMaterial;
void Start()
{
sharedMaterial = CRT.material;
VideoPlayer.RegisterCallbackReceiver(this);
sharedMaterial.SetFloat(MATERIAL_PARAM_OVERLAY_OPACITY, 0.0f);
}
public void OnUSharpVideoModeChange() => OnUSharpVideoRenderTextureChange();
public void OnUSharpVideoRenderTextureChange()
{
var manager = VideoPlayer.GetVideoManager();
var tex = manager.GetVideoTexture();
var unity = VideoPlayer.IsUsingUnityPlayer();
if (tex == null)
{
Debug.Log("[LTCGI_USharpVideoAdapter] set to standby texture");
sharedMaterial.SetTexture(MATERIAL_PARAM_TEX, StandbyTexture);
sharedMaterial.SetFloat(MATERIAL_PARAM_FLIPUV, 1.0f);
sharedMaterial.SetFloat(MATERIAL_PARAM_GAMMA, 0.0f);
}
else
{
sharedMaterial.SetTexture(MATERIAL_PARAM_TEX, tex);
if (unity)
{
Debug.Log("[LTCGI_USharpVideoAdapter] set to unity player");
sharedMaterial.SetFloat(MATERIAL_PARAM_FLIPUV, 1.0f);
sharedMaterial.SetFloat(MATERIAL_PARAM_GAMMA, 0.0f);
}
else
{
Debug.Log("[LTCGI_USharpVideoAdapter] set to avpro player");
sharedMaterial.SetFloat(MATERIAL_PARAM_FLIPUV, 0.0f);
sharedMaterial.SetFloat(MATERIAL_PARAM_GAMMA, 1.0f);
}
}
}
}
#endif
|