Guest User

Untitled

a guest
Oct 18th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. Shader "Outlined/Diffuse" {
  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 (.002, 0.03)) = .005
  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" = "Overlay" }
  41. CGPROGRAM
  42. #pragma surface surf Lambert
  43.  
  44. sampler2D _MainTex;
  45. fixed4 _Color;
  46.  
  47. struct Input {
  48. float2 uv_MainTex;
  49. };
  50.  
  51. void surf (Input IN, inout SurfaceOutput o) {
  52. fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  53. o.Albedo = c.rgb;
  54. o.Alpha = c.a;
  55. }
  56. ENDCG
  57.  
  58. // note that a vertex shader is specified here but its using the one above
  59. Pass {
  60. Name "OUTLINE"
  61. Tags { "LightMode" = "Always" "Queue" = "Overlay" }
  62. Cull Front
  63. ZWrite On
  64. ZTest LEqual
  65. ColorMask RGB
  66. Blend SrcAlpha OneMinusSrcAlpha
  67. Offset 15,15
  68.  
  69. CGPROGRAM
  70. #pragma vertex vert
  71. #pragma fragment frag
  72. half4 frag(v2f i) :COLOR { return i.color; }
  73. ENDCG
  74. }
  75. }
  76.  
  77. SubShader {
  78. Tags {"Queue" = "Overlay" }
  79. CGPROGRAM
  80. #pragma surface surf Lambert
  81.  
  82. sampler2D _MainTex;
  83. fixed4 _Color;
  84.  
  85. struct Input {
  86. float2 uv_MainTex;
  87. };
  88.  
  89. void surf (Input IN, inout SurfaceOutput o) {
  90. fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  91. o.Albedo = c.rgb;
  92. o.Alpha = c.a;
  93. }
  94. ENDCG
  95.  
  96. Pass {
  97. Name "OUTLINE"
  98. Tags { "LightMode" = "Always" }
  99. Cull Front
  100. ZWrite On
  101. ColorMask RGB
  102. Blend SrcAlpha OneMinusSrcAlpha
  103.  
  104. CGPROGRAM
  105. #pragma vertex vert
  106. #pragma exclude_renderers gles xbox360 ps3
  107. ENDCG
  108. SetTexture [_MainTex] { combine primary }
  109. }
  110. }
  111.  
  112. Fallback "Diffuse"
  113. }
Add Comment
Please, Sign In to add comment