Compare commits

...

155 Commits

Author SHA1 Message Date
hecomi
81bc23d0bc fix bug that destroyed texture in non-main thread. 2016-12-01 22:34:35 +09:00
hecomi
583af4ff46 Change the way to get pixels and finish the implementation of the APIs 🎉 2016-12-01 22:29:52 +09:00
hecomi
7e3df8ec2e add GetPixels() and GetPixel() APIs (wip). 2016-11-30 02:40:16 +09:00
hecomi
32adf6c2d0 fix out-of-area bug. 2016-11-29 20:10:05 +09:00
hecomi
a24472bd92 fix cursor capture area bug. 2016-11-29 20:02:02 +09:00
hecomi
cfee22832a fix indent. 2016-11-28 02:31:55 +09:00
hecomi
9c467a0e6f fix indent. 2016-11-28 02:31:17 +09:00
hecomi
87557ed5ff refactoring. 2016-11-28 02:30:09 +09:00
hecomi
67c90073d9 fix unity log call from native. 2016-11-27 16:22:03 +09:00
hecomi
ce9c148282 remove unused code and fix minor bug. 2016-11-27 15:48:09 +09:00
hecomi
8201a22523 move cursor owner from monitor to manager. 2016-11-27 14:44:23 +09:00
hecomi
5cfbd70e0b output monitor orientation in log. 2016-11-27 13:54:42 +09:00
hecomi
f2b6a99af3 modify the mothod to check monitor orientation. 2016-11-26 18:11:02 +09:00
hecomi
c48bf7fecf add displacement mapping example. 2016-11-26 17:50:03 +09:00
hecomi
6673734b9c remove Cursor-related codes because they were handled directly in the native code. 2016-11-26 16:31:34 +09:00
hecomi
3364c19adf add displacement shader. 2016-11-26 16:14:00 +09:00
hecomi
f7eba2434f fix bug #2 that causes crash after returning from UAC. 2016-11-24 23:38:07 +09:00
hecomi
ddbfad6e95 upload cursor texture in native plugin. 2016-11-20 22:35:52 +09:00
hecomi
49aef432e7 improve performance. 2016-11-20 15:59:06 +09:00
hecomi
fc81892917 cache cursor texture pointer to improve performance. 2016-11-20 15:41:47 +09:00
hecomi
306a656c4e add gaze point analyzer for multiple monitors. 2016-11-20 15:15:19 +09:00
hecomi
faf65b4200 support hot-reload. 2016-11-20 14:32:31 +09:00
hecomi
ab25af516e do not loop generation of monitors in creator. 2016-11-20 12:38:24 +09:00
hecomi
45b0ab2cd8 save scale even after reinitialization. 2016-11-20 03:27:16 +09:00
hecomi
68227e9af6 remove unused debug log. 2016-11-20 03:03:40 +09:00
hecomi
be9871ba92 fix thickness bug. 2016-11-20 02:57:31 +09:00
hecomi
110d5d7bda fix boudary condition of cursor texture. 2016-11-20 02:54:38 +09:00
hecomi
533a4c9f28 add gaze point analyzer. 2016-11-20 02:49:58 +09:00
hecomi
88e8342d7a tweak scenes. 2016-11-19 21:55:25 +09:00
hecomi
72376b9e91 implement dirty rects and move rects. 2016-11-19 21:45:32 +09:00
hecomi
a10d5aa5c1 add buffer class. 2016-11-19 15:37:35 +09:00
hecomi
306185a1e9 add badges. 2016-11-19 13:56:16 +09:00
hecomi
60889d53f4 modify layouter to fix height. 2016-11-19 13:49:38 +09:00
hecomi
f207e65952 do not stop initialization even when getting dpi has error. 2016-11-19 13:09:50 +09:00
hecomi
aea8d112c6 fix indent. 2016-11-18 02:33:24 +09:00
hecomi
9f6971dd45 register callbacks. 2016-11-18 02:28:27 +09:00
hecomi
1be698af63 keep local scale of monitors as 1. 2016-11-18 00:19:22 +09:00
hecomi
064db9f137 modify access rights of layouter. 2016-11-17 23:31:39 +09:00
hecomi
166d172db2 modify access rights. 2016-11-17 23:23:22 +09:00
hecomi
95f8099392 capture cursor mask taking monitor rotation into consideration. 2016-11-17 23:19:46 +09:00
hecomi
9c62157c0c fix typo. 2016-11-16 02:27:57 +09:00
hecomi
be79e52135 fix cursor buffer bug. 2016-11-16 02:24:49 +09:00
hecomi
e9c8b4e571 modify component requirements. 2016-11-16 02:07:57 +09:00
hecomi
77c95ab1bb fix indent 2016-11-16 02:04:13 +09:00
hecomi
7b3990107d fix bugs. 2016-11-15 22:29:36 +09:00
hecomi
5c21b65afe reinitialize texture. 2016-11-15 22:02:00 +09:00
hecomi
e83f43d7fd fix crash bugs and memory leaks. 2016-11-15 21:50:35 +09:00
hecomi
58e14d76d8 make code more stable (still has crash bug). 2016-11-15 03:06:55 +09:00
hecomi
f8d8e64e46 modify codes. 2016-11-15 02:29:38 +09:00
hecomi
0a39e37659 add logs. 2016-11-15 01:00:26 +09:00
hecomi
931ff6b2db modify field order. 2016-11-14 00:04:43 +09:00
hecomi
75819f0a7d fix uv. 2016-11-13 23:43:05 +09:00
hecomi
d6ce41f9b6 remove version information from readme. 2016-11-13 23:28:03 +09:00
hecomi
9f8a026c24 add offset angle xyz. 2016-11-13 23:25:53 +09:00
hecomi
dc702c6e1d support option to choise real / fixed scale. 2016-11-13 23:18:00 +09:00
hecomi
5a3af11d08 add thickness control. 2016-11-13 22:58:14 +09:00
hecomi
0646621f73 modify utility icon. 2016-11-13 22:22:57 +09:00
hecomi
c9d6d3ad6a check texture sizes. 2016-11-13 22:22:33 +09:00
hecomi
78ee75a875 improve detection for monitor state change. 2016-11-13 22:15:22 +09:00
hecomi
c83ce50468 improve log. 2016-11-13 21:59:22 +09:00
hecomi
3567182a4d add dpi warning. 2016-11-13 11:12:45 +09:00
hecomi
e466aa65db add offset angle of roundly layouter. 2016-11-13 11:09:39 +09:00
hecomi
a0edc1a439 use system cursor position for zoom when cursor is invisible (e.g. dragging). 2016-11-12 16:28:33 +09:00
hecomi
1eb821b34d add unknown error. 2016-11-12 16:04:37 +09:00
hecomi
212d8ccb9b check zoom values. 2016-11-12 15:22:53 +09:00
hecomi
fac8fe1ea7 fix dpi zero bug. 2016-11-12 15:22:39 +09:00
hecomi
f90178f1db use inline. 2016-11-12 14:46:22 +09:00
hecomi
74e25f2bd7 add scene manager. 2016-11-12 14:38:13 +09:00
hecomi
70c126be6c fix monitor reinitialization bug. 2016-11-12 13:16:00 +09:00
hecomi
f74221bf75 update board. 2016-11-12 04:27:28 +09:00
hecomi
3a705732d1 improve bending. 2016-11-12 04:25:12 +09:00
hecomi
804bfb96bd add board-style screen. 2016-11-12 03:56:46 +09:00
hecomi
63d8f6936d use ComPtr for resources instead of standard smart pointers. 2016-11-12 02:44:20 +09:00
hecomi
e4e4917bcb fix manager non-initialization bug. 2016-11-12 02:05:09 +09:00
hecomi
0e205ecef7 fix zoom bug. 2016-11-12 02:00:04 +09:00
hecomi
cda8024b17 fix break in error image. 2016-11-12 00:40:11 +09:00
hecomi
05085f7d24 fix bug caused when releasing duplication output. 2016-11-10 23:33:19 +09:00
hecomi
52eafbe919 change unsupported texture. 2016-11-10 23:21:04 +09:00
hecomi
be1e0c25bb expand aabb to avoid culling. 2016-11-10 23:06:24 +09:00
hecomi
372e44d8c1 output logs. 2016-11-10 22:35:46 +09:00
hecomi
d79eb91333 fix freeze bug caused by masked cursor boundary conditions. 2016-11-10 02:50:59 +09:00
hecomi
f654df7f5b add debug logs and use safer code. 2016-11-09 21:58:00 +09:00
hecomi
620762dba7 add logging and use smart pointers for buffers. 2016-11-09 19:40:05 +09:00
hecomi
43ba445623 Merge branch 'master' of github.com:hecomi/uDesktopDuplication 2016-11-09 02:55:32 +09:00
hecomi
c7c12de730 move dll location. 2016-11-09 02:55:26 +09:00
hecomi
1086595d6b fix bug that did not remove unsupported monitor element in list. 2016-11-09 02:54:49 +09:00
hecomi
f69fb6a7bb remove monitor if unsupported. 2016-11-09 00:50:57 +09:00
hecomi
b661b4a93f modify zoom scene. 2016-11-09 00:23:25 +09:00
hecomi
8d9ef71829 update monitor id of loupe. 2016-11-09 00:18:52 +09:00
hecomi
fb7bcbfa5b change texture cache key. 2016-11-09 00:13:55 +09:00
hecomi
9ed8bb8d5b fix mouse cursor mono mask bug. 2016-11-09 00:02:43 +09:00
hecomi
fab67bbc61 add null check. 2016-11-08 23:28:37 +09:00
hecomi
5fa9f03a0e separate multiple monitors examples. 2016-11-08 22:10:47 +09:00
hecomi
941bb2da91 add round layout example. 2016-11-08 22:09:55 +09:00
hecomi
d423e0d1db remove collider from prefab. 2016-11-06 23:29:19 +09:00
hecomi
33a55d95bd add clipping function and the example. 2016-11-06 23:28:33 +09:00
hecomi
8e2d8d3218 fix cursor visibility bug. 2016-11-06 21:16:35 +09:00
hecomi
6ac1a5ee60 get dpi of monitor and calculate actual size of it. 2016-11-06 12:17:29 +09:00
hecomi
15a98cd774 fix singleton bug. 2016-11-06 11:55:01 +09:00
hecomi
06bb971a42 support display setting change in realtime. 2016-11-06 04:04:23 +09:00
hecomi
217e63d40c fix indent. 2016-11-06 03:33:21 +09:00
hecomi
9e42fb0abf there is only one cursor in screens. 2016-11-06 03:30:21 +09:00
hecomi
9de5064fbe do reinitialization from unity. 2016-11-06 00:39:07 +09:00
hecomi
2b108bd4b1 fix available getter bug. 2016-11-05 23:25:22 +09:00
hecomi
f9f8b14f46 show not-available texture when display is not available. 2016-11-05 23:15:57 +09:00
hecomi
7774290e71 fix text orientation. 2016-11-05 22:56:22 +09:00
hecomi
a3a7754fb0 remove unused cursor material and move icon to editor dir. 2016-11-05 22:44:17 +09:00
hecomi
0accebb657 add not-available texture. 2016-11-05 22:42:45 +09:00
hecomi
0a38eda14f update files. 2016-11-05 22:36:08 +09:00
hecomi
720f74e6f6 check unsupported display. 2016-11-05 22:34:11 +09:00
hecomi
80fa39f4eb remove unused debug.log. 2016-11-05 02:14:19 +09:00
hecomi
22b21ae3f4 check texture size before recreating it. 2016-11-05 01:44:26 +09:00
hecomi
43153266a0 rename members named pointer to cursor. 2016-11-05 01:40:20 +09:00
hecomi
dc4fe44342 support rotation 90/180/270 degs. 2016-11-05 01:33:29 +09:00
hecomi
6bb9846510 remove unnecessary debug.log. 2016-11-05 00:11:54 +09:00
hecomi
90b811cd31 add function to fetch left/right/top/bottom/rotation. 2016-11-05 00:09:04 +09:00
hecomi
1d7b7e8650 add bending test. 2016-11-04 23:29:40 +09:00
hecomi
6f784860e5 make shaders simpler. 2016-11-04 22:58:19 +09:00
hecomi
690dba23cc make shader one pass. 2016-11-04 22:45:57 +09:00
hecomi
908988dcaa tweak multiple monitors example. 2016-11-04 21:37:08 +09:00
hecomi
0f72396540 rename initialize/finalize to suppress warning. 2016-11-04 21:35:34 +09:00
hecomi
8f7659d7c2 build with release mode. 2016-11-04 19:28:47 +09:00
hecomi
2e763d994d prevent screen lost after admin screen. 2016-11-04 19:11:17 +09:00
hecomi
2c61fcd470 refactoring. 2016-11-04 15:45:35 +09:00
hecomi
f2cad8bf73 check cursor texture size. 2016-11-02 14:59:15 +09:00
hecomi
ad4b49c177 add scenes in build. 2016-11-02 14:13:04 +09:00
hecomi
92b926bcde remove cursor GameObject from Monitor.prefab. 2016-11-02 14:12:56 +09:00
hecomi
3e90889266 add culling option and fix cursor problem on transparent material. 2016-11-02 11:25:43 +09:00
hecomi
6531fe1dd6 create class for duplication. 2016-11-02 02:57:27 +09:00
hecomi
0b62376ac5 fix shader position. 2016-11-02 02:57:08 +09:00
hecomi
9f611d5d34 use release build. 2016-11-01 09:26:45 +09:00
hecomi
dd4e27030d remove unused file. 2016-11-01 02:37:05 +09:00
hecomi
4350ac3953 cache pointer texture. 2016-11-01 02:20:46 +09:00
hecomi
6ba381f5d4 fetch cursor texture. 2016-11-01 02:15:25 +09:00
hecomi
9287ef2f2d simplify duplication code. 2016-10-30 21:20:31 +09:00
hecomi
dc6b8bc204 fix vertical screen bug. 2016-10-30 19:56:22 +09:00
hecomi
14cd67e0c6 check if monitor is vertical or not. 2016-10-30 19:35:23 +09:00
hecomi
73018f671a add error code getter. 2016-10-30 19:35:00 +09:00
hecomi
7a27d86eff consider aspect ratio in Multiple Monitor scene. 2016-10-30 19:03:25 +09:00
hecomi
99e1774388 add Monitor.aspect. 2016-10-30 19:03:06 +09:00
hecomi
e0408d4749 fix line endings. 2016-10-30 18:42:16 +09:00
hecomi
23ceef6502 modify invert method. 2016-10-30 18:41:43 +09:00
hecomi
4317fc06e3 update .gitignore. 2016-10-30 18:41:30 +09:00
hecomi
f8cb71b472 fix typo. 2016-10-28 20:15:10 +09:00
hecomi
f1a7c302bd update .gitignore. 2016-10-28 20:15:03 +09:00
hecomi
ec82c49d7f fix toggle scene. 2016-10-28 19:41:44 +09:00
hecomi
f8146c15bd update readme. 2016-10-28 19:33:45 +09:00
hecomi
d5a9827b4d add toggle example. 2016-10-28 19:33:37 +09:00
hecomi
4b499a96de update readme. 2016-10-28 19:23:10 +09:00
hecomi
583326c333 add license. 2016-10-28 19:09:42 +09:00
hecomi
c3ec17dd7b add shader example. 2016-10-28 19:08:08 +09:00
hecomi
6f375e2e5b change class names. / add multiple screen example. / performance tuning. 2016-10-28 18:48:53 +09:00
hecomi
d9f83cf89e implement multiple screen. 2016-10-28 17:28:22 +09:00
hecomi
ba5ebe8094 update readme. 2016-10-27 19:19:45 +09:00
hecomi
1e2ac40507 support linear color. 2016-10-27 19:18:44 +09:00
123 changed files with 5175 additions and 368 deletions

