mirror of
https://github.com/xiaopeng12138/MaiDXR.git
synced 2024-11-24 03:50:10 +01:00
add screen share over netcode using nvenc
This commit is contained in:
parent
99106fa378
commit
13c18c8fc2
@ -59,7 +59,7 @@ Material:
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 2800000, guid: 6660365cd3c564f4582541b1cf6cce84, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Scale: {x: 1, y: -1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
@ -73,6 +73,10 @@ Material:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SecTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
@ -92,16 +96,31 @@ Material:
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _BUILTIN_QueueControl: -1
|
||||
- _BUILTIN_QueueOffset: 0
|
||||
- _Blend: 0
|
||||
- _BlendOp: 0
|
||||
- _BumpScale: 1
|
||||
- _CameraFadingEnabled: 0
|
||||
- _CameraFarFadeDistance: 2
|
||||
- _CameraNearFadeDistance: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _ColorMode: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DistortionBlend: 0.5
|
||||
- _DistortionEnabled: 0
|
||||
- _DistortionStrength: 1
|
||||
- _DistortionStrengthScaled: 0.1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _FlipX: 0
|
||||
- _FlipY: 0
|
||||
- _FlipbookBlending: 0
|
||||
- _FlipbookMode: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 1
|
||||
@ -111,8 +130,12 @@ Material:
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _SampleGI: 0
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SoftParticlesEnabled: 0
|
||||
- _SoftParticlesFarFadeDistance: 1
|
||||
- _SoftParticlesNearFadeDistance: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
@ -121,7 +144,10 @@ Material:
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.38058165, g: 0.38058165, b: 0.38058165, a: 1}
|
||||
- _Color: {r: 0.38058162, g: 0.38058162, b: 0.38058162, a: 1}
|
||||
- _BaseColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _CameraFadeParams: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
|
@ -58,8 +58,8 @@ Material:
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 2800000, guid: f44b1ed140e7104439a23e290bf6ed3f, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Texture: {fileID: 2800000, guid: 6660365cd3c564f4582541b1cf6cce84, type: 3}
|
||||
m_Scale: {x: 1, y: -1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
|
Binary file not shown.
@ -1551,6 +1551,7 @@ MonoBehaviour:
|
||||
HandPositionX: 0
|
||||
HandPositionY: 0
|
||||
HandPositionZ: 0
|
||||
Sliders: []
|
||||
--- !u!1 &149481173433458732
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1479,6 +1479,8 @@ GameObject:
|
||||
- component: {fileID: 7954102358903816433}
|
||||
- component: {fileID: 6166462342570134929}
|
||||
- component: {fileID: 6918064188570338137}
|
||||
- component: {fileID: 5523943268535035658}
|
||||
- component: {fileID: 8812900737838453218}
|
||||
m_Layer: 0
|
||||
m_Name: XRNetwork
|
||||
m_TagString: Untagged
|
||||
@ -1698,8 +1700,54 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 5be4365f045c3264ea500128c655fae6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Player1Position: {x: -1, y: 0}
|
||||
Player2Position: {x: 1, y: 0}
|
||||
Player1Position: {x: -0.75, y: 0}
|
||||
Player2Position: {x: 0.75, y: 0}
|
||||
--- !u!114 &5523943268535035658
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 149481173429413636}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a50a416b20df1fe4e95e9982b82c084b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Encoder: {fileID: 8812900737838453218}
|
||||
Decoder: {fileID: 0}
|
||||
DecoderTexture: {fileID: 0}
|
||||
maxPacketSize: 4096
|
||||
timeout: 100
|
||||
--- !u!114 &8812900737838453218
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 149481173429413636}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1beb3ca2d3590d64aaa6e95c89db59aa, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
texture: {fileID: 0}
|
||||
encoder:
|
||||
onEncoded:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
outputError: 0
|
||||
setting:
|
||||
width: 1920
|
||||
height: 1080
|
||||
frameRate: 24
|
||||
bitRate: 98304
|
||||
maxFrameSize: 4096
|
||||
format: 87
|
||||
idrFrameIntervalFrame: 24
|
||||
ResolutionDivider: 2
|
||||
sTexture: {fileID: 0}
|
||||
ResizeShader: {fileID: 0}
|
||||
--- !u!1 &149481173433458732
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -888,6 +888,37 @@ MonoBehaviour:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_IsOn: 1
|
||||
--- !u!1 &87509939
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 87509942}
|
||||
m_Layer: 0
|
||||
m_Name: Test
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &87509942
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 87509939}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0.5159848, y: 1.8461566, z: 1.1951983}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 12
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &96262323
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -5398,7 +5429,7 @@ MonoBehaviour:
|
||||
Port: 7777
|
||||
Address: 127.0.0.1
|
||||
MaxClients: 100
|
||||
MessageBufferSize: 5120
|
||||
MessageBufferSize: 51200
|
||||
PingInterval: 500
|
||||
TimeoutLimit: 32
|
||||
TimeoutMinimum: 5000
|
||||
@ -5416,12 +5447,12 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
PlayerIOs:
|
||||
- {fileID: 1716582342}
|
||||
- {fileID: 1006346016}
|
||||
- {fileID: 393682}
|
||||
- {fileID: 2079759568}
|
||||
- {fileID: 934521997}
|
||||
- {fileID: 1006346016}
|
||||
- {fileID: 2069467403}
|
||||
- {fileID: 393682}
|
||||
- {fileID: 1716582342}
|
||||
- {fileID: 934521997}
|
||||
PlayerIOsOpposite:
|
||||
- {fileID: 1390826961}
|
||||
- {fileID: 1023774752}
|
||||
@ -7887,6 +7918,11 @@ PrefabInstance:
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1995990277796536632, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
type: 3}
|
||||
propertyPath: m_TagString
|
||||
value: DisplayP1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1995990277796536632, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
type: 3}
|
||||
propertyPath: m_StaticEditorFlags
|
||||
@ -7962,6 +7998,11 @@ PrefabInstance:
|
||||
propertyPath: m_Enabled
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2963333645091585133, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
type: 3}
|
||||
propertyPath: m_TagString
|
||||
value: Untagged
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2963333645091585133, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
type: 3}
|
||||
propertyPath: m_StaticEditorFlags
|
||||
@ -8602,6 +8643,11 @@ PrefabInstance:
|
||||
propertyPath: m_Enabled
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8110296352969589220, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
type: 3}
|
||||
propertyPath: m_TagString
|
||||
value: DisplayP2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8123848027915441045, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
@ -10458,6 +10504,12 @@ MonoBehaviour:
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!1 &963757693 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 8110296352969589220, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 757793526}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &965250220 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 5910539533559942829, guid: 4cbf0dbca1ca1a5499c4b7806ab6aac5,
|
||||
@ -15965,6 +16017,35 @@ Transform:
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 757793526}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &1390826964
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963757693}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 78ff908a2776a034e9792518f4c6da70, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
decoder: {fileID: 1390826965}
|
||||
--- !u!114 &1390826965
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963757693}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fd03e427cccae6341afca0ae448e2ec0, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
width: 360
|
||||
height: 640
|
||||
codec: 0
|
||||
format: 0
|
||||
--- !u!1 &1391291191
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -98,7 +98,7 @@ public class CaptureSettingManager : MonoBehaviour
|
||||
|
||||
public void SetCP1P()
|
||||
{
|
||||
WindowMaterial.SetTextureScale("_MainTex",new Vector2(Toggle.isOn ? 1f : 0.5f, 1));
|
||||
WindowMaterial.SetTextureScale("_MainTex",new Vector2(Toggle.isOn ? 1f : 0.5f, -1));
|
||||
JsonConfig.SetBoolean("Capture1P", Toggle.isOn);
|
||||
}
|
||||
}
|
||||
|
20
Assets/Scripts/Network/Display/Display.asmdef
Normal file
20
Assets/Scripts/Network/Display/Display.asmdef
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Display",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:1491147abca9d7d4bb7105af628b223e",
|
||||
"GUID:335e60c3f2584c947bb2dd55d449ab18",
|
||||
"GUID:4d14b15ded5e3ac4499a81ec3fc340fc",
|
||||
"GUID:56dd35f9b6f21364494ed8365264cbf6",
|
||||
"GUID:ec8e026973d4d094882a84e64338c685"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
137
Assets/Scripts/Network/Display/DisplaySync.cs
Normal file
137
Assets/Scripts/Network/Display/DisplaySync.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
using uWindowCapture;
|
||||
using uPacketDivision;
|
||||
using uNvPipe;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class DisplaySync : NetworkBehaviour
|
||||
{
|
||||
public WindowEncoder Encoder;
|
||||
public uNvPipeDecoder Decoder;
|
||||
public uNvPipeDecodedTexture DecoderTexture;
|
||||
public uint maxPacketSize = 4096;
|
||||
private UwcWindow DisplayP1Window;
|
||||
private Material DisplayP2Mat;
|
||||
Divider divider = new Divider();
|
||||
public uint timeout = 100;
|
||||
Assembler assembler = new Assembler();
|
||||
bool isInitialized = false;
|
||||
void Start()
|
||||
{
|
||||
NetworkManager.Singleton.OnClientDisconnectCallback += OnClientDisconnectedCallback;
|
||||
|
||||
var DisplayP1 = GameObject.FindGameObjectWithTag("DisplayP1");
|
||||
var DisplayP2 = GameObject.FindGameObjectWithTag("DisplayP2");
|
||||
|
||||
Encoder.texture = DisplayP1.GetComponent<UwcWindowTexture>();
|
||||
Decoder = DisplayP2.GetComponent<uNvPipeDecoder>();
|
||||
DecoderTexture = DisplayP2.GetComponent<uNvPipeDecodedTexture>();
|
||||
Decoder.enabled = false;
|
||||
DecoderTexture.enabled = false;
|
||||
DisplayP2Mat = DisplayP2.GetComponent<Renderer>().material;
|
||||
|
||||
divider.maxPacketSize = maxPacketSize;
|
||||
|
||||
if (IsOwner)
|
||||
{
|
||||
Debug.Log("Add Listener");
|
||||
Encoder.encoder.onEncoded.AddListener(OnEncoded);
|
||||
}
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void OnEncoded(System.IntPtr data, int size)
|
||||
{
|
||||
//Debug.Log("OnEncoded");
|
||||
int[] winSize = new int[2]{Encoder.setting.width, Encoder.setting.height};
|
||||
SendSizeServerRpc(winSize);
|
||||
|
||||
|
||||
divider.Divide(data, (uint)size);
|
||||
for (uint i = 0; i < divider.GetChunkCount(); ++i)
|
||||
{
|
||||
SendDataServerRpc(divider.GetChunk(i));
|
||||
}
|
||||
}
|
||||
private void OnClientDisconnectedCallback(ulong callBack)
|
||||
{
|
||||
Decoder.enabled = false;
|
||||
DecoderTexture.enabled = false;
|
||||
isInitialized = false;
|
||||
}
|
||||
|
||||
//[ServerRpc(Delivery = RpcDelivery.Unreliable)]
|
||||
[ServerRpc]
|
||||
private void SendDataServerRpc(byte[] bytes)
|
||||
{
|
||||
SetDataClientRpc(bytes);
|
||||
}
|
||||
|
||||
//[ClientRpc(Delivery = RpcDelivery.Unreliable)]
|
||||
[ClientRpc]
|
||||
private void SetDataClientRpc(byte[] bytes)
|
||||
{
|
||||
if (IsOwner) return;
|
||||
assembler.timeout = timeout;
|
||||
assembler.Add(bytes);
|
||||
CheckPacketEvent();
|
||||
}
|
||||
|
||||
[ServerRpc]
|
||||
private void SendSizeServerRpc(int[] ints)
|
||||
{
|
||||
SetSizeClientRpc(ints);
|
||||
}
|
||||
|
||||
//[ClientRpc(Delivery = RpcDelivery.Unreliable)]
|
||||
[ClientRpc]
|
||||
private void SetSizeClientRpc(int[] ints)
|
||||
{
|
||||
if (IsOwner) return;
|
||||
if (isInitialized) return;
|
||||
|
||||
var width = ints[0];
|
||||
var height = ints[1];
|
||||
Debug.LogFormat("Start decoder: width => {0}, height => {1}", width, height);
|
||||
Decoder.width = width;
|
||||
Decoder.height = height;
|
||||
Decoder.enabled = true;
|
||||
DecoderTexture.enabled = true;
|
||||
DecoderTexture.gameObject.GetComponent<Renderer>().material.SetTextureScale("_MainTex",new Vector2(width/height < 0.6 ? 1f : 0.5f, -1));
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
void CheckPacketEvent()
|
||||
{
|
||||
if (!isInitialized) return;
|
||||
|
||||
switch (assembler.GetEventType())
|
||||
{
|
||||
case uPacketDivision.EventType.FrameCompleted:
|
||||
{
|
||||
var data = assembler.GetAssembledData<byte>();
|
||||
int size = data.Length;
|
||||
var handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
var ptr = handle.AddrOfPinnedObject();
|
||||
Decoder.Decode(ptr, (int)size);
|
||||
handle.Free();
|
||||
break;
|
||||
}
|
||||
case uPacketDivision.EventType.PacketLoss:
|
||||
{
|
||||
Debug.LogError("packet loss");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
99
Assets/Scripts/Network/Display/WindowEncoder.cs
Normal file
99
Assets/Scripts/Network/Display/WindowEncoder.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using uWindowCapture;
|
||||
using Unity.Netcode;
|
||||
|
||||
public class WindowEncoder : NetworkBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public UwcWindowTexture texture = null;
|
||||
|
||||
[SerializeField]
|
||||
public uNvEncoder.Encoder encoder = null;
|
||||
|
||||
[SerializeField]
|
||||
public uNvEncoder.EncoderDesc setting = new uNvEncoder.EncoderDesc
|
||||
{
|
||||
width = 1920,
|
||||
height = 1080,
|
||||
frameRate = 24,
|
||||
format = uNvEncoder.Format.B8G8R8A8_UNORM,
|
||||
bitRate = 98304,
|
||||
maxFrameSize = 4096,
|
||||
};
|
||||
|
||||
public int idrFrameIntervalFrame = 24;
|
||||
int idrFrameCounter_ = 0;
|
||||
public int ResolutionDivider = 2;
|
||||
public Texture2D sTexture;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (!IsOwner) return;
|
||||
StartCoroutine(EncodeLoop());
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (!IsOwner) return;
|
||||
StopAllCoroutines();
|
||||
encoder.Destroy();
|
||||
}
|
||||
|
||||
RenderTexture rt;
|
||||
void Resize()
|
||||
{
|
||||
Graphics.Blit(texture.window.texture, rt);
|
||||
sTexture.ReadPixels(new Rect(0,0,setting.width, setting.height),0,0);
|
||||
sTexture.Apply();
|
||||
}
|
||||
IEnumerator EncodeLoop()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (texture.window != null) break;
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
setting.width = texture.window.width / ResolutionDivider;
|
||||
setting.height = texture.window.height / ResolutionDivider;
|
||||
encoder.Create(setting);
|
||||
|
||||
rt = new RenderTexture(setting.width, setting.height, 24);
|
||||
sTexture = new Texture2D(setting.width, setting.height, TextureFormat.BGRA32, false);
|
||||
RenderTexture.active = rt;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (setting.frameRate < 60)
|
||||
{
|
||||
yield return new WaitForSeconds(1f / setting.frameRate);
|
||||
}
|
||||
|
||||
bool idr = idrFrameCounter_++ % idrFrameIntervalFrame == 0;
|
||||
Resize();
|
||||
encoder.Encode(sTexture, idr);
|
||||
encoder.Update();
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Reconfigure")]
|
||||
public void Reconfigure()
|
||||
{
|
||||
if (encoder == null) return;
|
||||
encoder.Reconfigure(setting);
|
||||
}
|
||||
|
||||
public ComputeShader ResizeShader;
|
||||
Texture2D Resize(ComputeShader shader, Texture2D inputTexture, int divideSize)
|
||||
{
|
||||
Texture2D t = new Texture2D(inputTexture.width/divideSize, inputTexture.height/divideSize, TextureFormat.BGRA32, false);
|
||||
int k = shader.FindKernel("Resize");
|
||||
shader.SetInt("divideSize", divideSize);
|
||||
shader.SetTexture(k, "inputTexture", inputTexture);
|
||||
shader.SetTexture(k, "outputTexture", t);
|
||||
shader.Dispatch(k, inputTexture.width / 8, inputTexture.height / 8, 1);
|
||||
return t;
|
||||
}
|
||||
}
|
@ -22,6 +22,11 @@ public class StartManager : MonoBehaviour
|
||||
int hostPort = 7777;
|
||||
void Start()
|
||||
{
|
||||
NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectedCallback;
|
||||
NetworkManager.Singleton.OnServerStarted += OnServerStartedCallback;
|
||||
NetworkManager.Singleton.OnClientDisconnectCallback += OnClientDisconnectedCallback;
|
||||
NetworkManager.Singleton.OnTransportFailure += OnTransportFailure;
|
||||
|
||||
if (JsonConfig.HasKey("HostIP")) hostIP = JsonConfig.GetString("HostIP");
|
||||
else JsonConfig.SetString("HostIP", hostIP);
|
||||
|
||||
@ -32,16 +37,30 @@ public class StartManager : MonoBehaviour
|
||||
GetComponent<EnetTransport>().Port = (ushort)hostPort;
|
||||
|
||||
PlayerSettingManager = XRLocal.GetComponent<PlayerSettingManager>();
|
||||
|
||||
}
|
||||
public void StartHost()
|
||||
private void OnClientConnectedCallback(ulong callBack)
|
||||
{
|
||||
SetMode();
|
||||
}
|
||||
private void OnServerStartedCallback()
|
||||
{
|
||||
//SetMode();
|
||||
}
|
||||
private void OnClientDisconnectedCallback(ulong callBack)
|
||||
{
|
||||
Debug.Log("Client Disconnected");
|
||||
StopClient();
|
||||
}
|
||||
private void OnTransportFailure()
|
||||
{
|
||||
Debug.Log("Transport Failure");
|
||||
StopAll();
|
||||
}
|
||||
private void SetMode()
|
||||
{
|
||||
if (NetworkManager.Singleton.IsHost)
|
||||
return;
|
||||
if (NetworkManager.Singleton.IsClient)
|
||||
NetworkManager.Singleton.Shutdown();
|
||||
|
||||
NetworkManager.Singleton.StartHost();
|
||||
|
||||
{
|
||||
foreach (var IO in PlayerIOs)
|
||||
IO.position = new Vector3(Player1Anchor.position.x, IO.position.y, IO.position.z);
|
||||
foreach (var IO in PlayerIOsOpposite)
|
||||
@ -50,16 +69,10 @@ public class StartManager : MonoBehaviour
|
||||
PlayerSettingManager.SetTarget(NetworkManager.Singleton.LocalClient.PlayerObject.gameObject);
|
||||
XRLocal.SetActive(false);
|
||||
StartHostButton.interactable = false;
|
||||
Debug.Log("Start Host Success");
|
||||
}
|
||||
public void StartClient()
|
||||
else if (NetworkManager.Singleton.IsClient)
|
||||
{
|
||||
if (NetworkManager.Singleton.IsClient)
|
||||
return;
|
||||
if (NetworkManager.Singleton.IsHost)
|
||||
NetworkManager.Singleton.Shutdown();
|
||||
|
||||
NetworkManager.Singleton.StartClient();
|
||||
|
||||
foreach (var IO in PlayerIOs)
|
||||
IO.position = new Vector3(Player2Anchor.position.x, IO.position.y, IO.position.z);
|
||||
foreach (var IO in PlayerIOsOpposite)
|
||||
@ -69,13 +82,59 @@ public class StartManager : MonoBehaviour
|
||||
PlayerSettingManager.SetTarget(NetworkManager.Singleton.LocalClient.PlayerObject.gameObject);
|
||||
XRLocal.SetActive(false);
|
||||
StartClientButton.interactable = false;
|
||||
Debug.Log("Start Client Success");
|
||||
}
|
||||
}
|
||||
public void StartHost()
|
||||
{
|
||||
Debug.Log("Start Host");
|
||||
if (NetworkManager.Singleton.IsClient)
|
||||
{
|
||||
NetworkManager.Singleton.Shutdown();
|
||||
PlayerSettingManager.SetTarget(XRLocal);
|
||||
XRLocal.SetActive(true);
|
||||
}
|
||||
if (!NetworkManager.Singleton.StartHost())
|
||||
{
|
||||
Debug.Log("Start Host Failed");
|
||||
StopAll();
|
||||
}
|
||||
}
|
||||
public void StartClient()
|
||||
{
|
||||
Debug.Log("Start Client");
|
||||
if (NetworkManager.Singleton.IsHost)
|
||||
{
|
||||
NetworkManager.Singleton.Shutdown();
|
||||
PlayerSettingManager.SetTarget(XRLocal);
|
||||
XRLocal.SetActive(true);
|
||||
}
|
||||
if (!NetworkManager.Singleton.StartClient())
|
||||
{
|
||||
Debug.Log("Start Client Failed");
|
||||
StopAll();
|
||||
}
|
||||
StartClientButton.interactable = false;
|
||||
}
|
||||
public void StopAll()
|
||||
{
|
||||
if (NetworkManager.Singleton.IsClient || NetworkManager.Singleton.IsHost)
|
||||
NetworkManager.Singleton.Shutdown();
|
||||
PlayerSettingManager.SetTarget(XRLocal);
|
||||
XRLocal.SetActive(true);
|
||||
StartHostButton.interactable = true;
|
||||
StartClientButton.interactable = true;
|
||||
Debug.Log("Stop All");
|
||||
}
|
||||
private void StopClient()
|
||||
{
|
||||
if (NetworkManager.Singleton.IsHost)
|
||||
return;
|
||||
NetworkManager.Singleton.Shutdown();
|
||||
PlayerSettingManager.SetTarget(XRLocal);
|
||||
XRLocal.SetActive(true);
|
||||
StartHostButton.interactable = true;
|
||||
StartClientButton.interactable = true;
|
||||
Debug.Log("Stop Client");
|
||||
}
|
||||
}
|
||||
|
11
Assets/Shaders/Resize.compute
Normal file
11
Assets/Shaders/Resize.compute
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma kernel Resize
|
||||
|
||||
int divideSize;
|
||||
Texture2D inputTexture;
|
||||
RWTexture2D <float4> outputTexture;
|
||||
|
||||
[numthreads(8, 8, 1)]
|
||||
void Resize(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
outputTexture[id.xy / divideSize] = inputTexture[id.xy];
|
||||
}
|
@ -1 +0,0 @@
|
||||
{"Keys":["com.unity.services.qos.version","com.unity.services.lobby.version","com.unity.services.core.version","com.unity.services.authentication.version","com.unity.services.relay.version"],"Values":[{"m_Value":"1.0.0","m_IsReadOnly":true},{"m_Value":"1.0.0-pre.6","m_IsReadOnly":true},{"m_Value":"1.4.0","m_IsReadOnly":true},{"m_Value":"2.0.0","m_IsReadOnly":true},{"m_Value":"1.0.2","m_IsReadOnly":true}]}
|
@ -2,6 +2,9 @@
|
||||
"dependencies": {
|
||||
"com.community.netcode.transport.enet": "https://github.com/Unity-Technologies/multiplayer-community-contributions.git?path=/Transports/com.community.netcode.transport.enet",
|
||||
"com.community.netcode.transport.websocket": "https://github.com/Unity-Technologies/multiplayer-community-contributions.git?path=/Transports/com.community.netcode.transport.websocket",
|
||||
"com.hecomi.unvencoder": "https://github.com/hecomi/uNvEncoder.git#upm",
|
||||
"com.hecomi.unvpipe": "https://github.com/hecomi/uNvPipe.git#upm",
|
||||
"com.hecomi.upacketdivision": "https://github.com/hecomi/uPacketDivision.git#upm",
|
||||
"com.hecomi.uwindowcapture": "https://github.com/hecomi/uWindowCapture.git#upm",
|
||||
"com.unity.ide.visualstudio": "2.0.14",
|
||||
"com.unity.ide.vscode": "1.2.5",
|
||||
|
@ -14,6 +14,27 @@
|
||||
"dependencies": {},
|
||||
"hash": "095d1c78b77f405b44c9ff4ae20c3a01f6d3cddc"
|
||||
},
|
||||
"com.hecomi.unvencoder": {
|
||||
"version": "https://github.com/hecomi/uNvEncoder.git#upm",
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "3568c3fa3a4f9880ff18da515281950a0d646ab9"
|
||||
},
|
||||
"com.hecomi.unvpipe": {
|
||||
"version": "https://github.com/hecomi/uNvPipe.git#upm",
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "106bcc1a49d8ed573021e63bb07d1969b09880f3"
|
||||
},
|
||||
"com.hecomi.upacketdivision": {
|
||||
"version": "https://github.com/hecomi/uPacketDivision.git#upm",
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "0c302e237b3d42f501aab1d3d0ea3ca049fea001"
|
||||
},
|
||||
"com.hecomi.uwindowcapture": {
|
||||
"version": "https://github.com/hecomi/uWindowCapture.git#upm",
|
||||
"depth": 0,
|
||||
|
@ -175,8 +175,6 @@ PlayerSettings:
|
||||
- {fileID: 0}
|
||||
- {fileID: 0}
|
||||
- {fileID: 0}
|
||||
- {fileID: 6536100391545742739, guid: 55d1ec7a4296de343b6d3bb6f9a19731, type: 2}
|
||||
- {fileID: -6018045015233401694, guid: 3999ab811e936714280a476b3a032d86, type: 2}
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
m_HolographicPauseOnTrackingLoss: 1
|
||||
|
@ -3,7 +3,9 @@
|
||||
--- !u!78 &1
|
||||
TagManager:
|
||||
serializedVersion: 2
|
||||
tags: []
|
||||
tags:
|
||||
- DisplayP1
|
||||
- DisplayP2
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
Loading…
Reference in New Issue
Block a user