add thickness control.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
|
||||
|
||||
public class MultipleMonitorCreator : MonoBehaviour
|
||||
{
|
||||
@@ -9,8 +10,7 @@ public class MultipleMonitorCreator : MonoBehaviour
|
||||
bool hasMonitorUnsupportStateChecked = false;
|
||||
float removeWaitTimer_ = 0f;
|
||||
|
||||
public enum MeshForwardDirection { Y, Z }
|
||||
[Tooltip("Please specify the upper vector direction of the mesh (e.g. Plane's upper direction is Y.)")]
|
||||
[Tooltip("Please specify the surface direction of the mesh (e.g. Plane => Y.)")]
|
||||
public MeshForwardDirection meshForwardDirection = MeshForwardDirection.Z;
|
||||
|
||||
public class MonitorInfo
|
||||
|
||||
@@ -6,6 +6,7 @@ public class MultipleMonitorLayouter : MonoBehaviour
|
||||
protected MultipleMonitorCreator creator_;
|
||||
[SerializeField] bool updateEveryFrame = true;
|
||||
[SerializeField] protected float margin = 0.1f;
|
||||
[SerializeField][Range(0f, 10f)] protected float thickness = 1f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -15,16 +16,13 @@ public class MultipleMonitorLayouter : MonoBehaviour
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
margin = Mathf.Max(margin, 0f);
|
||||
|
||||
if (updateEveryFrame) {
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
margin = Mathf.Max(margin, 0f);
|
||||
}
|
||||
|
||||
protected virtual void Layout()
|
||||
{
|
||||
var monitors = creator_.monitors;
|
||||
@@ -39,13 +37,17 @@ public class MultipleMonitorLayouter : MonoBehaviour
|
||||
|
||||
var x = -totalWidth / 2;
|
||||
|
||||
foreach (var info in creator_.monitors) {
|
||||
foreach (var info in monitors) {
|
||||
var monitor = info.uddTexture.monitor;
|
||||
x += (monitor.widthMeter * info.mesh.bounds.extents.x);
|
||||
info.gameObject.transform.localPosition = new Vector3(x, 0f, 0f);
|
||||
info.gameObject.transform.localRotation = info.originalRotation;
|
||||
x += (monitor.widthMeter * info.mesh.bounds.extents.x) + margin;
|
||||
}
|
||||
|
||||
foreach (var info in monitors) {
|
||||
info.uddTexture.thickness = thickness;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
|
||||
{
|
||||
[SerializeField] float radius = 10f;
|
||||
[SerializeField] float offsetAngle = 0f;
|
||||
[SerializeField][Range(-180f, 180f)] float offsetAngle = 0f;
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
foreach (var info in creator_.monitors) {
|
||||
info.uddTexture.bend = uDesktopDuplication.Texture.Bend.Off;
|
||||
info.uddTexture.bend = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,10 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
|
||||
uddTex.transform.localRotation = Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.up) * info.originalRotation;
|
||||
angle += (width * 0.5f + margin) / radius;
|
||||
|
||||
if (creator_.meshForwardDirection == MultipleMonitorCreator.MeshForwardDirection.Y) {
|
||||
uddTex.bend = uDesktopDuplication.Texture.Bend.Y;
|
||||
} else {
|
||||
uddTex.bend = uDesktopDuplication.Texture.Bend.Z;
|
||||
}
|
||||
uddTex.bend = true;
|
||||
uddTex.meshForwardDirection = creator_.meshForwardDirection;
|
||||
uddTex.radius = radius;
|
||||
uddTex.thickness = thickness;
|
||||
uddTex.width = uddTex.transform.localScale.x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,37 +34,44 @@ public class Texture : MonoBehaviour
|
||||
public Vector2 clipPos = Vector2.zero;
|
||||
public Vector2 clipScale = new Vector2(0.2f, 0.2f);
|
||||
|
||||
public enum Bend
|
||||
public enum MeshForwardDirection
|
||||
{
|
||||
Off = 0,
|
||||
Y = 1,
|
||||
Z = 2,
|
||||
Y = 0,
|
||||
Z = 1,
|
||||
}
|
||||
|
||||
public Bend bend
|
||||
public bool bend
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Bend)material.GetInt("_Bend");
|
||||
return material.GetInt("_Bend") != 0;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value) {
|
||||
material.EnableKeyword("BEND_ON");
|
||||
} else {
|
||||
material.DisableKeyword("BEND_ON");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MeshForwardDirection meshForwardDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
return (MeshForwardDirection)material.GetInt("_Forward");
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value) {
|
||||
case Bend.Off:
|
||||
material.SetInt("_Bend", 0);
|
||||
material.DisableKeyword("_BEND_OFF");
|
||||
material.DisableKeyword("_BEND_Y");
|
||||
material.DisableKeyword("_BEND_Z");
|
||||
break;
|
||||
case Bend.Y:
|
||||
material.SetInt("_Bend", 1);
|
||||
material.DisableKeyword("_BEND_OFF");
|
||||
case MeshForwardDirection.Y:
|
||||
material.SetInt("_Forward", 0);
|
||||
material.EnableKeyword("_BEND_Y");
|
||||
material.DisableKeyword("_BEND_Z");
|
||||
break;
|
||||
case Bend.Z:
|
||||
material.SetInt("_Bend", 2);
|
||||
material.DisableKeyword("_BEND_OFF");
|
||||
case MeshForwardDirection.Z:
|
||||
material.SetInt("_Forward", 1);
|
||||
material.DisableKeyword("_BEND_Y");
|
||||
material.EnableKeyword("_BEND_Z");
|
||||
break;
|
||||
@@ -84,6 +91,12 @@ public class Texture : MonoBehaviour
|
||||
set { material.SetFloat("_Width", value); }
|
||||
}
|
||||
|
||||
public float thickness
|
||||
{
|
||||
get { return material.GetFloat("_Thickness"); }
|
||||
set { material.SetFloat("_Thickness", value); }
|
||||
}
|
||||
|
||||
public Material material
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -92,18 +92,26 @@ inline fixed4 uddGetScreenTextureWithCursor(float2 uv)
|
||||
return color;
|
||||
}
|
||||
|
||||
inline void uddBendVertex(inout float4 v, half radius, half width)
|
||||
inline void uddBendVertex(inout float4 v, half radius, half width, half thickness)
|
||||
{
|
||||
#if !defined(_BEND_OFF)
|
||||
#ifdef BEND_ON
|
||||
half angle = width * v.x / radius;
|
||||
#ifdef _BEND_Y
|
||||
#ifdef _FORWARD_Z
|
||||
v.y *= thickness;
|
||||
radius -= v.y;
|
||||
v.y += radius * (1 - cos(angle));
|
||||
#elif _BEND_Z
|
||||
#elif _FORWARD_Y
|
||||
v.z *= thickness;
|
||||
radius -= v.z;
|
||||
v.z += 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
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ Properties
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_CursorTex ("Cursor Texture", 2D) = "white" {}
|
||||
[KeywordEnum(Off, Y, Z)] _Bend("Bending", Int) = 0
|
||||
[PowerSlider(10.0)] _Radius("Radius", Range(1, 100)) = 30
|
||||
[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
|
||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||
}
|
||||
|
||||
@@ -24,11 +26,12 @@ CGINCLUDE
|
||||
|
||||
half _Radius;
|
||||
half _Width;
|
||||
half _Thickness;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
uddBendVertex(v.vertex, _Radius, _Width);
|
||||
uddBendVertex(v.vertex, _Radius, _Width, _Thickness);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
@@ -50,7 +53,8 @@ Pass
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
#pragma multi_compile _BEND_OFF _BEND_Y _BEND_Z
|
||||
#pragma multi_compile ___ BEND_ON
|
||||
#pragma multi_compile _FORWARD_Y _FORWARD_Z
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ Properties
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_Mask ("Mask", Range(0, 1)) = 0.1
|
||||
_CursorTex ("Cursor Texture", 2D) = "white" {}
|
||||
[KeywordEnum(Off, Y, Z)] _Bend("Bending", Int) = 0
|
||||
[PowerSlider(10.0)] _Radius("Radius", Range(1, 100)) = 30
|
||||
[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
|
||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||
}
|
||||
|
||||
@@ -28,11 +30,12 @@ CGINCLUDE
|
||||
fixed _Mask;
|
||||
half _Radius;
|
||||
half _Width;
|
||||
half _Thickness;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
uddBendVertex(v.vertex, _Radius, _Width);
|
||||
uddBendVertex(v.vertex, _Radius, _Width, _Thickness);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
|
||||
@@ -6,8 +6,10 @@ Properties
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_CursorTex ("Cursor Texture", 2D) = "white" {}
|
||||
[KeywordEnum(Off, Y, Z)] _Bend("Bending", Int) = 0
|
||||
[PowerSlider(10.0)] _Radius("Radius", Range(1, 100)) = 30
|
||||
[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
|
||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||
}
|
||||
|
||||
@@ -26,11 +28,12 @@ CGINCLUDE
|
||||
|
||||
half _Radius;
|
||||
half _Width;
|
||||
half _Thickness;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
uddBendVertex(v.vertex, _Radius, _Width);
|
||||
uddBendVertex(v.vertex, _Radius, _Width, _Thickness);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
|
||||
Reference in New Issue
Block a user