mirror of
https://github.com/maxartz15/InteractiveMask.git
synced 2024-11-23 05:55:32 +01:00
Mask Camera
- MaskCamera. - MaskDrawer. - Settings. - Prefab.
This commit is contained in:
parent
a8c303bd0e
commit
e400a62ed9
48
Editor/MaskDrawer.cs
Normal file
48
Editor/MaskDrawer.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.InteractiveMask.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Mask))]
|
||||
public class MaskDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Using BeginProperty / EndProperty on the parent property means that
|
||||
// prefab override logic works on the entire property.
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
|
||||
int indent = EditorGUI.indentLevel;
|
||||
Color color = GUI.color;
|
||||
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
float width = position.width / 4;
|
||||
Rect rectR = new Rect(position.x + (width * 0), position.y, width, position.height);
|
||||
Rect rectG = new Rect(position.x + (width * 1), position.y, width, position.height);
|
||||
Rect rectB = new Rect(position.x + (width * 2), position.y, width, position.height);
|
||||
Rect rectA = new Rect(position.x + (width * 3), position.y, width, position.height);
|
||||
|
||||
GUI.color = Color.red;
|
||||
EditorGUI.PropertyField(rectR, property.FindPropertyRelative("r"), new GUIContent(""));
|
||||
GUI.color = Color.green;
|
||||
EditorGUI.PropertyField(rectG, property.FindPropertyRelative("g"), new GUIContent(""));
|
||||
GUI.color = Color.cyan;
|
||||
EditorGUI.PropertyField(rectB, property.FindPropertyRelative("b"), new GUIContent(""));
|
||||
GUI.color = Color.gray;
|
||||
EditorGUI.PropertyField(rectA, property.FindPropertyRelative("a"), new GUIContent(""));
|
||||
|
||||
GUI.color = color;
|
||||
EditorGUI.indentLevel = indent;
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return base.GetPropertyHeight(property, label);
|
||||
}
|
||||
}
|
||||
}
|
11
Editor/MaskDrawer.cs.meta
Normal file
11
Editor/MaskDrawer.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f8624dd5f85530428dd00f913026c1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Runtime/MaskCamera.cs
Normal file
33
Runtime/MaskCamera.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.InteractiveMask
|
||||
{
|
||||
[RequireComponent(typeof(MaskRenderer))]
|
||||
public class MaskCamera : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Camera maskCamera = null;
|
||||
private MaskRenderer maskRenderer = null;
|
||||
|
||||
public RenderTexture target = null;
|
||||
|
||||
private RenderTexture source = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
maskRenderer = GetComponent<MaskRenderer>();
|
||||
|
||||
source = new RenderTexture(target);
|
||||
|
||||
maskCamera.targetTexture = source;
|
||||
|
||||
maskRenderer.target = target;
|
||||
maskRenderer.source = source;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
maskCamera.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
11
Runtime/MaskCamera.cs.meta
Normal file
11
Runtime/MaskCamera.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50ab359e83953ab4590f3bdba570d4cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -9,8 +9,10 @@ namespace TAO.InteractiveMask
|
||||
public Shader clearBlit = null;
|
||||
private Material clearBlitMaterial;
|
||||
// Camera source.
|
||||
[HideInInspector]
|
||||
public RenderTexture source = null;
|
||||
// Output target.
|
||||
[HideInInspector]
|
||||
public RenderTexture target = null;
|
||||
|
||||
public Layer[] layers;
|
||||
@ -118,10 +120,10 @@ namespace TAO.InteractiveMask
|
||||
{
|
||||
public static int LayerCount = 0;
|
||||
|
||||
public Type type;
|
||||
public Shader blit;
|
||||
private Material blitMaterial;
|
||||
public Vector4 channels;
|
||||
public Type type = Type.Clear;
|
||||
public Mask mask = new Mask();
|
||||
public Shader blit = null;
|
||||
private Material blitMaterial = null;
|
||||
|
||||
// Only when mode is persistent.
|
||||
public Shader persistentBlit;
|
||||
@ -149,7 +151,6 @@ namespace TAO.InteractiveMask
|
||||
{
|
||||
name = LayerCount.ToString()
|
||||
};
|
||||
LayerCount++;
|
||||
}
|
||||
|
||||
persistentBlitMaterial.SetTexture("_Source", source);
|
||||
@ -161,7 +162,9 @@ namespace TAO.InteractiveMask
|
||||
}
|
||||
|
||||
blitMaterial.SetTexture("_Source", source);
|
||||
blitMaterial.SetVector("_Channels", channels);
|
||||
blitMaterial.SetVector("_Channels", mask.GetMaskVector);
|
||||
|
||||
LayerCount++;
|
||||
}
|
||||
|
||||
public void Blit(RenderTexture source, RenderTexture target)
|
||||
@ -190,4 +193,18 @@ namespace TAO.InteractiveMask
|
||||
Persistent
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct Mask
|
||||
{
|
||||
public bool r;
|
||||
public bool g;
|
||||
public bool b;
|
||||
public bool a;
|
||||
|
||||
public Vector4 GetMaskVector
|
||||
{
|
||||
get { return new Vector4(r ? 1 : 0, g ? 1 : 0, b ? 1 : 0, a ? 1 : 0); }
|
||||
}
|
||||
}
|
||||
}
|
8
Runtime/Prefabs.meta
Normal file
8
Runtime/Prefabs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32397a0d798be9c498e9b59fe048be10
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
190
Runtime/Prefabs/MaskRenderer.prefab
Normal file
190
Runtime/Prefabs/MaskRenderer.prefab
Normal file
@ -0,0 +1,190 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &354132074049328695
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 354132074049328699}
|
||||
- component: {fileID: 354132074049328698}
|
||||
- component: {fileID: 354132074049328697}
|
||||
m_Layer: 6
|
||||
m_Name: MaskRenderer
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &354132074049328699
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 354132074049328695}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 354132074141824353}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &354132074049328698
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 354132074049328695}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 50ab359e83953ab4590f3bdba570d4cf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
maskCamera: {fileID: 354132074141824159}
|
||||
target: {fileID: 8400000, guid: 6dbf8770b857bc143a3ebf8ac17ff43a, type: 2}
|
||||
--- !u!114 &354132074049328697
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 354132074049328695}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c7ace5587b33c154490f78c11ec9a297, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
mode: 0
|
||||
clearBlit: {fileID: 4800000, guid: 612652bd41e196b408fe733989b1d223, type: 3}
|
||||
source: {fileID: 0}
|
||||
target: {fileID: 8400000, guid: 6dbf8770b857bc143a3ebf8ac17ff43a, type: 2}
|
||||
layers:
|
||||
- type: 0
|
||||
mask:
|
||||
r: 0
|
||||
g: 1
|
||||
b: 0
|
||||
a: 1
|
||||
blit: {fileID: 4800000, guid: b56b79d9c9a85fb45bf1a263d73bd938, type: 3}
|
||||
persistentBlit: {fileID: 4800000, guid: 794c349d1ba10d34c86b6dd5c2b8bb7e, type: 3}
|
||||
- type: 1
|
||||
mask:
|
||||
r: 1
|
||||
g: 0
|
||||
b: 0
|
||||
a: 0
|
||||
blit: {fileID: 4800000, guid: b56b79d9c9a85fb45bf1a263d73bd938, type: 3}
|
||||
persistentBlit: {fileID: 4800000, guid: 794c349d1ba10d34c86b6dd5c2b8bb7e, type: 3}
|
||||
debugGui: 1
|
||||
--- !u!1 &354132074141824156
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 354132074141824353}
|
||||
- component: {fileID: 354132074141824159}
|
||||
- component: {fileID: 354132074141824158}
|
||||
m_Layer: 6
|
||||
m_Name: MaskCamera
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &354132074141824353
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 354132074141824156}
|
||||
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
|
||||
m_LocalPosition: {x: 0, y: 100, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 354132074049328699}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
|
||||
--- !u!20 &354132074141824159
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 354132074141824156}
|
||||
m_Enabled: 0
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 2
|
||||
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic size: 10
|
||||
m_Depth: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 0
|
||||
m_AllowMSAA: 0
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!114 &354132074141824158
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 354132074141824156}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_RenderShadows: 0
|
||||
m_RequiresDepthTextureOption: 2
|
||||
m_RequiresOpaqueTextureOption: 2
|
||||
m_CameraType: 0
|
||||
m_Cameras: []
|
||||
m_RendererIndex: 1
|
||||
m_VolumeLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
m_VolumeTrigger: {fileID: 0}
|
||||
m_RenderPostProcessing: 0
|
||||
m_Antialiasing: 0
|
||||
m_AntialiasingQuality: 2
|
||||
m_StopNaN: 0
|
||||
m_Dithering: 0
|
||||
m_ClearDepth: 1
|
||||
m_AllowXRRendering: 1
|
||||
m_RequiresDepthTexture: 0
|
||||
m_RequiresColorTexture: 0
|
||||
m_Version: 2
|
7
Runtime/Prefabs/MaskRenderer.prefab.meta
Normal file
7
Runtime/Prefabs/MaskRenderer.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16a45af4d26459143a161c4f419e17b3
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Runtime/Settings.meta
Normal file
8
Runtime/Settings.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2efbe7ce63090b44e83e9a0f0f959020
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
44
Runtime/Settings/MaskRenderer.asset
Normal file
44
Runtime/Settings/MaskRenderer.asset
Normal file
@ -0,0 +1,44 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3}
|
||||
m_Name: MaskRenderer
|
||||
m_EditorClassIdentifier:
|
||||
m_RendererFeatures: []
|
||||
m_RendererFeatureMap:
|
||||
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
|
||||
xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2}
|
||||
shaders:
|
||||
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
|
||||
copyDepthPS: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}
|
||||
screenSpaceShadowPS: {fileID: 4800000, guid: 0f854b35a0cf61a429bd5dcfea30eddd, type: 3}
|
||||
samplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3}
|
||||
tileDepthInfoPS: {fileID: 0}
|
||||
tileDeferredPS: {fileID: 0}
|
||||
stencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3}
|
||||
fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3}
|
||||
materialErrorPS: {fileID: 4800000, guid: 5fd9a8feb75a4b5894c241777f519d4e, type: 3}
|
||||
m_OpaqueLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
m_TransparentLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
m_DefaultStencilState:
|
||||
overrideStencilState: 0
|
||||
stencilReference: 0
|
||||
stencilCompareFunction: 8
|
||||
passOperation: 0
|
||||
failOperation: 0
|
||||
zFailOperation: 0
|
||||
m_ShadowTransparentReceive: 0
|
||||
m_RenderingMode: 0
|
||||
m_AccurateGbufferNormals: 0
|
@ -1,8 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1100058e32530e546a7ae167f97c11c5
|
||||
guid: de7c7563db809844baabc245710725ba
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 8400000
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,38 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!84 &8400000
|
||||
RenderTexture:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Source
|
||||
m_ImageContentsHash:
|
||||
serializedVersion: 2
|
||||
Hash: 00000000000000000000000000000000
|
||||
m_ForcedFallbackFormat: 4
|
||||
m_DownscaleFallback: 0
|
||||
m_IsAlphaChannelOptional: 0
|
||||
serializedVersion: 3
|
||||
m_Width: 256
|
||||
m_Height: 256
|
||||
m_AntiAliasing: 1
|
||||
m_MipCount: -1
|
||||
m_DepthFormat: 0
|
||||
m_ColorFormat: 8
|
||||
m_MipMap: 0
|
||||
m_GenerateMips: 1
|
||||
m_SRGB: 0
|
||||
m_UseDynamicScale: 0
|
||||
m_BindMS: 0
|
||||
m_EnableCompatibleFormat: 1
|
||||
m_TextureSettings:
|
||||
serializedVersion: 2
|
||||
m_FilterMode: 1
|
||||
m_Aniso: 0
|
||||
m_MipBias: 0
|
||||
m_WrapU: 1
|
||||
m_WrapV: 1
|
||||
m_WrapW: 1
|
||||
m_Dimension: 2
|
||||
m_VolumeDepth: 1
|
Loading…
Reference in New Issue
Block a user