support rotation 90/180/270 degs.
This commit is contained in:
@@ -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<uDesktopDuplication.Texture>();
|
||||
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<MeshFilter>().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<uDesktopDuplication.Texture>();
|
||||
var halfScaleX = go.GetComponent<MeshFilter>().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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user