├── CustomOutline-CameraIndependent.shader ├── CustomOutline-ConstantWidth.shader ├── CustomOutline.shader ├── LICENSE ├── OutlineShowcase.unitypackage ├── README.md ├── RegularOutline.shader ├── UniformOutline.shader ├── images ├── Uniform.PNG ├── camera.PNG ├── camera2.PNG ├── custom.PNG ├── standard.PNG ├── zoom.PNG └── zoom2.PNG └── triangleOutline.shader /CustomOutline-CameraIndependent.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | 3 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 4 | 5 | Shader "Outlined/Custom Camera Independent" { 6 | Properties { 7 | _Color ("Main Color", Color) = (.5,.5,.5,1) 8 | _OutlineColor ("Outline Color", Color) = (0,0,0,1) 9 | _Outline2 ("Outline width", Range (0, 1)) = .1 10 | _MainTex ("Base (RGB)", 2D) = "white" { } 11 | } 12 | 13 | CGINCLUDE 14 | #include "UnityCG.cginc" 15 | 16 | struct appdata { 17 | float4 vertex : POSITION; 18 | float3 normal : NORMAL; 19 | }; 20 | 21 | struct v2f { 22 | float4 pos : POSITION; 23 | float4 color : COLOR; 24 | }; 25 | 26 | uniform float _Outline2; 27 | uniform float4 _OutlineColor; 28 | 29 | v2f vert(appdata v) { 30 | // just make a copy of incoming vertex data but scaled according to normal direction 31 | v2f o; 32 | 33 | //Camera position in world 34 | float3 targetPos = _WorldSpaceCameraPos; 35 | 36 | //Object position in world 37 | float3 objectPos = mul (unity_ObjectToWorld, v.vertex).xyz; 38 | 39 | //Vertex offset from center of the object 40 | float3 offset = v.vertex.xyz; 41 | 42 | //Distance from the object to the camera 43 | float dist = distance(objectPos, targetPos + offset); 44 | 45 | //Forward vector of the camera 46 | float3 viewDir = UNITY_MATRIX_IT_MV[2].xyz; 47 | 48 | //Vector between vertex and offseted camera pos 49 | float3 distVec = objectPos - (targetPos + offset); 50 | 51 | //Angle between two vectors 52 | float angle = distVec - distVec; 53 | //float angle = atan2(normalize(cross(distVec,viewDir)), dot(distVec,viewDir)); 54 | 55 | //Real distance (to the plane 90 degrees to camera forward and object) 56 | float finalDist = dist * cos(degrees(angle)); 57 | 58 | //v.vertex *= ( 2 ); 59 | v.vertex *= finalDist * _Outline2; 60 | 61 | //v.vertex *= -1; 62 | 63 | o.pos = UnityObjectToClipPos(v.vertex); 64 | 65 | o.color = _OutlineColor; 66 | return o; 67 | } 68 | ENDCG 69 | 70 | SubShader { 71 | //Tags {"Queue" = "Geometry+100" } 72 | CGPROGRAM 73 | #pragma surface surf Lambert 74 | 75 | sampler2D _MainTex; 76 | fixed4 _Color; 77 | 78 | struct Input { 79 | float2 uv_MainTex; 80 | }; 81 | 82 | void surf (Input IN, inout SurfaceOutput o) { 83 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 84 | o.Albedo = c.rgb; 85 | o.Alpha = c.a; 86 | } 87 | ENDCG 88 | 89 | // note that a vertex shader is specified here but its using the one above 90 | Pass { 91 | Name "OUTLINE" 92 | Tags { "LightMode" = "Always" } 93 | Cull Front 94 | ZWrite On 95 | ColorMask RGB 96 | Blend SrcAlpha OneMinusSrcAlpha 97 | //Offset 50,50 98 | 99 | CGPROGRAM 100 | #pragma vertex vert 101 | #pragma fragment frag 102 | half4 frag(v2f i) :COLOR { return i.color; } 103 | ENDCG 104 | } 105 | } 106 | 107 | SubShader { 108 | CGPROGRAM 109 | #pragma surface surf Lambert 110 | 111 | sampler2D _MainTex; 112 | fixed4 _Color; 113 | 114 | struct Input { 115 | float2 uv_MainTex; 116 | }; 117 | 118 | void surf (Input IN, inout SurfaceOutput o) { 119 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 120 | o.Albedo = c.rgb; 121 | o.Alpha = c.a; 122 | } 123 | ENDCG 124 | 125 | Pass { 126 | Name "OUTLINE" 127 | Tags { "LightMode" = "Always" } 128 | Cull Front 129 | ZWrite On 130 | ColorMask RGB 131 | Blend SrcAlpha OneMinusSrcAlpha 132 | 133 | CGPROGRAM 134 | #pragma vertex vert 135 | #pragma exclude_renderers gles xbox360 ps3 136 | ENDCG 137 | SetTexture [_MainTex] { combine primary } 138 | } 139 | } 140 | 141 | Fallback "Diffuse" 142 | } 143 | -------------------------------------------------------------------------------- /CustomOutline-ConstantWidth.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "Outlined/Custom Constant Width" { 4 | Properties { 5 | _Color ("Main Color", Color) = (.5,.5,.5,1) 6 | _OutlineColor ("Outline Color", Color) = (0,0,0,1) 7 | _Outline ("Outline width", Range (0, 5)) = .1 8 | _Limiter ("Outline width limiter", Range (0, 5)) = 0 9 | _MainTex ("Base (RGB)", 2D) = "white" { } 10 | } 11 | 12 | CGINCLUDE 13 | #include "UnityCG.cginc" 14 | 15 | struct appdata { 16 | float4 vertex : POSITION; 17 | float3 normal : NORMAL; 18 | }; 19 | 20 | struct v2f { 21 | float4 pos : POSITION; 22 | float4 color : COLOR; 23 | }; 24 | 25 | uniform float _Outline; 26 | uniform float _Limiter; 27 | uniform float4 _OutlineColor; 28 | 29 | v2f vert(appdata v) { 30 | 31 | v2f o; 32 | 33 | //Original concept of using FOV 34 | //float t = unity_CameraProjection._m11; 35 | //const float Rad2Deg = 180 / UNITY_PI; 36 | //float fov = atan(1.0f / t ) * 2.0 * Rad2Deg; 37 | 38 | //if(fov < _Limiter){ 39 | // fov = _Limiter; 40 | //} 41 | 42 | float multiplier = unity_OrthoParams.x * 0.1; 43 | 44 | if(multiplier < _Limiter){ 45 | multiplier = _Limiter; 46 | } 47 | 48 | v.vertex *= _Outline * multiplier; 49 | 50 | o.pos = UnityObjectToClipPos(v.vertex); 51 | 52 | o.color = _OutlineColor; 53 | return o; 54 | } 55 | ENDCG 56 | 57 | SubShader { 58 | //Tags {"Queue" = "Geometry+100" } 59 | CGPROGRAM 60 | #pragma surface surf Lambert 61 | 62 | sampler2D _MainTex; 63 | fixed4 _Color; 64 | 65 | struct Input { 66 | float2 uv_MainTex; 67 | }; 68 | 69 | void surf (Input IN, inout SurfaceOutput o) { 70 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 71 | o.Albedo = c.rgb; 72 | o.Alpha = c.a; 73 | } 74 | ENDCG 75 | 76 | // note that a vertex shader is specified here but its using the one above 77 | Pass { 78 | Name "OUTLINE" 79 | Tags { "LightMode" = "Always" } 80 | Cull Front 81 | ZWrite On 82 | ColorMask RGB 83 | Blend SrcAlpha OneMinusSrcAlpha 84 | //Offset 50,50 85 | 86 | CGPROGRAM 87 | #pragma vertex vert 88 | #pragma fragment frag 89 | half4 frag(v2f i) :COLOR { return i.color; } 90 | ENDCG 91 | } 92 | } 93 | 94 | SubShader { 95 | CGPROGRAM 96 | #pragma surface surf Lambert 97 | 98 | sampler2D _MainTex; 99 | fixed4 _Color; 100 | 101 | struct Input { 102 | float2 uv_MainTex; 103 | }; 104 | 105 | void surf (Input IN, inout SurfaceOutput o) { 106 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 107 | o.Albedo = c.rgb; 108 | o.Alpha = c.a; 109 | } 110 | ENDCG 111 | 112 | Pass { 113 | Name "OUTLINE" 114 | Tags { "LightMode" = "Always" } 115 | Cull Front 116 | ZWrite On 117 | ColorMask RGB 118 | Blend SrcAlpha OneMinusSrcAlpha 119 | 120 | CGPROGRAM 121 | #pragma vertex vert 122 | #pragma exclude_renderers gles xbox360 ps3 123 | ENDCG 124 | SetTexture [_MainTex] { combine primary } 125 | } 126 | } 127 | 128 | Fallback "Diffuse" 129 | } 130 | -------------------------------------------------------------------------------- /CustomOutline.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "Outlined/Custom" { 4 | Properties { 5 | _Color ("Main Color", Color) = (.5,.5,.5,1) 6 | _OutlineColor ("Outline Color", Color) = (0,0,0,1) 7 | _Outline ("Outline width", Range (0, 1)) = .1 8 | _MainTex ("Base (RGB)", 2D) = "white" { } 9 | } 10 | 11 | CGINCLUDE 12 | #include "UnityCG.cginc" 13 | 14 | struct appdata { 15 | float4 vertex : POSITION; 16 | float3 normal : NORMAL; 17 | }; 18 | 19 | struct v2f { 20 | float4 pos : POSITION; 21 | float4 color : COLOR; 22 | }; 23 | 24 | uniform float _Outline; 25 | uniform float4 _OutlineColor; 26 | 27 | v2f vert(appdata v) { 28 | // just make a copy of incoming vertex data but scaled according to normal direction 29 | v2f o; 30 | 31 | v.vertex *= ( 1 + _Outline); 32 | 33 | o.pos = UnityObjectToClipPos(v.vertex); 34 | 35 | //float3 norm = normalize(mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal)); 36 | //float2 offset = TransformViewToProjection(norm.xy); 37 | 38 | o.color = _OutlineColor; 39 | return o; 40 | } 41 | ENDCG 42 | 43 | SubShader { 44 | //Tags {"Queue" = "Geometry+100" } 45 | CGPROGRAM 46 | #pragma surface surf Lambert 47 | 48 | sampler2D _MainTex; 49 | fixed4 _Color; 50 | 51 | struct Input { 52 | float2 uv_MainTex; 53 | }; 54 | 55 | void surf (Input IN, inout SurfaceOutput o) { 56 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 57 | o.Albedo = c.rgb; 58 | o.Alpha = c.a; 59 | } 60 | ENDCG 61 | 62 | // note that a vertex shader is specified here but its using the one above 63 | Pass { 64 | Name "OUTLINE" 65 | Tags { "LightMode" = "Always" } 66 | Cull Front 67 | ZWrite On 68 | ColorMask RGB 69 | Blend SrcAlpha OneMinusSrcAlpha 70 | //Offset 50,50 71 | 72 | CGPROGRAM 73 | #pragma vertex vert 74 | #pragma fragment frag 75 | half4 frag(v2f i) :COLOR { return i.color; } 76 | ENDCG 77 | } 78 | } 79 | 80 | SubShader { 81 | CGPROGRAM 82 | #pragma surface surf Lambert 83 | 84 | sampler2D _MainTex; 85 | fixed4 _Color; 86 | 87 | struct Input { 88 | float2 uv_MainTex; 89 | }; 90 | 91 | void surf (Input IN, inout SurfaceOutput o) { 92 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 93 | o.Albedo = c.rgb; 94 | o.Alpha = c.a; 95 | } 96 | ENDCG 97 | 98 | Pass { 99 | Name "OUTLINE" 100 | Tags { "LightMode" = "Always" } 101 | Cull Front 102 | ZWrite On 103 | ColorMask RGB 104 | Blend SrcAlpha OneMinusSrcAlpha 105 | 106 | CGPROGRAM 107 | #pragma vertex vert 108 | #pragma exclude_renderers gles xbox360 ps3 109 | ENDCG 110 | SetTexture [_MainTex] { combine primary } 111 | } 112 | } 113 | 114 | Fallback "Diffuse" 115 | } 116 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Luke Kabat 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. 22 | -------------------------------------------------------------------------------- /OutlineShowcase.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/OutlineShowcase.unitypackage -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Outlined Diffuse Shader Fixed for Unity 5.6 2 | This is a fixed version of diffused outline shader from http://wiki.unity3d.com/index.php/Outlined_Diffuse_3 3 | It should be working fine in Unity 5.6 and above. 4 | 5 | # Important update: 6 | **A new version of the outline shader is available, go to: https://github.com/Shrimpey/UltimateOutline 7 | Use the updated shader, come back here only if you find it to be working weirdly on your custom models and try some of the ones mentioned below.** 8 | 9 | **Guide:** 10 | I suggest you trying **UniformOutline.shader** and then **CustomOutline.shader**. They should work fine for simple objects/complex objects with proper origin. If they fail - try out the **RegularOutline.shader**. The rest of the shaders are for really specyfic purposes, so unless you know what you're doing you probably shouldn't be using them :) 11 | 12 | **Showcase:** 13 | Download **OutlineShowcase.unitypackage** and import it to Unity project to see RegularOutline, CustomOutline and UniformOutline shaders in action. 14 | 15 | **Shaders:** 16 | 17 | # RegularOutline.shader 18 | **RegularOutline.shader** - Just an updated version of the shader from the wiki page, may still work in weird ways => if so, use custom one. 19 | ![Regular Outline](/images/standard.PNG?raw=true "Regular Outline") 20 | **Usage**: Curved shapes/thin outlines. 21 | **Problems**: Weird shapes on hard edges. 22 | 23 | --- 24 | # CustomOutline.shader 25 | **CustomOutline.shader** - My personal take on the outline shader. It increases the scale of the vertices instead of working with normals. 26 | ![Custom Outline](/images/custom.PNG?raw=true "Custom Outline") 27 | **Usage**: All shapes 28 | **Problems**: Possible clipping on really thick edges/weird offsets if model's origin is not in center 29 | 30 | --- 31 | # UniformOutline.shader 32 | **UniformOutline.shader** - Made from scratch, works just like CustomOutline except the scaling is more uniform - width of the outline should be more consistent on irregular meshes (easy to notice when comparing the wheels of the cart from the image below to the Custom Outline shader image). 33 | 34 | ![Uniform Outline](/images/Uniform.PNG?raw=true "Uniform Outline") 35 | 36 | **Usage**: All shapes 37 | **Problems**: Same as in Custom Outline, less overlaying, more angled distortions. 38 | 39 | --- 40 | # CustomOutline-CameraIndependent.shader 41 | **CustomOutline-CameraIndependent.shader** - Same as custom one, but the outline is the same width despite the distance to the camera. 42 | 43 | ![Camera Independend Close](/images/camera.PNG?raw=true "Camera Independend Close") 44 | ![Camera Independend Far](/images/camera2.PNG?raw=true "Camera Independend Far") 45 | 46 | **Usage**: Same sized outline on perspective camera. 47 | **Problems**: Weird shapes on complex objects. 48 | 49 | --- 50 | # CustomOutline-ConstantWidth.shader 51 | **CustomOutline-ConstantWidth.shader** - Same as custom one, but the outline is constant width despite the camera zoom. 52 | 53 | ![Constant Width Zoomed In](/images/zoom2.PNG?raw=true "Constant Width Zoomed In") 54 | ![Constant Width Zoomed Out](/images/zoom.PNG?raw=true "Constant Width Zoomed Out") 55 | 56 | **Usage**: Same outline width despite the camera's zoom (ortho/perspective) 57 | **Problems**: Clipping on thick outlines on complex shapes. 58 | 59 | --- 60 | 61 | 62 | *UPDATE 03.09.2017 - Added camera independent version of custom shader* 63 | 64 | *UPDATE 04.09.2017 - Added constant size version of custom shader | updated README to include images* 65 | 66 | *UPDATE 12.09.2017 - Added uniform outline shader* 67 | 68 | *UPDATE 23.12.2017 - Fixed some minor issues with custom, regular and uniform shaders | added showcase unity package* 69 | -------------------------------------------------------------------------------- /RegularOutline.shader: -------------------------------------------------------------------------------- 1 | Shader "Outlined/Regular" { 2 | Properties { 3 | _Color ("Main Color", Color) = (.5,.5,.5,1) 4 | _OutlineColor ("Outline Color", Color) = (0,0,0,1) 5 | _Outline ("Outline width", Range (0, 1)) = .1 6 | _MainTex ("Base (RGB)", 2D) = "white" { } 7 | } 8 | 9 | CGINCLUDE 10 | #include "UnityCG.cginc" 11 | 12 | struct appdata { 13 | float4 vertex : POSITION; 14 | float3 normal : NORMAL; 15 | }; 16 | 17 | struct v2f { 18 | float4 pos : POSITION; 19 | float4 color : COLOR; 20 | }; 21 | 22 | uniform float _Outline; 23 | uniform float4 _OutlineColor; 24 | 25 | v2f vert(appdata v) { 26 | // just make a copy of incoming vertex data but scaled according to normal direction 27 | v2f o; 28 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 29 | 30 | float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal); 31 | float2 offset = TransformViewToProjection(norm.xy); 32 | 33 | o.pos.xy += offset * o.pos.z * _Outline; 34 | o.color = _OutlineColor; 35 | return o; 36 | } 37 | ENDCG 38 | 39 | SubShader { 40 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True"} 41 | Cull Back 42 | CGPROGRAM 43 | #pragma surface surf Lambert 44 | 45 | sampler2D _MainTex; 46 | fixed4 _Color; 47 | 48 | struct Input { 49 | float2 uv_MainTex; 50 | }; 51 | 52 | void surf (Input IN, inout SurfaceOutput o) { 53 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 54 | o.Albedo = c.rgb; 55 | o.Alpha = c.a; 56 | } 57 | ENDCG 58 | 59 | Pass { 60 | Name "OUTLINE" 61 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True"} 62 | Cull Front 63 | ZWrite Off 64 | //ZTest Less 65 | //Offset 1, 1 66 | 67 | CGPROGRAM 68 | #pragma vertex vert 69 | #pragma fragment frag 70 | half4 frag(v2f i) :COLOR { return i.color; } 71 | ENDCG 72 | } 73 | } 74 | 75 | Fallback "Diffuse" 76 | } 77 | -------------------------------------------------------------------------------- /UniformOutline.shader: -------------------------------------------------------------------------------- 1 | Shader "Outlined/Uniform" 2 | { 3 | Properties 4 | { 5 | _Color("Main Color", Color) = (0.5,0.5,0.5,1) 6 | _MainTex ("Texture", 2D) = "white" {} 7 | _OutlineColor ("Outline color", Color) = (0,0,0,1) 8 | _OutlineWidth ("Outlines width", Range (0.0, 2.0)) = 1.1 9 | } 10 | 11 | CGINCLUDE 12 | #include "UnityCG.cginc" 13 | 14 | struct appdata 15 | { 16 | float4 vertex : POSITION; 17 | }; 18 | 19 | struct v2f 20 | { 21 | float4 pos : POSITION; 22 | }; 23 | 24 | uniform float _OutlineWidth; 25 | uniform float4 _OutlineColor; 26 | uniform sampler2D _MainTex; 27 | uniform float4 _Color; 28 | 29 | ENDCG 30 | 31 | SubShader 32 | { 33 | Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" } 34 | 35 | Pass //Outline 36 | { 37 | ZWrite Off 38 | Cull Back 39 | CGPROGRAM 40 | 41 | #pragma vertex vert 42 | #pragma fragment frag 43 | 44 | v2f vert(appdata v) 45 | { 46 | appdata original = v; 47 | v.vertex.xyz += _OutlineWidth * normalize(v.vertex.xyz); 48 | 49 | v2f o; 50 | o.pos = UnityObjectToClipPos(v.vertex); 51 | return o; 52 | 53 | } 54 | 55 | half4 frag(v2f i) : COLOR 56 | { 57 | return _OutlineColor; 58 | } 59 | 60 | ENDCG 61 | } 62 | 63 | Tags{ "Queue" = "Geometry"} 64 | 65 | CGPROGRAM 66 | #pragma surface surf Lambert 67 | 68 | struct Input { 69 | float2 uv_MainTex; 70 | }; 71 | 72 | void surf (Input IN, inout SurfaceOutput o) { 73 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 74 | o.Albedo = c.rgb; 75 | o.Alpha = c.a; 76 | } 77 | ENDCG 78 | } 79 | Fallback "Diffuse" 80 | } 81 | -------------------------------------------------------------------------------- /images/Uniform.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/images/Uniform.PNG -------------------------------------------------------------------------------- /images/camera.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/images/camera.PNG -------------------------------------------------------------------------------- /images/camera2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/images/camera2.PNG -------------------------------------------------------------------------------- /images/custom.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/images/custom.PNG -------------------------------------------------------------------------------- /images/standard.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/images/standard.PNG -------------------------------------------------------------------------------- /images/zoom.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/images/zoom.PNG -------------------------------------------------------------------------------- /images/zoom2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/f7179d1bbb51fbce9135cf479f6614e27beb7e50/images/zoom2.PNG -------------------------------------------------------------------------------- /triangleOutline.shader: -------------------------------------------------------------------------------- 1 | Shader "Outlined/Triangle" 2 | { 3 | Properties 4 | { 5 | _Color("Main Color", Color) = (0.5,0.5,0.5,1) 6 | _MainTex ("Texture", 2D) = "white" {} 7 | _OutlineColor ("Outline color", Color) = (0,0,0,1) 8 | _OutlineWidth ("Outlines width", Range (0.0, 2.0)) = 1.1 9 | } 10 | 11 | CGINCLUDE 12 | #include "UnityCG.cginc" 13 | 14 | struct appdata 15 | { 16 | float4 vertex : POSITION; 17 | }; 18 | 19 | struct v2f 20 | { 21 | float4 pos : POSITION; 22 | }; 23 | 24 | uniform float _OutlineWidth; 25 | uniform float4 _OutlineColor; 26 | uniform sampler2D _MainTex; 27 | uniform float4 _Color; 28 | 29 | ENDCG 30 | 31 | SubShader 32 | { 33 | Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" } 34 | 35 | Pass //Outline 36 | { 37 | ZWrite Off 38 | Cull Back 39 | CGPROGRAM 40 | 41 | #pragma vertex vert 42 | #pragma fragment frag 43 | 44 | v2f vert(appdata v) 45 | { 46 | appdata original = v; 47 | v.vertex.xyzw += _OutlineWidth * normalize(v.vertex.xyzw); 48 | v.vertex.x -= _OutlineWidth/4; 49 | v.vertex.y += _OutlineWidth/4; 50 | 51 | v2f o; 52 | o.pos = UnityObjectToClipPos(v.vertex); 53 | return o; 54 | 55 | } 56 | 57 | half4 frag(v2f i) : COLOR 58 | { 59 | return _OutlineColor; 60 | } 61 | 62 | ENDCG 63 | } 64 | 65 | Tags{ "Queue" = "Geometry"} 66 | 67 | CGPROGRAM 68 | #pragma surface surf Lambert 69 | 70 | struct Input { 71 | float2 uv_MainTex; 72 | }; 73 | 74 | void surf (Input IN, inout SurfaceOutput o) { 75 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 76 | o.Albedo = c.rgb; 77 | o.Alpha = c.a; 78 | } 79 | ENDCG 80 | } 81 | Fallback "Diffuse" 82 | } 83 | --------------------------------------------------------------------------------