diff --git a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs index 184493e..0cfc92d 100644 --- a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs +++ b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs @@ -8,31 +8,46 @@ public class MultipleMonitorCreator : MonoBehaviour void Start() { + // Sort monitors in coordinate order var monitors = uDesktopDuplication.Manager.monitors; monitors.Sort((a, b) => a.left - b.left); + // Create monitors var n = monitors.Count; - var totalWidth = 0f; for (int i = 0 ; i < n; ++i) { + // Create monitor obeject var go = Instantiate(monitorPrefab); go.name = "Monitor " + i; + + // Assign monitor var texture = go.GetComponent(); texture.monitorId = i; - var height = width / texture.monitor.aspect; - go.transform.localScale = new Vector3(width, go.transform.localScale.y, height); + + // Set width / height + var isHorizontal = texture.monitor.isHorizontal; + var w = isHorizontal ? width : (width * texture.monitor.aspect); + var h = isHorizontal ? width / texture.monitor.aspect : width; + go.transform.localScale = new Vector3(w, go.transform.localScale.y, h); + + // Set parent as this object go.transform.SetParent(transform); + + // Calc actual size considering mesh size var scaleX = go.GetComponent().sharedMesh.bounds.extents.x * 2f; - totalWidth += width * scaleX; + totalWidth += w * scaleX; } - + // Set positions with margin totalWidth += margin * (n - 1); var x = -totalWidth / 2; for (int i = 0 ; i < n; ++i) { + // var go = transform.FindChild("Monitor " + i); + var texture = go.GetComponent(); var halfScaleX = go.GetComponent().sharedMesh.bounds.extents.x; - var halfWidth = width * halfScaleX; + var w = texture.monitor.isHorizontal ? width : (width * texture.monitor.aspect); + var halfWidth = w * halfScaleX; x += halfWidth; go.transform.localPosition = new Vector3(x, 0f, 0f); x += halfWidth + margin; diff --git a/Assets/uDesktopDuplication/Scripts/Texture.cs b/Assets/uDesktopDuplication/Scripts/Texture.cs index e1ba444..168b4bd 100644 --- a/Assets/uDesktopDuplication/Scripts/Texture.cs +++ b/Assets/uDesktopDuplication/Scripts/Texture.cs @@ -68,10 +68,30 @@ public class Texture : MonoBehaviour material.DisableKeyword("INVERT_Y"); } - if (monitor.isVertical) { - material.EnableKeyword("VERTICAL"); - } else { - material.DisableKeyword("VERTICAL"); + switch (monitor.rotation) + { + case MonitorRotation.Identity: + material.DisableKeyword("ROTATE90"); + material.DisableKeyword("ROTATE180"); + material.DisableKeyword("ROTATE270"); + break; + case MonitorRotation.Rotate90: + material.EnableKeyword("ROTATE90"); + material.DisableKeyword("ROTATE180"); + material.DisableKeyword("ROTATE270"); + break; + case MonitorRotation.Rotate180: + material.DisableKeyword("ROTATE90"); + material.EnableKeyword("ROTATE180"); + material.DisableKeyword("ROTATE270"); + break; + case MonitorRotation.Rotate270: + material.DisableKeyword("ROTATE90"); + material.DisableKeyword("ROTATE180"); + material.EnableKeyword("ROTATE270"); + break; + default: + break; } } } diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc b/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc index 4fe696d..5d0ab44 100644 --- a/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc +++ b/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc @@ -20,22 +20,35 @@ struct Input float2 uv_MainTex; }; -inline void uddInvertUV(inout float2 uv) +float2 uddInvertUV(float2 uv) { #ifdef INVERT_X - uv.x = 1.0 - uv.x; + uv.x = 1.0 - uv.x; #endif #ifdef INVERT_Y - uv.y = 1.0 - uv.y; + uv.y = 1.0 - uv.y; #endif -#ifdef VERTICAL + return uv; +} + +float2 uddRotateUV(float2 uv) +{ +#ifdef ROTATE90 float2 tmp = uv; uv.x = tmp.y; uv.y = 1.0 - tmp.x; +#elif ROTATE180 + uv.x = 1.0 - uv.x; + uv.y = 1.0 - uv.y; +#elif ROTATE270 + float2 tmp = uv; + uv.x = 1.0 - tmp.y; + uv.y = tmp.x; #endif + return uv; } -inline void uddToLinearIfNeeded(inout fixed3 rgb) +inline void uddConvertToLinearIfNeeded(inout fixed3 rgb) { if (!IsGammaSpace()) { rgb = GammaToLinearSpace(rgb); @@ -60,11 +73,11 @@ inline fixed4 uddGetCursorTexture(sampler2D tex, float2 uv, fixed4 cursorPosScal inline fixed4 uddGetScreenTextureWithCursor(sampler2D screenTex, sampler2D cursorTex, float2 uv, fixed4 cursorPosScale) { - uddInvertUV(uv); - fixed4 screen = uddGetScreenTexture(screenTex, uv); + uv = uddInvertUV(uv); + fixed4 screen = uddGetScreenTexture(screenTex, uddRotateUV(uv)); fixed4 cursor = uddGetCursorTexture(cursorTex, uv, cursorPosScale); fixed4 color = lerp(screen, cursor, cursor.a); - uddToLinearIfNeeded(color.rgb); + uddConvertToLinearIfNeeded(color.rgb); return color; } diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader b/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader index d71e3ae..b91f701 100644 --- a/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader +++ b/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader @@ -23,6 +23,7 @@ SubShader #pragma multi_compile ___ INVERT_X #pragma multi_compile ___ INVERT_Y #pragma multi_compile ___ VERTICAL + #pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270 #define SURFACE_SHADER #include "./uDD_Common.cginc" diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader b/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader index cb04b23..1e4d72d 100644 --- a/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader @@ -53,6 +53,7 @@ Pass #pragma multi_compile ___ INVERT_Y #pragma multi_compile ___ VERTICAL #pragma shader_feature ___ USE_BEND + #pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270 ENDCG } diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader index e80bf60..5dbfadf 100644 --- a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader @@ -50,6 +50,7 @@ Pass #pragma multi_compile ___ INVERT_X #pragma multi_compile ___ INVERT_Y #pragma multi_compile ___ VERTICAL + #pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270 ENDCG } diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader index fbf62ba..8f795fc 100644 --- a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader @@ -45,6 +45,7 @@ Pass #pragma multi_compile ___ INVERT_X #pragma multi_compile ___ INVERT_Y #pragma multi_compile ___ VERTICAL + #pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270 ENDCG }