4
.gitignore vendored
View File

@@ -4,6 +4,7 @@
/[Oo]bj/
/[Bb]uild/
/[Ww]iki/
/[Mm]isc/
# Autogenerated VS/MD solution and project files
*.csproj
@@ -24,3 +25,6 @@ sysinfo.txt
# Others
.DS_Store
/Assets/AssetStoreTools*
/Assets/Extensions*
/uDesktopDuplication.log

View File

@@ -1,7 +1,7 @@
fileFormatVersion: 2
guid: 48b92326b146fa848beec6f35365b1f4
guid: 022a80d652ef0304e84e9d6ac689e21f
folderAsset: yes
timeCreated: 1477555207
timeCreated: 1478353382
licenseType: Pro
DefaultImporter:
userData:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 678e1de5e6de7914baed516a78940503
folderAsset: yes
timeCreated: 1477643728
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +1,6 @@
fileFormatVersion: 2
guid: 033e0db89e0ca1d46a399c953629f67d
timeCreated: 1477555367
guid: de6f36e446e5e8a48bf61fe198985bb4
timeCreated: 1477643732
licenseType: Pro
NativeFormatImporter:
userData:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 57d4a6e606848364c9880f2adec16d90
timeCreated: 1480074774
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 42d6b6dbae38a384e882c2c907915139
timeCreated: 1478889784
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0a3456d4b2f59e84f969e31deca4016d
folderAsset: yes
timeCreated: 1477643596
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4e1efec2c71c5b94e8522880dd9636c8
timeCreated: 1480074355
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 38a5db360d5147c46ae925104162b881
timeCreated: 1480420198
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aac40d1b58f3f8940be815779d89b5a4
timeCreated: 1479544409
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4bae91f55031b98488c9e668031f7387
timeCreated: 1478610618
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 445860b05342be845967392bfd70224e
timeCreated: 1477643648
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f66b67cb0e751dc4ca0251b38bc8638d
timeCreated: 1477648784
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9ce9467b01f36d647ace156faef9cb9f
timeCreated: 1478927635
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 78e54899a518eb749a589b921a1b263f
timeCreated: 1477650252
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f3d41026babadc241b9d0852b0831584
timeCreated: 1478436298
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 71921882396f0f345aa8a66e2fcb0b6c
folderAsset: yes
timeCreated: 1477643608
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
using UnityEngine;
using UnityEngine.Assertions;
[RequireComponent(typeof(uDesktopDuplication.Texture))]
public class DisplacementMapping : MonoBehaviour
{
public enum TargetMonitor
{
Self,
Next,
Prev,
}
public TargetMonitor target = TargetMonitor.Self;
uDesktopDuplication.Texture uddTexture_;
int dispTexId_;
int dispFactorId_;
int tessMinDistId_;
int tessMaxDistId_;
int tessFactorId_;
[Range(0.0f, 10f)] public float displacementFactor = 0.1f;
[Range(0.1f, 10f)] public float tessellationMinDist = 0.5f;
[Range(1.0f, 50f)] public float tessellationMaxDist = 25f;
[Range(1.0f, 50f)] public float tessellationFactor = 25f;
void Start()
{
uddTexture_ = GetComponent<uDesktopDuplication.Texture>();
Assert.IsNotNull(uddTexture_);
dispTexId_ = Shader.PropertyToID("_DispTex");
dispFactorId_ = Shader.PropertyToID("_DispFactor");
tessMinDistId_ = Shader.PropertyToID("_TessMinDist");
tessMaxDistId_ = Shader.PropertyToID("_TessMaxDist");
tessFactorId_ = Shader.PropertyToID("_TessFactor");
}
void Update()
{
var id = uddTexture_.monitor.id;
switch (target) {
case TargetMonitor.Self: break;
case TargetMonitor.Next: ++id; break;
case TargetMonitor.Prev: --id; break;
}
id = Mathf.Clamp(id, 0, uDesktopDuplication.Manager.monitorCount - 1);
var monitor = uDesktopDuplication.Manager.GetMonitor(id);
monitor.shouldBeUpdated = true;
uddTexture_.material.SetTexture(dispTexId_, monitor.texture);
uddTexture_.material.SetFloat(dispFactorId_, displacementFactor);
uddTexture_.material.SetFloat(tessMinDistId_, tessellationMinDist);
uddTexture_.material.SetFloat(tessMaxDistId_, tessellationMaxDist);
uddTexture_.material.SetFloat(tessFactorId_, tessellationFactor);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 859a2446b86e55c43932212872c82748
timeCreated: 1480146517
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,168 @@
using UnityEngine;
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
[RequireComponent(typeof(uDesktopDuplication.Texture))]
public class GazePointAnalyzer : MonoBehaviour
{
uDesktopDuplication.Texture uddTexture_;
[Tooltip("This needs a small calculation cost.")]
public bool calcAveragePos = true;
private Vector2 averageCoord_ = Vector2.zero;
private Vector2 averageCoordVelocity_ = Vector2.zero;
public Vector3 averagePos
{
get { return GetWorldPositionFromCoord((int)averageCoord_.x, (int)averageCoord_.y); }
}
public Vector3 cursorPos
{
get { return GetWorldPositionFromCoord(uddTexture_.monitor.cursorX, uddTexture_.monitor.cursorY); }
}
private Vector2 preCursorCoord_ = Vector2.zero;
[Header("Filters")]
[Range(0f, 1f)] public float moveRectFilter = 0.05f;
[Range(0f, 1f)] public float mouseFilter = 0.05f;
[Range(0f, 1f)] public float dirtyRectFilter = 0.01f;
[Range(0f, 1f)] public float noEventFilter = 0.01f;
[Range(0f, 1f)] public float velocityFilter = 0.1f;
[Header("Debug")]
public bool drawAveragePos;
public bool drawCursorPos;
public bool drawMoveRects;
public bool drawDirtyRects;
void Start()
{
uddTexture_ = GetComponent<uDesktopDuplication.Texture>();
averageCoord_ = new Vector2(uddTexture_.monitor.width / 2, uddTexture_.monitor.height / 2);
}
public Vector3 GetWorldPositionFromCoord(int u, int v)
{
return uddTexture_.GetWorldPositionFromCoord(u, v);
}
void CalcAveragePos()
{
if (!calcAveragePos) return;
var coord = Vector2.zero;
var monitor = uddTexture_.monitor;
var cursorCoord = new Vector2(monitor.cursorX, monitor.cursorY);
var filter = 0f;
// move rect
if (monitor.moveRectCount > 0) {
foreach (var rects in monitor.moveRects) {
var rect = rects.destination;
var center = new Vector2(
(rect.right + rect.left) / 2,
(rect.bottom + rect.top) / 2);
coord += center;
}
coord /= monitor.moveRectCount;
filter = moveRectFilter;
}
// mouse
else if (
monitor.isCursorVisible &&
cursorCoord != preCursorCoord_ &&
(cursorCoord - preCursorCoord_).magnitude > 5 &&
monitor.cursorX >= 0 &&
monitor.cursorY >= 0)
{
coord = cursorCoord;
filter = mouseFilter;
}
// dirty rect
else if (monitor.dirtyRectCount > 0) {
var totalWeights = 0f;
foreach (var rect in monitor.dirtyRects) {
var center = new Vector2(
(rect.right + rect.left) / 2,
(rect.bottom + rect.top) / 2);
var weight = 1f / Mathf.Sqrt((rect.right - rect.left) * (rect.bottom - rect.top));
coord += center * weight;
totalWeights += weight;
}
coord /= totalWeights;
filter = dirtyRectFilter;
}
// no event
else {
coord = new Vector2(monitor.width / 2, monitor.height / 2);
filter = noEventFilter;
}
var cf = (filter / ((1f / 60) / Time.deltaTime));
var vf = (velocityFilter / ((1f / 60) / Time.deltaTime));
var targetCoord = averageCoord_ + (coord - averageCoord_) * cf;
var targetVelocity = targetCoord - averageCoord_;
if (float.IsNaN(targetCoord.x) || float.IsNaN(targetCoord.y)) return;
if (float.IsNaN(targetVelocity.x) || float.IsNaN(targetVelocity.y)) return;
averageCoordVelocity_ += (targetVelocity - averageCoordVelocity_) * vf;
averageCoord_ += averageCoordVelocity_;
averageCoord_.x = Mathf.Clamp(averageCoord_.x, 0, monitor.width);
averageCoord_.y = Mathf.Clamp(averageCoord_.y, 0, monitor.height);
preCursorCoord_ = cursorCoord;
}
void Update()
{
CalcAveragePos();
DebugDraw();
}
void DebugDraw()
{
if (drawAveragePos) DrawAveragePos();
if (drawCursorPos) DrawCursorPos();
if (drawDirtyRects) DrawDirtyRects();
if (drawMoveRects) DrawMoveRects();
}
void DrawRect(uDesktopDuplication.RECT rect, Color color)
{
var p0 = GetWorldPositionFromCoord(rect.left, rect.top);
var p1 = GetWorldPositionFromCoord(rect.right, rect.top);
var p2 = GetWorldPositionFromCoord(rect.right, rect.bottom);
var p3 = GetWorldPositionFromCoord(rect.left, rect.bottom);
Debug.DrawLine(p0, p1, color);
Debug.DrawLine(p1, p2, color);
Debug.DrawLine(p2, p3, color);
Debug.DrawLine(p3, p0, color);
}
void DrawAveragePos()
{
Debug.DrawLine(transform.position, averagePos, Color.yellow);
}
void DrawCursorPos()
{
Debug.DrawLine(transform.position, cursorPos, Color.grey);
}
void DrawMoveRects()
{
foreach (var rect in uddTexture_.monitor.moveRects) {
DrawRect(rect.source, Color.blue);
DrawRect(rect.destination, Color.green);
}
}
void DrawDirtyRects()
{
foreach (var rect in uddTexture_.monitor.dirtyRects) {
DrawRect(rect, Color.red);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 52d402bdca823cc42925c9d65993ee59
timeCreated: 1479546123
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
using UnityEngine;
public class GetPixelsExample : MonoBehaviour
{
[SerializeField] uDesktopDuplication.Texture uddTexture;
[SerializeField] int x = 100;
[SerializeField] int y = 100;
const int width = 64;
const int height = 32;
public Texture2D texture;
Color32[] colors = new Color32[width * height];
void Start()
{
texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
GetComponent<Renderer>().material.mainTexture = texture;
}
void Update()
{
// must be called (performance will be slightly down).
uDesktopDuplication.Manager.primary.useGetPixels = true;
var monitor = uddTexture.monitor;
if (!monitor.hasBeenUpdated) return;
if (monitor.GetPixels(colors, x, y, width, height)) {
texture.SetPixels32(colors);
texture.Apply();
}
Debug.Log(monitor.GetPixel(monitor.cursorX, monitor.cursorY));
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fd3f838ff57152e44a1810274a9df49b
timeCreated: 1480420430
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using UnityEngine;
[RequireComponent(typeof(uDesktopDuplication.Texture))]
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 LateUpdate()
{
CheckVariables();
if (uDesktopDuplication.Manager.cursorMonitorId < 0) return;
uddTexture_.monitorId = uDesktopDuplication.Manager.cursorMonitorId;
// To get other monitor textures, set dirty flag.
foreach (var target in uDesktopDuplication.Manager.monitors) {
target.CreateTextureIfNeeded();
target.shouldBeUpdated = true;
}
var monitor = uddTexture_.monitor;
var x = monitor.isCursorVisible ?
(float)monitor.cursorX / monitor.width :
(float)monitor.systemCursorX / monitor.width;
var y = monitor.isCursorVisible ?
(float)monitor.cursorY / monitor.height :
(float)monitor.systemCursorY / monitor.height;
var w = 1f / zoom;
var h = w / aspect * 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);
}
void CheckVariables()
{
if (zoom < 1f) zoom = 1f;
if (aspect < 0.01f) aspect = 0.01f;
}
}

View 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:

View File

@@ -0,0 +1,69 @@
using UnityEngine;
[RequireComponent(typeof(MultipleMonitorCreator))]
public class MultipleMonitorAnalyzer : MonoBehaviour
{
MultipleMonitorCreator creator_;
Vector3 gazePoint_ = Vector3.zero;
public Vector3 gazePoint
{
get { return gazePoint_; }
private set
{
gazePoint_ += (value - gazePoint) * (gazePointFilter / (1f / 60 / Time.deltaTime));
}
}
[Header("Filters")]
[Range(0f, 1f)] public float gazePointFilter = 0.1f;
[Range(0f, 1f)] public float moveRectFilter = 0.05f;
[Range(0f, 1f)] public float mouseFilter = 0.05f;
[Range(0f, 1f)] public float dirtyRectFilter = 0.01f;
[Range(0f, 1f)] public float noEventFilter = 0.01f;
[Range(0f, 1f)] public float velocityFilter = 0.1f;
[Header("Debug")]
[SerializeField] bool drawGazePoint;
[SerializeField] bool drawAveragePos;
[SerializeField] bool drawMoveRects;
[SerializeField] bool drawDirtyRects;
void Start()
{
creator_ = GetComponent<MultipleMonitorCreator>();
}
void Update()
{
var cursorMonitorId = uDesktopDuplication.Manager.cursorMonitorId;
for (int i = 0; i < creator_.monitors.Count; ++i) {
var info = creator_.monitors[i];
var analyzer =
info.gameObject.GetComponent<GazePointAnalyzer>() ??
info.gameObject.AddComponent<GazePointAnalyzer>();
UpdateAnalyzer(analyzer);
if (info.uddTexture.monitorId == cursorMonitorId) {
gazePoint = analyzer.averagePos;
}
}
if (drawGazePoint) DrawGazePoint();
}
void DrawGazePoint()
{
Debug.DrawLine(transform.position, gazePoint, Color.magenta);
}
void UpdateAnalyzer(GazePointAnalyzer analyzer)
{
analyzer.moveRectFilter = moveRectFilter;
analyzer.mouseFilter = mouseFilter;
analyzer.dirtyRectFilter = dirtyRectFilter;
analyzer.noEventFilter = noEventFilter;
analyzer.velocityFilter = velocityFilter;
analyzer.drawAveragePos = drawAveragePos;
analyzer.drawMoveRects = drawMoveRects;
analyzer.drawDirtyRects = drawDirtyRects;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dbdfccef47068644b81b671bb4e6e166
timeCreated: 1479620455
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,203 @@
using UnityEngine;
using UnityEngine.Assertions;
using System.Collections.Generic;
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
using MonitorState = uDesktopDuplication.MonitorState;
public class MultipleMonitorCreator : MonoBehaviour
{
[Tooltip("Create monitors using this prefab.")]
public GameObject monitorPrefab;
public enum ScaleMode
{
Real,
Fixed,
Pixel,
}
[Tooltip("Real: DPI-based real scale \nFixed: Same width \nPixel: bigger if screen resolution is high.")]
public ScaleMode scaleMode = ScaleMode.Fixed;
[Tooltip("Use this scale as width if scaleMode is Fixed.")]
public float scale = 0.5f;
[Tooltip("Please specify the surface direction of the mesh (e.g. Plane => Y.)")]
public MeshForwardDirection meshForwardDirection = MeshForwardDirection.Z;
[Tooltip("Remove unsupported monitors automatically after removeWaitDuration.")]
public bool removeIfUnsupported = true;
[Tooltip("Remove unsupported monitors automatically after removeWaitDuration.")]
public float removeWaitDuration = 5f;
[Tooltip("Remove all childrens (for debug).")]
public bool removeChildrenWhenClear = true;
bool hasMonitorUnsupportStateChecked_ = false;
float removeWaitTimer_ = 0f;
public class MonitorInfo
{
public GameObject gameObject { get; set; }
public Quaternion originalRotation { get; set; }
public Vector3 originalLocalScale { get; set; }
public uDesktopDuplication.Texture uddTexture { get; set; }
public Mesh mesh { get; set; }
}
private List<MonitorInfo> monitors_ = new List<MonitorInfo>();
public List<MonitorInfo> monitors { get { return monitors_; } }
public class SavedMonitorInfo
{
public float widthScale = 1f;
public float heightScale = 1f;
}
private List<SavedMonitorInfo> savedInfoList_ = new List<SavedMonitorInfo>();
public List<SavedMonitorInfo> savedInfoList { get { return savedInfoList_; } }
void Start()
{
uDesktopDuplication.Manager.CreateInstance();
Create();
}
void Update()
{
if (removeIfUnsupported) {
RemoveUnsupportedDisplayAfterRemoveTimer();
}
if (uDesktopDuplication.Manager.monitorCount != monitors.Count) {
Recreate();
}
}
void OnEnable()
{
uDesktopDuplication.Manager.onReinitialized += Recreate;
}
void OnDisable()
{
uDesktopDuplication.Manager.onReinitialized -= Recreate;
}
void RemoveUnsupportedDisplayAfterRemoveTimer()
{
if (!hasMonitorUnsupportStateChecked_) {
removeWaitTimer_ += Time.deltaTime;
if (removeWaitTimer_ > removeWaitDuration) {
hasMonitorUnsupportStateChecked_ = true;
foreach (var info in monitors) {
if (info.uddTexture.monitor.state == MonitorState.Unsupported) {
Destroy(info.gameObject);
}
}
monitors.RemoveAll(info => info.uddTexture.monitor.state == MonitorState.Unsupported);
}
}
}
void ResetRemoveTimer()
{
hasMonitorUnsupportStateChecked_ = false;
removeWaitTimer_ = 0f;
}
void Create()
{
ResetRemoveTimer();
// Create monitors
var n = uDesktopDuplication.Manager.monitors.Count;
for (int i = 0; i < n; ++i) {
// Create monitor obeject
var go = Instantiate(monitorPrefab);
go.name = "Monitor " + i;
// Saved infomation
if (savedInfoList.Count == i) {
savedInfoList.Add(new SavedMonitorInfo());
Assert.AreEqual(i, savedInfoList.Count - 1);
}
var savedInfo = savedInfoList[i];
// Expand AABB
var mesh = go.GetComponent<MeshFilter>().mesh; // clone
var aabbScale = mesh.bounds.size;
aabbScale.y = Mathf.Max(aabbScale.y, aabbScale.x);
aabbScale.z = Mathf.Max(aabbScale.z, aabbScale.x);
mesh.bounds = new Bounds(mesh.bounds.center, aabbScale);
// Assign monitor
var texture = go.GetComponent<uDesktopDuplication.Texture>();
texture.monitorId = i;
var monitor = texture.monitor;
// Set width / height
float width = 1f, height = 1f;
switch (scaleMode) {
case ScaleMode.Real:
width = monitor.widthMeter;
height = monitor.heightMeter;
break;
case ScaleMode.Fixed:
width = scale * (monitor.isHorizontal ? monitor.aspect : 1f);
height = scale * (monitor.isHorizontal ? 1f : 1f / monitor.aspect);
break;
case ScaleMode.Pixel:
width = scale * (monitor.isHorizontal ? 1f : monitor.aspect) * ((float)monitor.width / 1920);
height = scale * (monitor.isHorizontal ? 1f / monitor.aspect : 1f) * ((float)monitor.width / 1920);
break;
}
width *= savedInfo.widthScale;
height *= savedInfo.heightScale;
if (meshForwardDirection == MeshForwardDirection.Y) {
go.transform.localScale = new Vector3(width, go.transform.localScale.y, height);
} else {
go.transform.localScale = new Vector3(width, height, go.transform.localScale.z);
}
// Set parent as this object
go.transform.SetParent(transform);
// Save
var info = new MonitorInfo();
info.gameObject = go;
info.originalRotation = go.transform.rotation;
info.originalLocalScale = go.transform.localScale;
info.uddTexture = texture;
info.mesh = mesh;
monitors.Add(info);
}
// Sort monitors in coordinate order
monitors.Sort((a, b) => a.uddTexture.monitor.left - b.uddTexture.monitor.left);
}
void Clear()
{
foreach (var info in monitors) {
Destroy(info.gameObject);
}
if (removeChildrenWhenClear) {
for (int i = 0; i < transform.childCount; ++i) {
Destroy(transform.GetChild(i).gameObject);
}
}
monitors.Clear();
}
[ContextMenu("Recreate")]
public void Recreate()
{
Clear();
Create();
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fb22986017201f74aa864dcbf0cab751
timeCreated: 1477643778
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
using UnityEngine;
[RequireComponent(typeof(MultipleMonitorCreator))]
public class MultipleMonitorLayouter : MonoBehaviour
{
protected MultipleMonitorCreator creator_;
public bool updateEveryFrame = true;
public float margin = 0.1f;
[Range(0f, 10f)] public float thickness = 1f;
void Start()
{
creator_ = GetComponent<MultipleMonitorCreator>();
Layout();
}
protected virtual void Update()
{
margin = Mathf.Max(margin, 0f);
if (updateEveryFrame) {
Layout();
}
}
protected virtual void Layout()
{
var monitors = creator_.monitors;
var n = monitors.Count;
var totalWidth = 0f;
foreach (var info in monitors) {
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);
totalWidth += width;
}
totalWidth += margin * (n - 1);
var x = -totalWidth / 2;
foreach (var info in monitors) {
var width = info.gameObject.transform.localScale.x;
x += (width * info.mesh.bounds.extents.x);
info.gameObject.transform.localPosition = new Vector3(x, 0f, 0f);
info.gameObject.transform.localRotation = info.originalRotation;
x += (width * info.mesh.bounds.extents.x) + margin;
}
foreach (var info in monitors) {
info.uddTexture.thickness = thickness;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0db1dcac2dedc724194c423ee75b3bf4
timeCreated: 1478608632
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
using UnityEngine;
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
{
[SerializeField] bool debugDraw = true;
public float radius = 10f;
public Vector3 offsetAngle = Vector3.zero;
void OnDisable()
{
foreach (var info in creator_.monitors) {
info.uddTexture.bend = false;
}
}
protected override void Layout()
{
var monitors = creator_.monitors;
var n = monitors.Count;
// Keep the local scale z of monitors as 1 to bend them correctly.
// And save width / height to use same values after reinitialization.
for (int i = 0; i < n; ++i) {
var info = monitors[i];
var savedInfo = creator_.savedInfoList[i];
var scale = info.gameObject.transform.localScale;
if (creator_.meshForwardDirection == MeshForwardDirection.Y) {
scale.y = 1f;
savedInfo.widthScale = scale.x / info.originalLocalScale.x;
savedInfo.heightScale = scale.z / info.originalLocalScale.z;
} else {
scale.z = 1f;
savedInfo.widthScale = scale.x / info.originalLocalScale.x;
savedInfo.heightScale = scale.y / info.originalLocalScale.y;
}
info.gameObject.transform.localScale = scale;
}
// keep thicness plus value.
thickness = Mathf.Max(thickness, 0f);
// calculate total width
var totalWidth = 0f;
foreach (var info in monitors) {
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);
totalWidth += width;
}
totalWidth += margin * (n - 1);
// expand radius if total width is larger than the circumference.
radius = Mathf.Max(radius, (totalWidth + margin) / (2 * Mathf.PI));
// total angle of monitors
var totalAngle = totalWidth / radius;
// layout
float angle = -totalAngle / 2;
var offsetRot = Quaternion.Euler(offsetAngle);
foreach (var info in monitors) {
var uddTex = info.uddTexture;
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);
angle += (width / radius) * 0.5f;
var pos = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);
pos += radius * Vector3.forward;
pos = offsetRot * pos;
pos -= radius * Vector3.forward;
uddTex.transform.localPosition = pos;
uddTex.transform.localRotation = offsetRot * Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.up) * info.originalRotation;
angle += (width * 0.5f + margin) / radius;
uddTex.bend = true;
uddTex.meshForwardDirection = creator_.meshForwardDirection;
uddTex.radius = radius;
uddTex.thickness = thickness;
uddTex.width = uddTex.transform.localScale.x;
}
}
protected override void Update()
{
base.Update();
if (debugDraw) DebugDraw();
}
void DebugDraw()
{
// draw the circumference in the scene view.
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);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a31b05fdfa301f14e88365e64622b43a
timeCreated: 1478524060
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using UnityEngine;
public class ToggleMonitors : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown(KeyCode.Tab)) {
var texture = GetComponent<uDesktopDuplication.Texture>();
var id = texture.monitorId;
var n = uDesktopDuplication.Manager.monitorCount;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) {
texture.monitorId = (id - 1 < 0) ? 0 : (id - 1);
} else {
texture.monitorId = (id + 1 >= n) ? (n - 1) : (id + 1);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 602d3a9bed585d14eaf21e0528d24d54
timeCreated: 1477650268
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class UddSceneManager : MonoBehaviour
{
public static UddSceneManager instance { get; set; }
[SerializeField] string[] scenes;
[SerializeField] int sceneNo = 0;
void Awake()
{
if (!instance) {
instance = this;
} else {
Destroy(gameObject);
}
}
void Start()
{
DontDestroyOnLoad(gameObject);
Load();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.RightArrow)) {
Next();
} else if (Input.GetKeyDown(KeyCode.LeftArrow)) {
Prev();
}
if (Input.GetKeyDown(KeyCode.R) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) {
uDesktopDuplication.Manager.instance.Reinitialize();
}
if (Input.GetKeyDown(KeyCode.Escape)) {
Application.Quit();
}
}
void Next()
{
sceneNo = (sceneNo + 1) % scenes.Length;
Load();
}
void Prev()
{
sceneNo = (sceneNo - 1) % scenes.Length;
Load();
}
void Load()
{
SceneManager.LoadScene(scenes[Mathf.Clamp(sceneNo, 0, scenes.Length - 1)]);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 426ff762e9c02b0499e1453018ecdc94
timeCreated: 1478927673
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 06ef13d14bbcf9242a8eba19a94803f3
timeCreated: 1477648806
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3abaadab838fb3c4ba342eda7431d4f7
timeCreated: 1477648806
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 596fd740aeeee0d4cb4f962d4072954e
timeCreated: 1480074277
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 647550562f402264fb69871ec732b74c
timeCreated: 1477648806
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 75494e992a22ea44d9b614d7fd3dc235
folderAsset: yes
timeCreated: 1478887431
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b281589e6b8e27b4fbf0509d620b7871
folderAsset: yes
timeCreated: 1478354860
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e36cd526b654d024e875d5110a1b0442
folderAsset: yes
timeCreated: 1478354877
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0e2bcc27e10c0d141a0c11cd88cdcf98
folderAsset: yes
timeCreated: 1478353263
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@@ -0,0 +1,59 @@
fileFormatVersion: 2
guid: 9855ecfc2b823c94d8a1354715d343a1
timeCreated: 1478353264
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 7
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: -1
buildTargetSettings: []
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,78 @@
fileFormatVersion: 2
guid: d6b30b913257fee4d8246bf7a2620fcd
timeCreated: 1478887431
licenseType: Pro
ModelImporter:
serializedVersion: 19
fileIDToRecycleName:
100000: //RootNode
400000: //RootNode
2300000: //RootNode
3300000: //RootNode
4300000: pCube1
4300002: uDD_Board
9500000: //RootNode
materials:
importMaterials: 0
materialName: 0
materialSearch: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleCurves: 1
optimizeGameObjects: 0
motionNodeName:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
clipAnimations: []
isReadable: 0
meshes:
lODScreenPercentages: []
globalScale: 0.1
meshCompression: 0
addColliders: 0
importBlendShapes: 0
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
optimizeMeshForGPU: 0
keepQuads: 0
weldVertices: 1
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVPackMargin: 4
useFileScale: 1
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
tangentImportMode: 2
importAnimation: 0
copyAvatar: 0
humanDescription:
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
rootMotionBoneName:
hasTranslationDoF: 0
lastHumanDescriptionAvatarSource: {instanceID: 0}
animationType: 0
humanoidOversampling: 1
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,87 @@
fileFormatVersion: 2
guid: f30f6cfd6aa37554ca886424cada7cbb
timeCreated: 1480072865
licenseType: Pro
ModelImporter:
serializedVersion: 19
fileIDToRecycleName:
100000: //RootNode
100002: uDD_Plane_MeshPart0
100004: uDD_Plane_MeshPart1
400000: //RootNode
400002: uDD_Plane_MeshPart0
400004: uDD_Plane_MeshPart1
2300000: //RootNode
2300002: uDD_Plane_MeshPart0
2300004: uDD_Plane_MeshPart1
3300000: //RootNode
3300002: uDD_Plane_MeshPart0
3300004: uDD_Plane_MeshPart1
4300000: uDD_Plane
4300002: uDD_Plane_MeshPart0
4300004: uDD_Plane_MeshPart1
9500000: //RootNode
materials:
importMaterials: 0
materialName: 0
materialSearch: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleCurves: 1
optimizeGameObjects: 0
motionNodeName:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
clipAnimations: []
isReadable: 0
meshes:
lODScreenPercentages: []
globalScale: 0.1
meshCompression: 0
addColliders: 0
importBlendShapes: 0
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
optimizeMeshForGPU: 1
keepQuads: 0
weldVertices: 1
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVPackMargin: 4
useFileScale: 1
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
tangentImportMode: 2
importAnimation: 0
copyAvatar: 0
humanDescription:
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
rootMotionBoneName:
hasTranslationDoF: 0
lastHumanDescriptionAvatarSource: {instanceID: 0}
animationType: 0
humanoidOversampling: 1
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 99257566ccd0582439a44abad90e65d4
folderAsset: yes
timeCreated: 1478626361
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,239 @@
using UnityEngine;
using System;
using System.Text;
using System.Runtime.InteropServices;
#pragma warning disable 114, 465
namespace uDesktopDuplication
{
public enum Message
{
None = -1,
Reinitialized = 0,
TextureSizeChanged = 1,
}
public enum CursorShapeType
{
Unspecified = 0,
MonoChrome = 1,
Color = 2,
MaskedColor = 4,
}
public enum MonitorRotation
{
Unspecified = 0,
Identity = 1,
Rotate90 = 2,
Rotate180 = 3,
Rotate270 = 4
}
public enum MonitorState
{
NotSet = -1,
Available = 0,
InvalidArg = 1,
AccessDenied = 2,
Unsupported = 3,
CurrentlyNotAvailable = 4,
SessionDisconnected = 5,
AccessLost = 6,
TextureSizeInconsistent = 7,
Unknown = 999,
}
public enum DebugMode
{
None = 0,
File = 1,
UnityLog = 2, /* currently has bug when app exits. */
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
[MarshalAs(UnmanagedType.I4)]
public int left;
[MarshalAs(UnmanagedType.I4)]
public int top;
[MarshalAs(UnmanagedType.I4)]
public int right;
[MarshalAs(UnmanagedType.I4)]
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct DXGI_OUTDUPL_MOVE_RECT
{
public RECT source;
public RECT destination;
}
public static class Lib
{
public delegate void MessageHandler(Message message);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void DebugLogDelegate(string str);
[DllImport("uDesktopDuplication")]
public static extern bool IsInitialized();
[DllImport("uDesktopDuplication")]
public static extern void Initialize();
[DllImport("uDesktopDuplication")]
public static extern void Finalize();
[DllImport("uDesktopDuplication")]
public static extern void Reinitialize();
[DllImport("uDesktopDuplication")]
public static extern void Update();
[DllImport("uDesktopDuplication")]
public static extern Message PopMessage();
[DllImport("uDesktopDuplication")]
public static extern void EnableDebug();
[DllImport("uDesktopDuplication")]
public static extern void DisableDebug();
[DllImport("uDesktopDuplication")]
public static extern void SetDebugMode(DebugMode mode);
[DllImport("uDesktopDuplication")]
public static extern void SetLogFunc(DebugLogDelegate func);
[DllImport("uDesktopDuplication")]
public static extern void SetErrorFunc(DebugLogDelegate func);
[DllImport("uDesktopDuplication")]
public static extern int GetMonitorCount();
[DllImport("uDesktopDuplication")]
public static extern bool HasMonitorCountChanged();
[DllImport("uDesktopDuplication")]
public static extern int GetCursorMonitorId();
[DllImport("uDesktopDuplication")]
public static extern int GetTotalWidth();
[DllImport("uDesktopDuplication")]
public static extern int GetTotalHeight();
[DllImport("uDesktopDuplication")]
public static extern void SetTimeout(int timeout);
[DllImport("uDesktopDuplication")]
public static extern IntPtr GetRenderEventFunc();
[DllImport("uDesktopDuplication")]
public static extern int GetId(int id);
[DllImport("uDesktopDuplication")]
public static extern MonitorState GetState(int id);
[DllImport("uDesktopDuplication")]
public static extern void GetName(int id, StringBuilder buf, int len);
[DllImport("uDesktopDuplication")]
public static extern int GetLeft(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetRight(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetTop(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetBottom(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetWidth(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetHeight(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetDpiX(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetDpiY(int id);
[DllImport("uDesktopDuplication")]
public static extern MonitorRotation GetRotation(int id);
[DllImport("uDesktopDuplication")]
public static extern bool IsPrimary(int id);
[DllImport("uDesktopDuplication")]
public static extern bool IsCursorVisible(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetCursorX();
[DllImport("uDesktopDuplication")]
public static extern int GetCursorY();
[DllImport("uDesktopDuplication")]
public static extern int GetCursorShapeWidth();
[DllImport("uDesktopDuplication")]
public static extern int GetCursorShapeHeight();
[DllImport("uDesktopDuplication")]
public static extern int GetCursorShapePitch();
[DllImport("uDesktopDuplication")]
public static extern CursorShapeType GetCursorShapeType();
[DllImport("uDesktopDuplication")]
public static extern void GetCursorTexture(int id, System.IntPtr ptr);
[DllImport("uDesktopDuplication")]
public static extern int SetTexturePtr(int id, IntPtr ptr);
[DllImport("uDesktopDuplication")]
public static extern int GetMoveRectCount(int id);
[DllImport("uDesktopDuplication", EntryPoint = "GetMoveRects")]
private static extern IntPtr GetMoveRects_Internal(int id);
[DllImport("uDesktopDuplication")]
public static extern int GetDirtyRectCount(int id);
[DllImport("uDesktopDuplication", EntryPoint = "GetDirtyRects")]
private static extern IntPtr GetDirtyRects_Internal(int id);
[DllImport("uDesktopDuplication", EntryPoint = "GetPixels")]
private static extern bool GetPixels_Internal(int id, System.IntPtr ptr, int x, int y, int width, int height);
[DllImport("uDesktopDuplication")]
public static extern bool HasBeenUpdated(int id);
[DllImport("uDesktopDuplication")]
public static extern bool UseGetPixels(int id, bool use);
public static string GetName(int id)
{
var buf = new StringBuilder(32);
GetName(id, buf, buf.Capacity);
return buf.ToString();
}
public static DXGI_OUTDUPL_MOVE_RECT[] GetMoveRects(int id)
{
var count = GetMoveRectCount(id);
var rects = new DXGI_OUTDUPL_MOVE_RECT[count];
var ptr = GetMoveRects_Internal(id);
var size = Marshal.SizeOf(typeof(DXGI_OUTDUPL_MOVE_RECT));
for (int i = 0; i < count; ++i) {
var data = new IntPtr(ptr.ToInt64() + size * i);
rects[i] = (DXGI_OUTDUPL_MOVE_RECT)Marshal.PtrToStructure(data, typeof(DXGI_OUTDUPL_MOVE_RECT));
}
return rects;
}
public static RECT[] GetDirtyRects(int id)
{
var count = GetDirtyRectCount(id);
var rects = new RECT[count];
var ptr = GetDirtyRects_Internal(id);
var size = Marshal.SizeOf(typeof(RECT));
for (int i = 0; i < count; ++i) {
var data = new IntPtr(ptr.ToInt64() + size * i);
rects[i] = (RECT)Marshal.PtrToStructure(data, typeof(RECT));
}
return rects;
}
public static Color32[] GetPixels(int id, int x, int y, int width, int height)
{
var color = new Color32[width * height];
GetPixels(id, color, x, y, width, height);
return color;
}
public static bool GetPixels(int id, Color32[] colors, int x, int y, int width, int height)
{
if (colors.Length < width * height) {
Debug.LogErrorFormat("colors is small.", id, x, y, width, height);
return false;
}
var handle = GCHandle.Alloc(colors, GCHandleType.Pinned);
var ptr = handle.AddrOfPinnedObject();
if (!GetPixels_Internal(id, ptr, x, y, width, height)) {
Debug.LogErrorFormat("GetPixels({0}, {1}, {2}, {3}, {4}) failed.", id, x, y, width, height);
return false;
}
handle.Free();
return true;
}
public static Color32 GetPixel(int id, int x, int y)
{
return GetPixels(id, x, y, 1, 1)[0];
}
}
}

View File

@@ -1,6 +1,6 @@
fileFormatVersion: 2
guid: d2d9e4ca459ecb44da8815bafe9655c5
timeCreated: 1477559806
guid: cb02196c3e766c14ba398dc130e443e8
timeCreated: 1477643164
licenseType: Pro
MonoImporter:
serializedVersion: 2

View File

@@ -0,0 +1,258 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace uDesktopDuplication
{
public class Manager : MonoBehaviour
{
private static Manager instance_;
public static Manager instance
{
get { return CreateInstance(); }
}
public static Manager CreateInstance()
{
if (instance_ != null) return instance_;
var manager = FindObjectOfType<Manager>();
if (manager) {
instance_ = manager;
return manager;
}
var go = new GameObject("uDesktopDuplicationManager");
instance_ = go.AddComponent<Manager>();
return instance_;
}
private List<Monitor> monitors_ = new List<Monitor>();
static public List<Monitor> monitors
{
get { return instance.monitors_; }
}
static public int monitorCount
{
get { return Lib.GetMonitorCount(); }
}
static public int cursorMonitorId
{
get { return Lib.GetCursorMonitorId(); }
}
static public Monitor primary
{
get
{
return instance.monitors_.Find(monitor => monitor.isPrimary);
}
}
[Tooltip("Debug mode is not applied while running.")]
[SerializeField] DebugMode debugMode = DebugMode.File;
[SerializeField] int desktopDuplicationApiTimeout = 0;
[SerializeField] float retryReinitializationDuration = 1f;
private Coroutine renderCoroutine_ = null;
private bool shouldReinitialize_ = false;
private float reinitializationTimer_ = 0f;
private bool isFirstFrame_ = true;
public static event Lib.DebugLogDelegate onDebugLog = msg => Debug.Log(msg);
public static event Lib.DebugLogDelegate onDebugErr = msg => Debug.LogError(msg);
public delegate void ReinitializeHandler();
public static event ReinitializeHandler onReinitialized;
public static Monitor GetMonitor(int id)
{
if (id < 0 || id >= Manager.monitors.Count) {
Debug.LogErrorFormat("[uDD::Error] there is no monitor whose id is {0}.", id);
return Manager.primary;
}
return monitors[Mathf.Clamp(id, 0, Manager.monitorCount - 1)];
}
void Awake()
{
// for simple singleton
if (instance_ == this) {
return;
}
if (instance_ != null && instance_ != this) {
Destroy(gameObject);
return;
}
instance_ = this;
Lib.SetDebugMode(debugMode);
Lib.SetLogFunc(onDebugLog);
Lib.SetErrorFunc(onDebugErr);
Lib.SetTimeout(desktopDuplicationApiTimeout);
Lib.Initialize();
CreateMonitors();
}
void OnApplicationQuit()
{
Lib.Finalize();
DestroyMonitors();
}
void OnEnable()
{
renderCoroutine_ = StartCoroutine(OnRender());
if (!isFirstFrame_) {
Reinitialize();
}
Lib.SetDebugMode(debugMode);
Lib.SetLogFunc(onDebugLog);
}
void OnDisable()
{
if (renderCoroutine_ != null) {
StopCoroutine(renderCoroutine_);
renderCoroutine_ = null;
}
Lib.SetLogFunc(null);
Lib.SetErrorFunc(null);
}
void Update()
{
Lib.Update();
ReinitializeIfNeeded();
UpdateMessage();
isFirstFrame_ = false;
}
[ContextMenu("Reinitialize")]
public void Reinitialize()
{
Debug.Log("[uDD] Reinitialize");
Lib.Reinitialize();
CreateMonitors();
if (onReinitialized != null) {
onReinitialized();
}
}
void ReinitializeIfNeeded()
{
bool reinitializeNeeded = false;
for (int i = 0; i < monitors.Count; ++i) {
var monitor = monitors[i];
var state = monitor.state;
if (
state == MonitorState.NotSet ||
state == MonitorState.AccessLost ||
state == MonitorState.AccessDenied ||
state == MonitorState.SessionDisconnected ||
state == MonitorState.Unknown
) {
reinitializeNeeded = true;
break;
}
}
if (Lib.HasMonitorCountChanged()) {
reinitializeNeeded = true;
}
if (!shouldReinitialize_ && reinitializeNeeded) {
shouldReinitialize_ = true;
reinitializationTimer_ = 0f;
}
if (shouldReinitialize_) {
if (reinitializationTimer_ > retryReinitializationDuration) {
Reinitialize();
shouldReinitialize_ = false;
}
reinitializationTimer_ += Time.deltaTime;
}
}
void UpdateMessage()
{
var message = Lib.PopMessage();
while (message != Message.None) {
Debug.Log("[uDD] " + message);
switch (message) {
case Message.Reinitialized:
ReinitializeMonitors();
break;
case Message.TextureSizeChanged:
RecreateTextures();
break;
default:
break;
}
message = Lib.PopMessage();
}
}
IEnumerator OnRender()
{
for (;;) {
yield return new WaitForEndOfFrame();
for (int i = 0; i < monitors.Count; ++i) {
var monitor = monitors[i];
if (monitor.shouldBeUpdated) {
monitor.Render();
}
monitor.shouldBeUpdated = false;
}
}
}
void CreateMonitors()
{
DestroyMonitors();
for (int i = 0; i < monitorCount; ++i) {
monitors.Add(new Monitor(i));
}
}
void DestroyMonitors()
{
for (int i = 0; i < monitors.Count; ++i) {
monitors[i].DestroyTexture();
}
monitors.Clear();
}
void ReinitializeMonitors()
{
for (int i = 0; i < monitorCount; ++i) {
if (i == monitors.Count) {
monitors.Add(new Monitor(i));
} else {
monitors[i].Reinitialize();
}
}
}
void RecreateTextures()
{
for (int i = 0; i < monitorCount; ++i) {
monitors[i].CreateTextureIfNeeded();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4dccb434f55ebee4f91bfb9935092bbf
timeCreated: 1477643174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 89616e59e1cccb346bd4e959257990ca, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,367 @@
using UnityEngine;
namespace uDesktopDuplication
{
public class Monitor
{
public Monitor(int id)
{
this.id = id;
switch (state)
{
case MonitorState.Available:
break;
case MonitorState.InvalidArg:
Debug.LogErrorFormat("[uDD] {0}:{1} => Invalid.", id, name);
break;
case MonitorState.AccessDenied:
Debug.LogWarningFormat("[uDD] {0}:{1} => Access Denied.", id, name);
break;
case MonitorState.Unsupported:
Debug.LogWarningFormat("[uDD] {0}:{1} => Unsupported.", id, name);
break;
case MonitorState.SessionDisconnected:
Debug.LogWarningFormat("[uDD] {0}:{1} => Disconnected.", id, name);
break;
case MonitorState.NotSet:
Debug.LogErrorFormat("[uDD] {0}:{1} => Something wrong.", id, name);
break;
default:
Debug.LogErrorFormat("[uDD] {0}:{1} => Unknown error.", id, name);
break;
}
if (dpiX == 0 || dpiY == 0) {
Debug.LogWarningFormat("[uDD] {0}:{1} => Could not get DPI", id, name);
}
}
~Monitor()
{
}
public int id
{
get;
private set;
}
public bool exists
{
get { return id < Manager.monitorCount; }
}
public MonitorState state
{
get { return Lib.GetState(id); }
}
public bool available
{
get { return state == MonitorState.Available; }
}
public string name
{
get { return Lib.GetName(id); }
}
public bool isPrimary
{
get { return Lib.IsPrimary(id); }
}
public int left
{
get { return Lib.GetLeft(id); }
}
public int right
{
get { return Lib.GetRight(id); }
}
public int top
{
get { return Lib.GetTop(id); }
}
public int bottom
{
get { return Lib.GetBottom(id); }
}
public int width
{
get { return Lib.GetWidth(id); }
}
public int height
{
get { return Lib.GetHeight(id); }
}
public int dpiX
{
get
{
var dpi = Lib.GetDpiX(id);
if (dpi == 0) dpi = 100; // when monitors are duplicated
return dpi;
}
}
public int dpiY
{
get
{
var dpi = Lib.GetDpiY(id);
if (dpi == 0) dpi = 100; // when monitors are duplicated
return dpi;
}
}
public float widthMeter
{
get { return width / dpiX * 0.0254f; }
}
public float heightMeter
{
get { return height / dpiY * 0.0254f; }
}
public MonitorRotation rotation
{
get { return Lib.GetRotation(id); }
}
public float aspect
{
get { return (float)width / height; }
}
public bool isHorizontal
{
get
{
return
(rotation == MonitorRotation.Identity) ||
(rotation == MonitorRotation.Rotate180);
}
}
public bool isVertical
{
get
{
return
(rotation == MonitorRotation.Rotate90) ||
(rotation == MonitorRotation.Rotate270);
}
}
public bool isCursorVisible
{
get { return Lib.IsCursorVisible(id); }
}
public int cursorX
{
get { return Lib.GetCursorMonitorId() == id ? Lib.GetCursorX() : -1; }
}
public int cursorY
{
get { return Lib.GetCursorMonitorId() == id ? Lib.GetCursorY() : -1; }
}
public int systemCursorX
{
get
{
var p = Utility.GetCursorPos();
return p.x - left;
}
}
public int systemCursorY
{
get
{
var p = Utility.GetCursorPos();
return p.y - top;
}
}
public int cursorShapeWidth
{
get { return Lib.GetCursorShapeWidth(); }
}
public int cursorShapeHeight
{
get { return Lib.GetCursorShapeHeight(); }
}
public CursorShapeType cursorShapeType
{
get { return Lib.GetCursorShapeType(); }
}
public int moveRectCount
{
get { return Lib.GetMoveRectCount(id); }
}
public DXGI_OUTDUPL_MOVE_RECT[] moveRects
{
get { return Lib.GetMoveRects(id); }
}
public int dirtyRectCount
{
get { return Lib.GetDirtyRectCount(id); }
}
public RECT[] dirtyRects
{
get { return Lib.GetDirtyRects(id); }
}
public bool hasBeenUpdated
{
get { return Lib.HasBeenUpdated(id); }
}
bool useGetPixels_ = false;
public bool useGetPixels
{
get
{
return useGetPixels_;
}
set
{
useGetPixels_ = value;
Lib.UseGetPixels(id, value);
}
}
public bool shouldBeUpdated
{
get;
set;
}
private static Texture2D errorTexture_;
private static readonly string errorTexturePath = "uDesktopDuplication/Textures/NotAvailable";
private Texture2D errorTexture
{
get
{
return errorTexture_ ??
(errorTexture_ = Resources.Load<Texture2D>(errorTexturePath));
}
}
private Texture2D texture_;
private System.IntPtr texturePtr_;
public Texture2D texture
{
get
{
if (!available) return errorTexture;
if (texture_ == null) CreateTextureIfNeeded();
return texture_;
}
}
public void Render()
{
if (texture_ && available && texturePtr_ != System.IntPtr.Zero) {
Lib.SetTexturePtr(id, texturePtr_);
GL.IssuePluginEvent(Lib.GetRenderEventFunc(), id);
}
}
public void GetCursorTexture(System.IntPtr ptr)
{
Lib.GetCursorTexture(id, ptr);
}
public void CreateTextureIfNeeded()
{
if (!available) return;
var w = isHorizontal ? width : height;
var h = isHorizontal ? height : width;
bool shouldCreate = true;
if (texture_ && texture_.width == w && texture_.height == h) {
shouldCreate = false;
}
if (w <= 0 || h <= 0) {
shouldCreate = false;
}
if (shouldCreate) {
CreateTexture();
}
}
void CreateTexture()
{
DestroyTexture();
var w = isHorizontal ? width : height;
var h = isHorizontal ? height : width;
texture_ = new Texture2D(w, h, TextureFormat.BGRA32, false);
texturePtr_ = texture_.GetNativeTexturePtr();
}
public void DestroyTexture()
{
if (texture_) {
Object.Destroy(texture_);
texture_ = null;
texturePtr_ = System.IntPtr.Zero;
}
}
public void Reinitialize()
{
CreateTextureIfNeeded();
}
public Color32[] GetPixels(int x, int y, int width, int height)
{
if (!useGetPixels_) {
Debug.LogErrorFormat("Please set Monitor[{0}].useGetPixels as true.", id);
return null;
}
return Lib.GetPixels(id, x, y, width, height);
}
public bool GetPixels(Color32[] colors, int x, int y, int width, int height)
{
if (!useGetPixels_) {
Debug.LogErrorFormat("Please set Monitor[{0}].useGetPixels as true.", id);
return false;
}
return Lib.GetPixels(id, colors, x, y, width, height);
}
public Color32 GetPixel(int x, int y)
{
if (!useGetPixels_) {
Debug.LogErrorFormat("Please set Monitor[{0}].useGetPixels as true.", id);
return Color.black;
}
return Lib.GetPixel(id, x, y);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 310590b113d909b43b4ea19702904ac3
timeCreated: 1477643181
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 89616e59e1cccb346bd4e959257990ca, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,44 +0,0 @@
using UnityEngine;
namespace uDesktopDuplication
{
[RequireComponent(typeof(uDesktopDuplication))]
public class MouseDrawer : MonoBehaviour
{
[SerializeField]
Transform cursor;
[SerializeField]
Vector2 modelScale = Vector2.one;
[SerializeField]
Vector2 offset = new Vector2(0.5f, 0.5f);
uDesktopDuplication udd_;
void OnEnable()
{
udd_ = GetComponent<uDesktopDuplication>();
udd_.onMouseMove += OnMouseMove;
}
void OnDisable()
{
udd_.onMouseMove -= OnMouseMove;
}
void OnMouseMove(Vector2 pos)
{
var x = pos.x * modelScale.x * 0.5f;
var y = pos.y * modelScale.y * 0.5f;
var iy = udd_.invertY ? +1 : -1;
var localPos = transform.right * x + iy * transform.up * y;
var worldPos = transform.TransformPoint(localPos);
worldPos += cursor.right * offset.x * cursor.localScale.x;
worldPos += -cursor.up * offset.y * cursor.localScale.y;
cursor.position = worldPos;
}
}
}

View File

@@ -0,0 +1,235 @@
using UnityEngine;
namespace uDesktopDuplication
{
[AddComponentMenu("uDesktopDuplication/Texture")]
public class Texture : MonoBehaviour
{
private Monitor monitor_;
public Monitor monitor
{
get { return monitor_; }
set
{
monitor_ = value;
if (monitor_ != null) {
material = GetComponent<Renderer>().material; // clone
material.mainTexture = monitor_.texture;
material.SetFloat("_Width", transform.localScale.x);
}
}
}
private int lastMonitorId_ = 0;
public int monitorId
{
get { return monitor.id; }
set { monitor = Manager.GetMonitor(value); }
}
[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 MeshForwardDirection
{
Y = 0,
Z = 1,
}
public bool bend
{
get
{
return material.GetInt("_Bend") != 0;
}
set
{
if (value) {
material.EnableKeyword("BEND_ON");
material.SetInt("_Bend", 1);
} else {
material.DisableKeyword("BEND_ON");
material.SetInt("_Bend", 0);
}
}
}
public MeshForwardDirection meshForwardDirection
{
get
{
return (MeshForwardDirection)material.GetInt("_Forward");
}
set
{
switch (value) {
case MeshForwardDirection.Y:
material.SetInt("_Forward", 0);
material.EnableKeyword("_FORWARD_Y");
material.DisableKeyword("_FORWARD_Z");
break;
case MeshForwardDirection.Z:
material.SetInt("_Forward", 1);
material.DisableKeyword("_FORWARD_Y");
material.EnableKeyword("_FORWARD_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 float thickness
{
get { return material.GetFloat("_Thickness"); }
set { material.SetFloat("_Thickness", value); }
}
public Material material
{
get;
private set;
}
void OnEnable()
{
if (monitor == null) {
monitor = Manager.primary;
}
Manager.onReinitialized += Reinitialize;
}
void OnDisable()
{
Manager.onReinitialized -= Reinitialize;
}
void Update()
{
KeepMonitor();
monitor.shouldBeUpdated = true;
UpdateMaterial();
}
void KeepMonitor()
{
if (monitor == null) {
Reinitialize();
} else {
lastMonitorId_ = monitorId;
}
}
void Reinitialize()
{
// Monitor instance is released here when initialized.
monitor = Manager.GetMonitor(lastMonitorId_);
}
void UpdateMaterial()
{
Invert();
Rotate();
Clip();
}
void Invert()
{
if (invertX) {
material.EnableKeyword("INVERT_X");
} else {
material.DisableKeyword("INVERT_X");
}
if (invertY) {
material.EnableKeyword("INVERT_Y");
} else {
material.DisableKeyword("INVERT_Y");
}
}
void Rotate()
{
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;
}
}
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");
}
}
public Vector3 GetWorldPositionFromCoord(int u, int v)
{
// Mesh & Scale information
var mesh = GetComponent<MeshFilter>().sharedMesh;
var width = transform.localScale.x * (mesh.bounds.extents.x * 2f);
var height = transform.localScale.y * (mesh.bounds.extents.y * 2f);
// Local position (scale included).
var x = (float)(u - monitor.width / 2) / monitor.width;
var y = -(float)(v - monitor.height / 2) / monitor.height;
var localPos = new Vector3(width * x, height * y, 0f);
// Bending
if (bend) {
var angle = localPos.x / radius;
if (meshForwardDirection == MeshForwardDirection.Y) {
localPos.y -= radius * (1f - Mathf.Cos(angle));
} else {
localPos.z -= radius * (1f - Mathf.Cos(angle));
}
localPos.x = radius * Mathf.Sin(angle);
}
// To world position
return transform.position + (transform.rotation * localPos);
}
}
}

View File

@@ -1,6 +1,6 @@
fileFormatVersion: 2
guid: bb54a34570e4747429b1c5b66c69d356
timeCreated: 1477559813
timeCreated: 1477635636
licenseType: Pro
MonoImporter:
serializedVersion: 2

View File

@@ -0,0 +1,42 @@
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
namespace uDesktopDuplication
{
public struct MousePoint
{
public int x;
public int y;
}
public static class Utility
{
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(out MousePoint point);
public static MousePoint GetCursorPos()
{
MousePoint p;
if (!GetCursorPos(out p)) {
p.x = -1;
p.y = -1;
}
return p;
}
public static void WaitThenDo(System.Action func, float sec)
{
Manager.instance.StartCoroutine(_WaitThenDo(func, sec));
}
public static IEnumerator _WaitThenDo(System.Action func, float sec)
{
yield return new WaitForSeconds(sec);
func();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6c7e8da181b03ce4fb343ffa33cbb929
timeCreated: 1479043365
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 89616e59e1cccb346bd4e959257990ca, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,97 +0,0 @@
using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;
namespace uDesktopDuplication
{
public class uDesktopDuplication : MonoBehaviour
{
[DllImport("uDesktopDuplication")]
private static extern void Initialize();
[DllImport("uDesktopDuplication")]
private static extern int GetWidth();
[DllImport("uDesktopDuplication")]
private static extern int GetHeight();
[DllImport("uDesktopDuplication")]
private static extern bool IsPointerVisible();
[DllImport("uDesktopDuplication")]
private static extern int GetPointerX();
[DllImport("uDesktopDuplication")]
private static extern int GetPointerY();
[DllImport("uDesktopDuplication")]
private static extern int SetTexturePtr(IntPtr ptr);
[DllImport("uDesktopDuplication")]
private static extern IntPtr GetRenderEventFunc();
private Material material_;
public bool invertX = false;
public bool invertY = false;
public delegate void MouseMoveEventHandler(Vector2 pos);
public MouseMoveEventHandler onMouseMove { get; set; }
private Coroutine renderCoroutine_ = null;
void OnEnable()
{
var tex = new Texture2D(GetWidth(), GetHeight(), TextureFormat.BGRA32, false);
material_ = GetComponent<Renderer>().material;
material_.mainTexture = tex;
SetTexturePtr(tex.GetNativeTexturePtr());
renderCoroutine_ = StartCoroutine(OnRender());
}
void OnDisable()
{
if (renderCoroutine_ != null) {
StopCoroutine(renderCoroutine_);
renderCoroutine_ = null;
}
}
void Update()
{
UpdateMouseEvent();
UpdateMaterial();
}
void UpdateMouseEvent()
{
var isVisible = IsPointerVisible();
if (isVisible && onMouseMove != null) {
var x = GetPointerX();
var y = GetPointerY();
var w = GetWidth();
var h = GetHeight();
onMouseMove(new Vector2(2f * x / w - 1f, 1f - 2f * y / h));
}
}
void UpdateMaterial()
{
if (invertX) {
material_.EnableKeyword("INVERT_X");
} else {
material_.DisableKeyword("INVERT_X");
}
if (invertY) {
material_.EnableKeyword("INVERT_Y");
} else {
material_.DisableKeyword("INVERT_Y");
}
}
IEnumerator OnRender()
{
for (;;) {
yield return new WaitForEndOfFrame();
GL.IssuePluginEvent(GetRenderEventFunc(), 0);
}
}
}
}

View File

@@ -1,13 +1,130 @@
#ifndef UDD_COMMON_CGINC
#define UDD_COMMON_CGINC
inline void uddInvertUV(inout float2 uv)
#include "UnityCG.cginc"
#include "./uDD_Params.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
struct Input
{
float2 uv_MainTex;
};
inline float2 uddInvertUV(float2 uv)
{
#ifdef INVERT_X
uv.x *= -1.0;
uv.x = 1.0 - uv.x;
#endif
#ifdef INVERT_Y
uv.y *= -1.0;
uv.y = 1.0 - uv.y;
#endif
return uv;
}
inline 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 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()) {
rgb = GammaToLinearSpace(rgb);
}
}
inline fixed4 uddGetTexture(sampler2D tex, float2 uv)
{
uv = uddInvertUV(uv);
#ifdef USE_CLIP
uv = uddClipUV(uv);
#endif
fixed4 c = tex2D(tex, uddRotateUV(uv));
uddConvertToLinearIfNeeded(c.rgb);
return c;
}
inline fixed4 uddGetScreenTexture(float2 uv)
{
return uddGetTexture(_MainTex, uv);
}
inline void uddBendVertex(inout float3 v, half radius, half width, half thickness)
{
#ifdef BEND_ON
half angle = width * v.x / radius;
#ifdef _FORWARD_Z
v.z *= thickness;
radius += v.z;
v.z -= radius * (1 - cos(angle));
#elif _FORWARD_Y
v.y *= thickness;
radius += v.y;
v.y += radius * (1 - cos(angle));
#endif
v.x = radius * sin(angle) / width;
#else
#ifdef _FORWARD_Z
v.y *= thickness;
#elif _FORWARD_Y
v.z *= thickness;
#endif
#endif
}
inline float3 uddRotateY(float3 n, float angle)
{
float c = cos(angle);
float s = sin(angle);
return float3(c * n.x - s * n.z, n.y, s * n.x + c * n.z);
}
inline float3 uddRotateX(float3 n, float angle)
{
float c = cos(angle);
float s = sin(angle);
return float3(n.x, c * n.y + s * n.z, -s * n.y + c * n.z);
}
inline void uddBendNormal(float4 x, inout float3 n, half radius, half width)
{
#ifdef BEND_ON
half angle = width * x / radius;
#ifdef _FORWARD_Z
n = uddRotateY(n, -angle);
#elif _FORWARD_Y
n = uddRotateX(n, -angle);
#endif
#endif
}

View File

@@ -0,0 +1,24 @@
#ifndef UDD_PARAMS_CGINC
#define UDD_PARAMS_CGINC
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;
#endif
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 54044418ab4785c4a84dd4be507db6c2
timeCreated: 1478266678
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,11 +7,14 @@ Properties
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0, 1)) = 0.5
_Metallic ("Metallic", Range(0, 1)) = 0.0
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull [_Cull]
CGPROGRAM
@@ -19,24 +22,19 @@ SubShader
#pragma surface surf Standard fullforwardshadows
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
#pragma multi_compile ___ USE_BEND
#pragma multi_compile ___ USE_CLIP
#define SURFACE_SHADER
#include "./uDD_Common.cginc"
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
uddInvertUV(IN.uv_MainTex);
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
fixed4 c = uddGetScreenTexture(IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;

View File

@@ -5,6 +5,12 @@ Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "white" {}
[KeywordEnum(Y, Z)] _Forward("Mesh Forward Direction", Int) = 0
[Toggle(BEND_ON)] _Bend("Use Bend", Int) = 0
[PowerSlider(10.0)] _Radius("Bend Radius", Range(1, 100)) = 30
[PowerSlider(10.0)] _Thickness("Thickness", Range(0.01, 10)) = 1
_Width("Width", Range(0.0, 10.0)) = 1.0
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
}
SubShader
@@ -12,30 +18,20 @@ SubShader
Tags { "RenderType"="Opaque" }
Cull [_Cull]
CGINCLUDE
#include "UnityCG.cginc"
#include "./uDD_Common.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
half _Radius;
half _Width;
half _Thickness;
v2f vert(appdata v)
{
v2f o;
uddBendVertex(v.vertex.xyz, _Radius, _Width, _Thickness);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
@@ -43,8 +39,7 @@ v2f vert(appdata v)
fixed4 frag(v2f i) : SV_Target
{
uddInvertUV(i.uv);
return tex2D(_MainTex, i.uv) * _Color;
return uddGetScreenTexture(i.uv);
}
ENDCG
@@ -56,6 +51,10 @@ Pass
#pragma fragment frag
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
#pragma multi_compile ___ USE_CLIP
#pragma multi_compile ___ BEND_ON
#pragma multi_compile _FORWARD_Y _FORWARD_Z
ENDCG
}
@@ -63,4 +62,4 @@ Pass
Fallback "Unlit/Texture"
}
}

View File

@@ -6,6 +6,12 @@ Properties
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "white" {}
_Mask ("Mask", Range(0, 1)) = 0.1
[KeywordEnum(Y, Z)] _Forward("Mesh Forward Direction", Int) = 0
[Toggle(BEND_ON)] _Bend("Use Bend", Int) = 0
[PowerSlider(10.0)] _Radius("Bend Radius", Range(1, 100)) = 30
[PowerSlider(10.0)] _Thickness("Thickness", Range(0.01, 10)) = 1
_Width("Width", Range(0.0, 10.0)) = 1.0
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
}
SubShader
@@ -13,34 +19,23 @@ SubShader
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
ZWrite Off
Cull [_Cull]
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
CGINCLUDE
#include "UnityCG.cginc"
#include "./uDD_Common.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
fixed _Mask;
half _Radius;
half _Width;
half _Thickness;
v2f vert(appdata v)
{
v2f o;
uddBendVertex(v.vertex.xyz, _Radius, _Width, _Thickness);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
@@ -48,10 +43,9 @@ v2f vert(appdata v)
fixed4 frag(v2f i) : SV_Target
{
uddInvertUV(i.uv);
fixed4 tex = tex2D(_MainTex, i.uv);
fixed4 tex = uddGetScreenTexture(i.uv);
fixed alpha = pow((tex.r + tex.g + tex.b) / 3.0, _Mask);
return fixed4(tex.rgb * _Color.rgb, alpha);
return fixed4(tex.rgb * _Color.rgb, alpha * _Color.a);
}
ENDCG
@@ -63,6 +57,10 @@ Pass
#pragma fragment frag
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
#pragma multi_compile ___ USE_BEND
#pragma multi_compile ___ USE_CLIP
#pragma multi_compile _BEND_OFF _BEND_Y _BEND_Z
ENDCG
}

View File

@@ -0,0 +1,178 @@
Shader "uDesktopDuplication/Unlit_Displacement"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "white" {}
[KeywordEnum(Y, Z)] _Forward("Mesh Forward Direction", Int) = 0
[Toggle(BEND_ON)] _Bend("Use Bend", Int) = 0
[PowerSlider(10.0)] _Radius("Bend Radius", Range(1, 100)) = 30
_Width ("Width", Range(0.0, 10.0)) = 1.92
[PowerSlider(10.0)] _Thickness("Thickness", Range(0.01, 10)) = 1
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
_DispTex ("Displacement Map", 2D) = "black" {}
_DispFactor("Displacement Factor", Range(0, 5.0)) = 1
_TessMinDist("Tessellation Min Distance", Range(0.1, 100.0)) = 1.0
_TessMaxDist("Tessellation Max Distance", Range(0.1, 100.0)) = 5.0
_TessFactor("Tessellation Factor", Range(0.1, 50.0)) = 10.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull [_Cull]
CGINCLUDE
#include "./uDD_Common.cginc"
#include "Tessellation.cginc"
half _Radius;
half _Width;
half _Thickness;
Texture2D _DispTex;
SamplerState sampler_DispTex;
half _DispFactor;
half _TessMinDist;
half _TessMaxDist;
half _TessFactor;
struct VsInput
{
float3 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
struct HsInput
{
float4 f4Position : POS;
float3 f3Normal : NORMAL;
float2 f2TexCoord : TEXCOORD;
};
struct HsControlPointOutput
{
float3 f3Position : POS;
float3 f3Normal : NORMAL;
float2 f2TexCoord : TEXCOORD;
};
struct HsConstantOutput
{
float fTessFactor[3] : SV_TessFactor;
float fInsideTessFactor : SV_InsideTessFactor;
};
struct DsOutput
{
float4 f4Position : SV_Position;
float2 f2TexCoord : TEXCOORD0;
};
HsInput vert(VsInput i)
{
HsInput o;
o.f4Position = float4(i.vertex, 1.0);
o.f3Normal = i.normal;
o.f2TexCoord = i.texcoord;
return o;
}
[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[patchconstantfunc("hullConst")]
[outputcontrolpoints(3)]
HsControlPointOutput hull(InputPatch<HsInput, 3> i, uint id : SV_OutputControlPointID)
{
HsControlPointOutput o = (HsControlPointOutput)0;
o.f3Position = i[id].f4Position.xyz;
o.f3Normal = i[id].f3Normal;
o.f2TexCoord = i[id].f2TexCoord;
return o;
}
HsConstantOutput hullConst(InputPatch<HsInput, 3> i)
{
HsConstantOutput o = (HsConstantOutput)0;
float4 p0 = i[0].f4Position;
float4 p1 = i[1].f4Position;
float4 p2 = i[2].f4Position;
float4 tessFactor = UnityDistanceBasedTess(p0, p1, p2, _TessMinDist, _TessMaxDist, _TessFactor);
o.fTessFactor[0] = tessFactor.x;
o.fTessFactor[1] = tessFactor.y;
o.fTessFactor[2] = tessFactor.z;
o.fInsideTessFactor = tessFactor.w;
return o;
}
[domain("tri")]
DsOutput domain(
HsConstantOutput hsConst,
const OutputPatch<HsControlPointOutput, 3> i,
float3 bary : SV_DomainLocation)
{
DsOutput o = (DsOutput)0;
float3 f3Position =
bary.x * i[0].f3Position +
bary.y * i[1].f3Position +
bary.z * i[2].f3Position;
float3 f3Normal = normalize(
bary.x * i[0].f3Normal +
bary.y * i[1].f3Normal +
bary.z * i[2].f3Normal);
o.f2TexCoord =
bary.x * i[0].f2TexCoord +
bary.y * i[1].f2TexCoord +
bary.z * i[2].f2TexCoord;
uddBendNormal(f3Position.x, f3Normal, _Radius, _Width);
uddBendVertex(f3Position, _Radius, _Width, _Thickness);
float disp = length(_DispTex.SampleLevel(sampler_DispTex, o.f2TexCoord, 0)) * _DispFactor;
f3Position.xyz += f3Normal * disp;
o.f4Position = mul(UNITY_MATRIX_MVP, float4(f3Position.xyz, 1.0));
return o;
}
fixed4 frag(DsOutput i) : SV_Target
{
return uddGetScreenTexture(i.f2TexCoord);
}
ENDCG
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma hull hull
#pragma domain domain
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
#pragma multi_compile ___ USE_CLIP
#pragma multi_compile ___ BEND_ON
#pragma multi_compile _FORWARD_Y _FORWARD_Z
ENDCG
}
}
Fallback "Unlit/Texture"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 05df46eb51b13c84eabbdf4c53cc8db7
timeCreated: 1480072905
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More