├── .gitattributes ├── Assets ├── Texture.png ├── Cutout Demo.unity ├── Materials │ ├── CutoutMaterial.mat │ ├── CutoutSolid.shader │ └── CutoutFade.shader └── CameraCutout.cs ├── .gitignore ├── README.md └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /Assets/Texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Camera-cutout/HEAD/Assets/Texture.png -------------------------------------------------------------------------------- /Assets/Cutout Demo.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Camera-cutout/HEAD/Assets/Cutout Demo.unity -------------------------------------------------------------------------------- /Assets/Materials/CutoutMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPBotelho/Unity-Camera-cutout/HEAD/Assets/Materials/CutoutMaterial.mat -------------------------------------------------------------------------------- /Assets/CameraCutout.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | [ExecuteInEditMode] 6 | public class CameraCutout : MonoBehaviour 7 | { 8 | 9 | public Material mat; 10 | 11 | void OnRenderImage (RenderTexture src, RenderTexture dst) 12 | { 13 | Graphics.Blit (src, dst, mat); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.meta 28 | 29 | # Unity3D Video Generated Files 30 | *.db 31 | 32 | # Unity3D Generated File On Crash Reports 33 | sysinfo.txt 34 | 35 | # Builds 36 | *.apk 37 | *.unitypackage 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Camera Cutout 2 | A simple Image Effect to only render certain parts of the screen by comparing the original image to a cutout texture. 3 | 4 | # Examples 5 | 6 | Source 7 | ![Alt text](https://i.imgur.com/eH52PdP.png "Source") 8 | 9 | Cutout Texture 10 | ![Alt text](https://i.imgur.com/ajKUSrr.png "Cutout Texture") 11 | 12 | Fade Shader: 13 | ![Alt text](https://i.imgur.com/ZGHVHlM.png "Fade") 14 | 15 | Solid Shader: 16 | ![Alt text](https://i.imgur.com/hSNwm0P.png "Solid") 17 | 18 | 19 | # Usage 20 | 21 | Drag the CameraCutout.cs component to your Camera. 22 | Create a new Material and add either the CutoutSolid or the CutoutFade shader. 23 | Create a Cutout Texture the same resolution as your game's and add it to your material under "Cutout". 24 | Set a color. 25 | 26 | 27 | Make sure your texture settings look like this: 28 | 29 | ![Alt text](https://image.prntscr.com/image/e3GzJyqvTyO_u5pLXGUF7A.png "Settings") 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 João Pedro Costa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Assets/Materials/CutoutSolid.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/NewImageEffectShader" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | _Lookup ("Cutout", 2D) = "white" {} 7 | 8 | _Color ("Color", Color) = (1, 1, 1, 1) 9 | } 10 | SubShader 11 | { 12 | // No culling or depth 13 | Cull Off ZWrite Off ZTest Always 14 | 15 | Pass 16 | { 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | #pragma target 3.0 21 | 22 | #include "UnityCG.cginc" 23 | 24 | float4 _Color; 25 | 26 | struct appdata 27 | { 28 | float4 vertex : POSITION; 29 | float2 uv : TEXCOORD0; 30 | }; 31 | 32 | struct v2f 33 | { 34 | float2 uv : TEXCOORD0; 35 | float4 vertex : SV_POSITION; 36 | }; 37 | 38 | v2f vert (appdata v) 39 | { 40 | v2f o; 41 | o.vertex = UnityObjectToClipPos(v.vertex); 42 | o.uv = v.uv; 43 | return o; 44 | } 45 | 46 | sampler2D _MainTex; 47 | sampler2D _Lookup; 48 | 49 | float4 frag (v2f i) : SV_Target 50 | { 51 | float4 col = tex2D(_MainTex, i.uv); 52 | float4 lookup = tex2D(_Lookup, i.uv); 53 | 54 | bool x = (lookup == float4(0,0,0,0)); 55 | 56 | col = x ? _Color : col; 57 | 58 | return col; 59 | } 60 | ENDCG 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Assets/Materials/CutoutFade.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/NewImageEffectShader" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | _Lookup ("Cutout", 2D) = "white" {} 7 | 8 | _Color ("Color", Color) = (1, 1, 1, 1) 9 | } 10 | SubShader 11 | { 12 | // No culling or depth 13 | Cull Off ZWrite Off ZTest Always 14 | 15 | Pass 16 | { 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | #pragma target 3.0 21 | 22 | #include "UnityCG.cginc" 23 | 24 | float4 _Color; 25 | 26 | struct appdata 27 | { 28 | float4 vertex : POSITION; 29 | float2 uv : TEXCOORD0; 30 | }; 31 | 32 | struct v2f 33 | { 34 | float2 uv : TEXCOORD0; 35 | float4 vertex : SV_POSITION; 36 | }; 37 | 38 | v2f vert (appdata v) 39 | { 40 | v2f o; 41 | o.vertex = UnityObjectToClipPos(v.vertex); 42 | o.uv = v.uv; 43 | return o; 44 | } 45 | 46 | sampler2D _MainTex; 47 | sampler2D _Lookup; 48 | 49 | float4 frag (v2f i) : SV_Target 50 | { 51 | float4 col = tex2D(_MainTex, i.uv); 52 | float4 lookup = tex2D(_Lookup, i.uv); 53 | 54 | bool x = lookup == float4(0,0,0,0); 55 | 56 | float4 _ColorNew = col * _Color; 57 | 58 | _ColorNew.a = 0; 59 | 60 | col = x ? _ColorNew : col; 61 | 62 | return col; 63 | } 64 | ENDCG 65 | } 66 | } 67 | } 68 | --------------------------------------------------------------------------------