diff --git a/Assets/uDesktopDuplication/Materials/uDD_Screen.mat b/Assets/uDesktopDuplication/Materials/uDD_Screen.mat index 77806c9..53d06d5 100644 Binary files a/Assets/uDesktopDuplication/Materials/uDD_Screen.mat and b/Assets/uDesktopDuplication/Materials/uDD_Screen.mat differ diff --git a/Assets/uDesktopDuplication/Scripts/MouseDrawer.cs b/Assets/uDesktopDuplication/Scripts/MouseDrawer.cs index 259d559..fc51590 100644 --- a/Assets/uDesktopDuplication/Scripts/MouseDrawer.cs +++ b/Assets/uDesktopDuplication/Scripts/MouseDrawer.cs @@ -1,44 +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(); - 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; - } +{ + +[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(); + 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; + } } } \ No newline at end of file diff --git a/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs b/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs index e3e8f3d..1f22539 100644 --- a/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs +++ b/Assets/uDesktopDuplication/Scripts/uDesktopDuplication.cs @@ -71,18 +71,18 @@ public class uDesktopDuplication : MonoBehaviour } void UpdateMaterial() - { - if (invertX) { - material_.EnableKeyword("INVERT_X"); - } else { - material_.DisableKeyword("INVERT_X"); - } - - if (invertY) { - material_.EnableKeyword("INVERT_Y"); - } else { - material_.DisableKeyword("INVERT_Y"); - } + { + if (invertX) { + material_.EnableKeyword("INVERT_X"); + } else { + material_.DisableKeyword("INVERT_X"); + } + + if (invertY) { + material_.EnableKeyword("INVERT_Y"); + } else { + material_.DisableKeyword("INVERT_Y"); + } } IEnumerator OnRender() diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc b/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc new file mode 100644 index 0000000..f97d8e7 --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc @@ -0,0 +1,14 @@ +#ifndef UDD_COMMON_CGINC +#define UDD_COMMON_CGINC + +inline void uddInvertUV(inout float2 uv) +{ +#ifdef INVERT_X + uv.x *= -1.0; +#endif +#ifdef INVERT_Y + uv.y *= -1.0; +#endif +} + +#endif \ No newline at end of file diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc.meta b/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc.meta new file mode 100644 index 0000000..357c50c --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Common.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 1090e048de83c254d99a242f407890c6 +timeCreated: 1477561310 +licenseType: Pro +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader b/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader new file mode 100644 index 0000000..64d971e --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader @@ -0,0 +1,51 @@ +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) + { + uddInvertUV(IN.uv_MainTex); + fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; + o.Albedo = c.rgb; + o.Metallic = _Metallic; + o.Smoothness = _Glossiness; + o.Alpha = c.a; + } + + ENDCG +} + +FallBack "Diffuse" + +} diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader.meta b/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader.meta new file mode 100644 index 0000000..aa8e6e6 --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Standard.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 1428bebbde173ab4ab509941809d6aec +timeCreated: 1477559925 +licenseType: Pro +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader b/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader index c54965d..c62f7c0 100644 --- a/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader @@ -3,6 +3,7 @@ Properties { + _Color ("Color", Color) = (1, 1, 1, 1) _MainTex ("Texture", 2D) = "white" {} } @@ -14,6 +15,7 @@ Tags { "RenderType"="Opaque" } CGINCLUDE #include "UnityCG.cginc" +#include "./uDD_Common.cginc" struct appdata { @@ -29,8 +31,9 @@ struct v2f sampler2D _MainTex; float4 _MainTex_ST; +fixed4 _Color; -v2f vert (appdata v) +v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); @@ -38,15 +41,10 @@ v2f vert (appdata v) return o; } -fixed4 frag (v2f i) : SV_Target +fixed4 frag(v2f i) : SV_Target { -#ifdef INVERT_X - i.uv.x *= -1.0; -#endif -#ifdef INVERT_Y - i.uv.y *= -1.0; -#endif - return tex2D(_MainTex, i.uv); + uddInvertUV(i.uv); + return tex2D(_MainTex, i.uv) * _Color; } ENDCG @@ -63,4 +61,6 @@ Pass } +Fallback "Unlit/Texture" + } diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader new file mode 100644 index 0000000..1f60f44 --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader @@ -0,0 +1,73 @@ +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 +{ + uddInvertUV(i.uv); + fixed4 tex = tex2D(_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" + +} diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader.meta b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader.meta new file mode 100644 index 0000000..bbfde44 --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_BlackMask.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8d8bed8b85c7bb844a44481b2feb53ca +timeCreated: 1477561145 +licenseType: Pro +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader new file mode 100644 index 0000000..a6d042e --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader @@ -0,0 +1,69 @@ +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 +{ + uddInvertUV(i.uv); + return fixed4(tex2D(_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" + +} diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader.meta b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader.meta new file mode 100644 index 0000000..e8ccb9a --- /dev/null +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit_Transparent.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 32b14c1fb31640f43b002138823eb1e1 +timeCreated: 1477560210 +licenseType: Pro +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: