Compare commits

..

7 Commits

Author SHA1 Message Date
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
hecomi
de0c157fb5 update readme. 2016-10-27 18:53:36 +09:00
hecomi
c93bd58ec4 modify default shader. 2016-10-27 18:51:10 +09:00
hecomi
c4db1ab14a add shader family. 2016-10-27 18:50:45 +09:00
hecomi
e72eff0ee7 add mouse cursor. 2016-10-27 18:17:37 +09:00
hecomi
50fd042e35 update readme. 2016-10-27 16:33:39 +09:00
27 changed files with 544 additions and 22 deletions

Binary file not shown.

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 033e0db89e0ca1d46a399c953629f67d
timeCreated: 1477555367
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 967 B

View File

@@ -0,0 +1,59 @@
fileFormatVersion: 2
guid: 89616e59e1cccb346bd4e959257990ca
timeCreated: 1477555207
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
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: 0
aniso: 1
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 1
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: 1
spriteTessellationDetail: -1
textureType: 8
buildTargetSettings: []
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
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,12 @@
fileFormatVersion: 2
guid: d2d9e4ca459ecb44da8815bafe9655c5
timeCreated: 1477559806
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 89616e59e1cccb346bd4e959257990ca, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3,6 +3,9 @@ using System;
using System.Collections;
using System.Runtime.InteropServices;
namespace uDesktopDuplication
{
public class uDesktopDuplication : MonoBehaviour
{
[DllImport("uDesktopDuplication")]
@@ -22,34 +25,64 @@ public class uDesktopDuplication : MonoBehaviour
[DllImport("uDesktopDuplication")]
private static extern IntPtr GetRenderEventFunc();
public bool isPointerVisible = false;
public int pointerX = 0;
public int pointerY = 0;
private Material material_;
public bool invertX = false;
public bool invertY = false;
Coroutine renderCoroutine_ = null;
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);
GetComponent<Renderer>().sharedMaterial.mainTexture = tex;
material_ = GetComponent<Renderer>().material;
material_.mainTexture = tex;
SetTexturePtr(tex.GetNativeTexturePtr());
renderCoroutine_ = StartCoroutine(OnRender());
}
void OnDisable()
{
if (renderCoroutine_ != null) {
StopCoroutine(renderCoroutine_);
renderCoroutine_ = null;
}
{
if (renderCoroutine_ != null) {
StopCoroutine(renderCoroutine_);
renderCoroutine_ = null;
}
}
void Update()
{
isPointerVisible = IsPointerVisible();
pointerX = GetPointerX();
pointerY = GetPointerY();
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()
@@ -59,4 +92,6 @@ public class uDesktopDuplication : MonoBehaviour
GL.IssuePluginEvent(GetRenderEventFunc(), 0);
}
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,26 @@
#ifndef UDD_COMMON_CGINC
#define UDD_COMMON_CGINC
#include "UnityCG.cginc"
inline void uddInvertUV(inout float2 uv)
{
#ifdef INVERT_X
uv.x *= -1.0;
#endif
#ifdef INVERT_Y
uv.y *= -1.0;
#endif
}
inline fixed4 uddGetTexture(sampler2D tex, float2 uv)
{
uddInvertUV(uv);
fixed4 c = tex2D(tex, uv);
if (!IsGammaSpace()) {
c.rgb = GammaToLinearSpace(c.rgb);
}
return c;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1090e048de83c254d99a242f407890c6
timeCreated: 1477561310
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
Shader "uDesktopDuplication/Standard"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0, 1)) = 0.5
_Metallic ("Metallic", Range(0, 1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma target 3.0
#pragma surface surf Standard fullforwardshadows
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
#include "./uDD_Common.cginc"
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = uddGetTexture(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1428bebbde173ab4ab509941809d6aec
timeCreated: 1477559925
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
Shader "uDesktopDuplication/Unlit"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
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;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return uddGetTexture(_MainTex, i.uv) * _Color;
}
ENDCG
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
ENDCG
}
}
Fallback "Unlit/Texture"
}

View File

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

View File

@@ -0,0 +1,72 @@
Shader "uDesktopDuplication/Unlit BlackMask"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "white" {}
_Mask ("Mask", Range(0, 1)) = 0.1
}
SubShader
{
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
ZWrite Off
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;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 tex = uddGetTexture(_MainTex, i.uv);
fixed alpha = pow((tex.r + tex.g + tex.b) / 3.0, _Mask);
return fixed4(tex.rgb * _Color.rgb, alpha);
}
ENDCG
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
ENDCG
}
}
Fallback "Unlit/Texture"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8d8bed8b85c7bb844a44481b2feb53ca
timeCreated: 1477561145
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
Shader "uDesktopDuplication/Unlit Transparent"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
ZWrite Off
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;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return fixed4(uddGetTexture(_MainTex, i.uv).rgb, 1.0) * _Color;
}
ENDCG
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile ___ INVERT_X
#pragma multi_compile ___ INVERT_Y
ENDCG
}
}
Fallback "Unlit/Transparent"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 32b14c1fb31640f43b002138823eb1e1
timeCreated: 1477560210
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -34,7 +34,7 @@ extern "C"
{
// Search the main monitor from all outputs.
IDXGIOutput* output;
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); j++)
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); ++j)
{
DXGI_OUTPUT_DESC outputDesc;
output->GetDesc(&outputDesc);

View File

@@ -1,7 +1,7 @@
uDesktopDuplication
===================
**uDesktopDuplication** is Desktop Duplication API implementation for Unity.
**uDesktopDuplication** is a simple Desktop Duplication API implementation for Unity.
ScreenShot
@@ -27,15 +27,17 @@ Attach `uDesktopDuplication.cs` component to the target object, then its main te
TODOs
-----
- [ ] Mouse cursor
- [x] Mouse cursor
- [ ] Monitor selector
- [ ] Support linear color
- [x] Support linear color
Please request new features you want to issues.
Version
-------
| Data | Version | Description |
| ---------- | ------- | --------------------------- |
| 2016/10/27 | 0.0.1 | Initial commit. |
| Data | Version | Description |
| ---------- | ------- | --------------------------------- |
| 2016/10/27 | 0.0.3 | Support lienar color. |
| 2016/10/27 | 0.0.2 | Add mouse cursor / shader family. |
| 2016/10/27 | 0.0.1 | Initial commit. |