Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb7bcbfa5b | ||
|
|
9ed8bb8d5b | ||
|
|
fab67bbc61 | ||
|
|
5fa9f03a0e | ||
|
|
941bb2da91 | ||
|
|
d423e0d1db | ||
|
|
33a55d95bd | ||
|
|
8e2d8d3218 |
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bae91f55031b98488c9e668031f7387
|
||||
timeCreated: 1478610618
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
BIN
Assets/uDesktopDuplication/Examples/Scenes/Zoom.unity
Normal file
BIN
Assets/uDesktopDuplication/Examples/Scenes/Zoom.unity
Normal file
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3d41026babadc241b9d0852b0831584
|
||||
timeCreated: 1478436298
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs
Normal file
37
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Loupe : MonoBehaviour
|
||||
{
|
||||
private uDesktopDuplication.Texture uddTexture_;
|
||||
public float zoom = 3f;
|
||||
public float aspect = 1f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
uddTexture_ = GetComponent<uDesktopDuplication.Texture>();
|
||||
uddTexture_.useClip = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// To get other monitor textures, set dirty flag.
|
||||
foreach (var monitor in uDesktopDuplication.Manager.monitors) {
|
||||
monitor.CreateTexture();
|
||||
monitor.shouldBeUpdated = true;
|
||||
}
|
||||
|
||||
if (!uddTexture_.monitor.isCursorVisible) {
|
||||
uddTexture_.monitorId = uDesktopDuplication.Manager.cursorMonitorId;
|
||||
}
|
||||
|
||||
var x = (float)uddTexture_.monitor.cursorX / uddTexture_.monitor.width;
|
||||
var y = (float)uddTexture_.monitor.cursorY / uddTexture_.monitor.height;
|
||||
var w = 1f / zoom;
|
||||
var h = w / aspect * uddTexture_.monitor.aspect;
|
||||
x = Mathf.Clamp(x - w / 2, 0f, 1f - w);
|
||||
y = Mathf.Clamp(y - h / 2, 0f, 1f - h);
|
||||
uddTexture_.clipPos = new Vector2(x, y);
|
||||
uddTexture_.clipScale = new Vector2(w, h);
|
||||
}
|
||||
}
|
||||
|
||||
12
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs.meta
Normal file
12
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efd9499cdb931b945947a2cd47909676
|
||||
timeCreated: 1478438457
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,11 +4,17 @@ using System.Collections.Generic;
|
||||
public class MultipleMonitorCreator : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject monitorPrefab;
|
||||
[SerializeField] float scale = 1f;
|
||||
[SerializeField] float margin = 1f;
|
||||
|
||||
private List<GameObject> monitors_ = new List<GameObject>();
|
||||
private float totalWidth_ = 0f;
|
||||
public class MonitorInfo
|
||||
{
|
||||
public GameObject gameObject { get; set; }
|
||||
public Quaternion originalRotation { get; set; }
|
||||
public uDesktopDuplication.Texture uddTexture { get; set; }
|
||||
public Vector3 meshBounds;
|
||||
}
|
||||
|
||||
private List<MonitorInfo> monitors_ = new List<MonitorInfo>();
|
||||
public List<MonitorInfo> monitors { get { return monitors_; } }
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -26,25 +32,16 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
}
|
||||
|
||||
void Create()
|
||||
{
|
||||
CreateMonitors();
|
||||
LayoutMonitors();
|
||||
}
|
||||
|
||||
void CreateMonitors()
|
||||
{
|
||||
// Sort monitors in coordinate order
|
||||
var monitors = uDesktopDuplication.Manager.monitors;
|
||||
monitors.Sort((a, b) => a.left - b.left);
|
||||
|
||||
// Create monitors
|
||||
var n = monitors.Count;
|
||||
totalWidth_ = 0f;
|
||||
for (int i = 0 ; i < n; ++i) {
|
||||
for (int i = 0 ; i < uDesktopDuplication.Manager.monitorCount; ++i) {
|
||||
// Create monitor obeject
|
||||
var go = Instantiate(monitorPrefab);
|
||||
go.name = "Monitor " + i;
|
||||
monitors_.Add(go);
|
||||
|
||||
// Assign monitor
|
||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||
@@ -58,31 +55,22 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
go.transform.SetParent(transform);
|
||||
|
||||
// Calc actual size considering mesh size
|
||||
var scaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x * 2f;
|
||||
totalWidth_ += monitor.widthMeter * scaleX;
|
||||
}
|
||||
}
|
||||
var bounds = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents * 2f;
|
||||
|
||||
void LayoutMonitors()
|
||||
{
|
||||
// Set positions with margin
|
||||
totalWidth_ += margin * (monitors_.Count - 1);
|
||||
var x = -totalWidth_ / 2;
|
||||
foreach (var go in monitors_) {
|
||||
var monitor = go.GetComponent<uDesktopDuplication.Texture>().monitor;
|
||||
var halfScaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x;
|
||||
var width = monitor.widthMeter;
|
||||
var halfWidth = width * halfScaleX;
|
||||
x += halfWidth;
|
||||
go.transform.localPosition = new Vector3(x, 0f, 0f);
|
||||
x += halfWidth + margin;
|
||||
// Save
|
||||
var info = new MonitorInfo();
|
||||
info.gameObject = go;
|
||||
info.originalRotation = go.transform.rotation;
|
||||
info.uddTexture = texture;
|
||||
info.meshBounds = bounds;
|
||||
monitors_.Add(info);
|
||||
}
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
foreach (var go in monitors_) {
|
||||
Destroy(go);
|
||||
foreach (var info in monitors_) {
|
||||
Destroy(info.gameObject);
|
||||
}
|
||||
monitors_.Clear();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(MultipleMonitorCreator))]
|
||||
public class MultipleMonitorLayouter : MonoBehaviour
|
||||
{
|
||||
protected MultipleMonitorCreator creator_;
|
||||
[SerializeField] bool updateEveryFrame = true;
|
||||
[SerializeField] protected float margin = 0.1f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
creator_ = GetComponent<MultipleMonitorCreator>();
|
||||
Layout();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (updateEveryFrame) {
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
margin = Mathf.Max(margin, 0f);
|
||||
}
|
||||
|
||||
protected virtual void Layout()
|
||||
{
|
||||
var monitors = creator_.monitors;
|
||||
var n = monitors.Count;
|
||||
|
||||
var totalWidth = 0f;
|
||||
foreach (var info in monitors) {
|
||||
var width = info.uddTexture.monitor.widthMeter * info.meshBounds.x;
|
||||
totalWidth += width;
|
||||
}
|
||||
totalWidth += margin * (n - 1);
|
||||
|
||||
var x = -totalWidth / 2;
|
||||
|
||||
foreach (var info in creator_.monitors) {
|
||||
var monitor = info.uddTexture.monitor;
|
||||
x += (monitor.widthMeter * info.meshBounds.x) / 2;
|
||||
info.gameObject.transform.localPosition = new Vector3(x, 0f, 0f);
|
||||
info.gameObject.transform.localRotation = info.originalRotation;
|
||||
x += (monitor.widthMeter * info.meshBounds.x) / 2 + margin;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0db1dcac2dedc724194c423ee75b3bf4
|
||||
timeCreated: 1478608632
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
|
||||
{
|
||||
[SerializeField] float radius = 10f;
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
foreach (var info in creator_.monitors) {
|
||||
info.uddTexture.bend = uDesktopDuplication.Texture.Bend.Off;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Layout()
|
||||
{
|
||||
var monitors = creator_.monitors;
|
||||
var n = monitors.Count;
|
||||
|
||||
var totalWidth = 0f;
|
||||
foreach (var info in monitors) {
|
||||
var width = info.uddTexture.monitor.widthMeter * info.meshBounds.x;
|
||||
totalWidth += width;
|
||||
}
|
||||
totalWidth += margin * (n - 1);
|
||||
|
||||
radius = Mathf.Max(radius, (totalWidth + margin) / (2 * Mathf.PI));
|
||||
var totalAngle = totalWidth / radius;
|
||||
|
||||
float angle = -totalAngle / 2;
|
||||
foreach (var info in monitors) {
|
||||
var uddTex = info.uddTexture;
|
||||
var width = uddTex.monitor.widthMeter * info.meshBounds.x;
|
||||
|
||||
angle += (width / radius) * 0.5f;
|
||||
uddTex.transform.localPosition = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);
|
||||
uddTex.transform.localRotation = Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.up) * info.originalRotation;
|
||||
angle += (width * 0.5f + margin) / radius;
|
||||
|
||||
uddTex.bend = uDesktopDuplication.Texture.Bend.Y;
|
||||
uddTex.radius = radius;
|
||||
uddTex.width = uddTex.monitor.widthMeter;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
var scale = transform.localScale.x;
|
||||
var center = transform.position - Vector3.forward * radius * scale;
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
var a0 = 2 * Mathf.PI * i / 100;
|
||||
var a1 = 2 * Mathf.PI * (i + 1) / 100;
|
||||
var p0 = center + radius * scale * new Vector3(Mathf.Cos(a0), 0f, Mathf.Sin(a0));
|
||||
var p1 = center + radius * scale * new Vector3(Mathf.Cos(a1), 0f, Mathf.Sin(a1));
|
||||
Debug.DrawLine(p0, p1, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a31b05fdfa301f14e88365e64622b43a
|
||||
timeCreated: 1478524060
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,14 +8,13 @@ namespace uDesktopDuplication
|
||||
RequireComponent(typeof(Texture))]
|
||||
public class Cursor : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Vector2 modelScale = Vector2.one;
|
||||
|
||||
Vector3 worldPosition { get; set; }
|
||||
|
||||
private Texture uddTexture_;
|
||||
private Monitor monitor { get { return uddTexture_.monitor; } }
|
||||
|
||||
private Texture2D currentTexture_;
|
||||
private Dictionary<Vector2, Texture2D> textures_ = new Dictionary<Vector2, Texture2D>();
|
||||
[SerializeField] Vector2 modelScale = Vector2.one;
|
||||
private Dictionary<int, Texture2D> textures_ = new Dictionary<int, Texture2D>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -27,8 +26,8 @@ public class Cursor : MonoBehaviour
|
||||
if (monitor.isCursorVisible) {
|
||||
UpdatePosition();
|
||||
UpdateTexture();
|
||||
UpdateMaterial();
|
||||
}
|
||||
UpdateMaterial();
|
||||
}
|
||||
|
||||
void UpdatePosition()
|
||||
@@ -46,14 +45,14 @@ public class Cursor : MonoBehaviour
|
||||
var h = monitor.cursorShapeHeight;
|
||||
if (w == 0 || h == 0) return;
|
||||
|
||||
var scale = new Vector2(w, h);
|
||||
if (!textures_.ContainsKey(scale)) {
|
||||
var key = w + h * 100;
|
||||
if (!textures_.ContainsKey(key)) {
|
||||
var texture = new Texture2D(w, h, TextureFormat.BGRA32, false);
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
textures_.Add(scale, texture);
|
||||
textures_.Add(key, texture);
|
||||
}
|
||||
|
||||
var cursorTexture = textures_[scale];
|
||||
var cursorTexture = textures_[key];
|
||||
monitor.GetCursorTexture(cursorTexture.GetNativeTexturePtr());
|
||||
uddTexture_.material.SetTexture("_CursorTex", cursorTexture);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetMonitorCount();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetCursorMonitorId();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalWidth();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalHeight();
|
||||
|
||||
@@ -38,6 +38,11 @@ public class Manager : MonoBehaviour
|
||||
get { return Lib.GetMonitorCount(); }
|
||||
}
|
||||
|
||||
static public int cursorMonitorId
|
||||
{
|
||||
get { return Lib.GetCursorMonitorId(); }
|
||||
}
|
||||
|
||||
static public Monitor primary
|
||||
{
|
||||
get
|
||||
|
||||
@@ -196,7 +196,7 @@ public class Monitor
|
||||
Lib.GetCursorTexture(id, ptr);
|
||||
}
|
||||
|
||||
void CreateTexture()
|
||||
public void CreateTexture()
|
||||
{
|
||||
if (!available) return;
|
||||
|
||||
|
||||
@@ -24,9 +24,65 @@ public class Texture : MonoBehaviour
|
||||
set { monitor = Manager.monitors[Mathf.Clamp(value, 0, Manager.monitorCount - 1)]; }
|
||||
}
|
||||
|
||||
[Header("Invert UVs")]
|
||||
public bool invertX = false;
|
||||
public bool invertY = false;
|
||||
|
||||
[Header("Clip")]
|
||||
public bool useClip = false;
|
||||
public Vector2 clipPos = Vector2.zero;
|
||||
public Vector2 clipScale = new Vector2(0.2f, 0.2f);
|
||||
|
||||
public enum Bend
|
||||
{
|
||||
Off = 0,
|
||||
Y = 1,
|
||||
Z = 2,
|
||||
}
|
||||
|
||||
public Bend bend
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Bend)material.GetInt("_Bend");
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value) {
|
||||
case Bend.Off:
|
||||
material.SetInt("_Bend", 0);
|
||||
material.DisableKeyword("_BEND_OFF");
|
||||
material.DisableKeyword("_BEND_Y");
|
||||
material.DisableKeyword("_BEND_Z");
|
||||
break;
|
||||
case Bend.Y:
|
||||
material.SetInt("_Bend", 1);
|
||||
material.DisableKeyword("_BEND_OFF");
|
||||
material.EnableKeyword("_BEND_Y");
|
||||
material.DisableKeyword("_BEND_Z");
|
||||
break;
|
||||
case Bend.Z:
|
||||
material.SetInt("_Bend", 2);
|
||||
material.DisableKeyword("_BEND_OFF");
|
||||
material.DisableKeyword("_BEND_Y");
|
||||
material.EnableKeyword("_BEND_Z");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float radius
|
||||
{
|
||||
get { return material.GetFloat("_Radius"); }
|
||||
set { material.SetFloat("_Radius", value); }
|
||||
}
|
||||
|
||||
public float width
|
||||
{
|
||||
get { return material.GetFloat("_Width"); }
|
||||
set { material.SetFloat("_Width", value); }
|
||||
}
|
||||
|
||||
public Material material
|
||||
{
|
||||
get;
|
||||
@@ -55,6 +111,13 @@ public class Texture : MonoBehaviour
|
||||
}
|
||||
|
||||
void UpdateMaterial()
|
||||
{
|
||||
Invert();
|
||||
Rotate();
|
||||
Clip();
|
||||
}
|
||||
|
||||
void Invert()
|
||||
{
|
||||
if (invertX) {
|
||||
material.EnableKeyword("INVERT_X");
|
||||
@@ -67,7 +130,10 @@ public class Texture : MonoBehaviour
|
||||
} else {
|
||||
material.DisableKeyword("INVERT_Y");
|
||||
}
|
||||
}
|
||||
|
||||
void Rotate()
|
||||
{
|
||||
switch (monitor.rotation)
|
||||
{
|
||||
case MonitorRotation.Identity:
|
||||
@@ -94,6 +160,16 @@ public class Texture : MonoBehaviour
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Clip()
|
||||
{
|
||||
if (useClip) {
|
||||
material.EnableKeyword("USE_CLIP");
|
||||
material.SetVector("_ClipPositionScale", new Vector4(clipPos.x, clipPos.y, clipScale.x, clipScale.y));
|
||||
} else {
|
||||
material.DisableKeyword("USE_CLIP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#define UDD_COMMON_CGINC
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
@@ -48,6 +49,13 @@ float2 uddRotateUV(float2 uv)
|
||||
return uv;
|
||||
}
|
||||
|
||||
float2 uddClipUV(float2 uv)
|
||||
{
|
||||
uv.x = _ClipX + uv.x * _ClipWidth;
|
||||
uv.y = _ClipY + uv.y * _ClipHeight;
|
||||
return uv;
|
||||
}
|
||||
|
||||
inline void uddConvertToLinearIfNeeded(inout fixed3 rgb)
|
||||
{
|
||||
if (!IsGammaSpace()) {
|
||||
@@ -55,27 +63,30 @@ inline void uddConvertToLinearIfNeeded(inout fixed3 rgb)
|
||||
}
|
||||
}
|
||||
|
||||
inline fixed4 uddGetScreenTexture(sampler2D tex, float2 uv)
|
||||
inline fixed4 uddGetScreenTexture(float2 uv)
|
||||
{
|
||||
fixed4 c = tex2D(tex, uv);
|
||||
fixed4 c = tex2D(_MainTex, uv);
|
||||
return c;
|
||||
}
|
||||
|
||||
inline fixed4 uddGetCursorTexture(sampler2D tex, float2 uv, fixed4 cursorPosScale)
|
||||
inline fixed4 uddGetCursorTexture(float2 uv)
|
||||
{
|
||||
uv.x = (uv.x - cursorPosScale.x) / cursorPosScale.z;
|
||||
uv.y = (uv.y - cursorPosScale.y) / cursorPosScale.w;
|
||||
fixed4 c = tex2D(tex, uv);
|
||||
fixed a = c.a * step(0, uv.x) * step(0, uv.y) * step(uv.x, 1) * step(uv.y, 1);
|
||||
c *= step(0.01, a);
|
||||
uv.x = (uv.x - _CursorX) / _CursorWidth;
|
||||
uv.y = (uv.y - _CursorY) / _CursorHeight;
|
||||
fixed4 c = tex2D(_CursorTex, uv);
|
||||
fixed a = step(0, uv.x) * step(0, uv.y) * step(uv.x, 1) * step(uv.y, 1);
|
||||
c.a *= step(0.01, a);
|
||||
return c;
|
||||
}
|
||||
|
||||
inline fixed4 uddGetScreenTextureWithCursor(sampler2D screenTex, sampler2D cursorTex, float2 uv, fixed4 cursorPosScale)
|
||||
inline fixed4 uddGetScreenTextureWithCursor(float2 uv)
|
||||
{
|
||||
uv = uddInvertUV(uv);
|
||||
fixed4 screen = uddGetScreenTexture(screenTex, uddRotateUV(uv));
|
||||
fixed4 cursor = uddGetCursorTexture(cursorTex, uv, cursorPosScale);
|
||||
#ifdef USE_CLIP
|
||||
uv = uddClipUV(uv);
|
||||
#endif
|
||||
fixed4 screen = uddGetScreenTexture(uddRotateUV(uv));
|
||||
fixed4 cursor = uddGetCursorTexture(uv);
|
||||
fixed4 color = lerp(screen, cursor, cursor.a);
|
||||
uddConvertToLinearIfNeeded(color.rgb);
|
||||
return color;
|
||||
|
||||
@@ -4,7 +4,18 @@
|
||||
sampler2D _MainTex;
|
||||
fixed4 _Color;
|
||||
sampler2D _CursorTex;
|
||||
|
||||
half4 _CursorPositionScale;
|
||||
#define _CursorX _CursorPositionScale.x
|
||||
#define _CursorY _CursorPositionScale.y
|
||||
#define _CursorWidth _CursorPositionScale.z
|
||||
#define _CursorHeight _CursorPositionScale.w
|
||||
|
||||
half4 _ClipPositionScale;
|
||||
#define _ClipX _ClipPositionScale.x
|
||||
#define _ClipY _ClipPositionScale.y
|
||||
#define _ClipWidth _ClipPositionScale.z
|
||||
#define _ClipHeight _ClipPositionScale.w
|
||||
|
||||
#ifndef SURFACE_SHADER
|
||||
float4 _MainTex_ST;
|
||||
|
||||
@@ -22,19 +22,19 @@ SubShader
|
||||
#pragma surface surf Standard fullforwardshadows
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_BEND
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
|
||||
#define SURFACE_SHADER
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
half _Glossiness;
|
||||
half _Metallic;
|
||||
|
||||
void surf(Input IN, inout SurfaceOutputStandard o)
|
||||
{
|
||||
fixed4 c = uddGetScreenTextureWithCursor(_MainTex, _CursorTex, IN.uv_MainTex, _CursorPositionScale) * _Color;
|
||||
fixed4 c = uddGetScreenTextureWithCursor(IN.uv_MainTex) * _Color;
|
||||
o.Albedo = c.rgb;
|
||||
o.Metallic = _Metallic;
|
||||
o.Smoothness = _Glossiness;
|
||||
|
||||
@@ -5,8 +5,9 @@ Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
[Toggle(USE_BEND)] _UseBend("UseBend", Float) = 0
|
||||
[PowerSlider(10.0)]_Radius ("Radius", Range(10, 100)) = 30
|
||||
_CursorTex ("Cursor Texture", 2D) = "white" {}
|
||||
[KeywordEnum(Off, Y, Z)] _Bend("Bending", Int) = 0
|
||||
[PowerSlider(10.0)]_Radius ("Radius", Range(1, 100)) = 30
|
||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||
}
|
||||
|
||||
@@ -20,17 +21,21 @@ Cull [_Cull]
|
||||
CGINCLUDE
|
||||
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
fixed _Radius;
|
||||
half _Radius;
|
||||
half _Width;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
#ifdef USE_BEND
|
||||
half a = v.vertex.x / _Radius;
|
||||
v.vertex.x = _Radius * sin(a);
|
||||
#if defined(_BEND_Z) || defined(_BEND_Y)
|
||||
half a = _Width * v.vertex.x / _Radius;
|
||||
v.vertex.x = _Radius * sin(a) / _Width;
|
||||
#ifdef _BEND_Y
|
||||
v.vertex.y += _Radius * (1 - cos(a));
|
||||
#elif _BEND_Z
|
||||
v.vertex.z += _Radius * (1 - cos(a));
|
||||
#endif
|
||||
#endif
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
@@ -39,7 +44,7 @@ v2f vert(appdata v)
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
return uddGetScreenTextureWithCursor(_MainTex, _CursorTex, i.uv, _CursorPositionScale);
|
||||
return uddGetScreenTextureWithCursor(i.uv);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
@@ -51,9 +56,9 @@ Pass
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma shader_feature ___ USE_BEND
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
#pragma multi_compile _BEND_OFF _BEND_Y _BEND_Z
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ Blend SrcAlpha OneMinusSrcAlpha
|
||||
CGINCLUDE
|
||||
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
fixed _Mask;
|
||||
|
||||
@@ -35,7 +34,7 @@ v2f vert(appdata v)
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
fixed4 tex = uddGetScreenTextureWithCursor(_MainTex, _CursorTex, i.uv, _CursorPositionScale);
|
||||
fixed4 tex = uddGetScreenTextureWithCursor(i.uv);
|
||||
fixed alpha = pow((tex.r + tex.g + tex.b) / 3.0, _Mask);
|
||||
return fixed4(tex.rgb * _Color.rgb, alpha * _Color.a);
|
||||
}
|
||||
@@ -49,8 +48,9 @@ Pass
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_BEND
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ Blend SrcAlpha OneMinusSrcAlpha
|
||||
CGINCLUDE
|
||||
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
@@ -32,7 +31,7 @@ v2f vert(appdata v)
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
return fixed4(uddGetScreenTextureWithCursor(_MainTex, _CursorTex, i.uv, _CursorPositionScale).rgb, 1.0) * _Color;
|
||||
return fixed4(uddGetScreenTextureWithCursor(i.uv).rgb, 1.0) * _Color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
@@ -44,8 +43,9 @@ Pass
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_BEND
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,12 @@ void Cursor::UpdateBuffer(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
|
||||
x_ = frameInfo.PointerPosition.Position.x;
|
||||
y_ = frameInfo.PointerPosition.Position.y;
|
||||
if (frameInfo.PointerPosition.Visible != 0) {
|
||||
isVisible_ = frameInfo.PointerPosition.Visible != 0;
|
||||
timestamp_ = frameInfo.LastMouseUpdateTime;
|
||||
|
||||
if (isVisible_)
|
||||
{
|
||||
GetMonitorManager()->SetCursorMonitorId(monitor_->GetId());
|
||||
timestamp_ = frameInfo.LastMouseUpdateTime;
|
||||
isVisible_ = frameInfo.PointerPosition.Visible != 0;
|
||||
}
|
||||
|
||||
if (frameInfo.PointerShapeBufferSize == 0)
|
||||
@@ -163,8 +165,8 @@ void Cursor::UpdateTexture()
|
||||
const int i = row * w + col;
|
||||
const BYTE andMask = apiBuffer_[col / 8 + row * p] & mask;
|
||||
const BYTE xorMask = apiBuffer_[col / 8 + (row + h) * p] & mask;
|
||||
const UINT andMask32 = andMask ? 0xFFFFFFFF : 0xFF000000;
|
||||
const UINT xorMask32 = xorMask ? 0x00FFFFFF : 0x00000000;
|
||||
const UINT andMask32 = andMask ? 0xFFFFFFFF : 0x00000000;
|
||||
const UINT xorMask32 = xorMask ? 0xFFFFFFFF : 0x00000000;
|
||||
output32[i] = (desktop32[row * desktopPitch + col] & andMask32) ^ xorMask32;
|
||||
mask = (mask == 0x01) ? 0x80 : (mask >> 1);
|
||||
}
|
||||
@@ -217,7 +219,7 @@ void Cursor::UpdateTexture()
|
||||
|
||||
void Cursor::GetTexture(ID3D11Texture2D* texture)
|
||||
{
|
||||
if (bgra32Buffer_ == nullptr) return;
|
||||
if (bgra32Buffer_ == nullptr || texture == nullptr) return;
|
||||
ID3D11DeviceContext* context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->UpdateSubresource(texture, 0, nullptr, bgra32Buffer_, shapeInfo_.Width * 4, 0);
|
||||
|
||||
@@ -72,8 +72,6 @@ HRESULT Monitor::Render(UINT timeout)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if (unityTexture_ == nullptr) return 0;
|
||||
|
||||
IDXGIResource* resource = nullptr;
|
||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||
|
||||
@@ -97,18 +95,22 @@ HRESULT Monitor::Render(UINT timeout)
|
||||
return hr;
|
||||
}
|
||||
|
||||
ID3D11Texture2D* texture;
|
||||
resource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture));
|
||||
if (unityTexture_)
|
||||
{
|
||||
ID3D11Texture2D* texture;
|
||||
resource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture));
|
||||
|
||||
ID3D11DeviceContext* context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->CopyResource(unityTexture_, texture);
|
||||
context->Release();
|
||||
ID3D11DeviceContext* context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->CopyResource(unityTexture_, texture);
|
||||
context->Release();
|
||||
|
||||
resource->Release();
|
||||
}
|
||||
|
||||
cursor_->UpdateBuffer(frameInfo);
|
||||
cursor_->UpdateTexture();
|
||||
|
||||
resource->Release();
|
||||
deskDupl_->ReleaseFrame();
|
||||
|
||||
return S_OK;
|
||||
|
||||
@@ -118,6 +118,12 @@ extern "C"
|
||||
return g_manager->GetMonitorCount();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorMonitorId()
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorMonitorId();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalWidth()
|
||||
{
|
||||
if (!g_manager) return 0;
|
||||
|
||||
Reference in New Issue
Block a user