Advertisement
Hyluss

outline

Jul 22nd, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2.  
  3. Shader "Custom/Outline"
  4. {
  5. Properties //variables
  6. {
  7. _MainTex("Main Texture (RGB)",2D) = "white" {} // allows for a texture property
  8. _Color("Color", Color) = (1,1,1,1) // allows for a color property
  9. _OutlineTex("Outline Texture", 2D) = "white" {}
  10. _OutlineColor("Outline Color", Color) = (1,1,1,1)
  11. _OutlineWidth("Outline Width", Range(1.0,10.0)) = 1.1
  12. }
  13.  
  14. Subshader
  15. {
  16. Tags
  17. {
  18. "Queue" = "Transparent"
  19. // "DisableBatching" = "True"
  20. }
  21.  
  22. Pass
  23. {
  24. Name "OUTLINE"
  25.  
  26.  
  27. ZWrite Off
  28.  
  29.  
  30. CGPROGRAM // allows talk between two languages: shader lab and nvidia C for graphics
  31.  
  32. // Function Defines - defines the name for the vertex and fragment functions
  33.  
  34. // Define for the building function.
  35. // Has information of the shape and tells program how to build it
  36. #pragma vertex vert
  37.  
  38. // Define for coloring function
  39. #pragma fragment frag
  40.  
  41. // Includes
  42.  
  43. #include "UnityCG.cginc" // build in shader functions.
  44.  
  45. // Structures - can get data like - vertices's, normal, color, uv
  46.  
  47. //appdata basically says how the vertex function has going to get inforamtions
  48. struct appdata // vertex information
  49. {
  50. float4 vertex : POSITION;
  51. float2 uv : TEXCOORD0;
  52. };
  53.  
  54. // how fragments get its data
  55. struct v2f // fragment inforamtion
  56. {
  57. //without SV_ this shader doesnt work on playstation and some other platforms
  58. float4 pos : SV_POSITION;
  59. float2 uv: TEXCOORD0;
  60. };
  61.  
  62. // Imports - Re-import property from shader lab to nvidia cg
  63. // properties have to same the same name like in shader lab part
  64. float4 _OutlineColor;
  65. sampler2D _OutlineTex;
  66. float _OutlineWidth;
  67.  
  68. // Vertex function - builds the object
  69. //vertex to fragment
  70.  
  71. //put struct appdata (above) into IN and convert it into a v2f
  72. v2f vert(appdata IN)
  73. {
  74. //get all vertexes of the shape and it's going to
  75. //times it by the outline width
  76. // and so its gonna make it either the same size if its 1 or more than one
  77. // SO its gonna get the shape and then its goona increase it a bit bigger than the actual shape size
  78.  
  79. IN.vertex.xyz *= _OutlineWidth;
  80.  
  81. v2f OUT;
  82. // its gonna take the object form the object space and
  83. // put it into camera clip space so it's gonna allow it to appear
  84. // on the screen
  85.  
  86. //OUT.pos = UnityObjectToClipPos(IN.vertex);
  87. OUT.pos = UnityObjectToClipPos(IN.vertex);
  88.  
  89. // OUT.pos -= float4(1, 0, 0,0);
  90. // swapping the uvs to our uvs
  91. OUT.uv = IN.uv;
  92.  
  93. return OUT;
  94. }
  95.  
  96. // fragment function - color it in
  97.  
  98. fixed4 frag(v2f IN) : SV_Target
  99. {
  100. //gets the teture and wraps it around the uvs of the objects
  101. float4 texColor = tex2D(_OutlineTex, IN.uv);
  102. return texColor * _OutlineColor;
  103. }
  104.  
  105. ENDCG
  106. }
  107.  
  108. Pass
  109. {
  110. Name "OBJECT"
  111. CGPROGRAM // allows talk between two languages: shader lab and nvidia C for graphics
  112.  
  113. // Function Defines - defines the name for the vertex and fragment functions
  114.  
  115. // Define for the building function.
  116. // Has information of the shape and tells program how to build it
  117. #pragma vertex vert
  118.  
  119. // Define for coloring function
  120. #pragma fragment frag
  121.  
  122. // Includes
  123.  
  124. #include "UnityCG.cginc" // build in shader functions.
  125.  
  126. // Structures - can get data like - vertices's, normal, color, uv
  127.  
  128. //appdata basically says how the vertex function has going to get inforamtions
  129. struct appdata // vertex information
  130. {
  131. float4 vertex : POSITION;
  132. float2 uv : TEXCOORD0;
  133. };
  134.  
  135. // how fragments get its data
  136. struct v2f // fragment inforamtion
  137. {
  138. //without SV_ this shader doesnt work on playstation and some other platforms
  139. float4 pos : SV_POSITION;
  140. float2 uv: TEXCOORD0;
  141. };
  142.  
  143. // Imports - Re-import property from shader lab to nvidia cg
  144. // properties have to same the same name like in shader lab part
  145. float4 _Color;
  146. sampler2D _MainTex;
  147.  
  148. // Vertex function - builds the object
  149. //vertex to fragment
  150.  
  151. //put struct appdata (above) into IN and convert it into a v2f
  152. v2f vert(appdata IN)
  153. {
  154. v2f OUT;
  155. // its gonna take the object form the object space and
  156. // put it into camera clip space so it's gonna allow it to appear
  157. // on the screen
  158. OUT.pos = UnityObjectToClipPos(IN.vertex);
  159. // swapping the uvs to our uvs
  160. OUT.uv = IN.uv;
  161.  
  162. return OUT;
  163. }
  164.  
  165. // fragment function - color it in
  166.  
  167. fixed4 frag(v2f IN) : SV_Target
  168. {
  169. //gets the teture and wraps it around the uvs of the objects
  170. float4 texColor = tex2D(_MainTex, IN.uv);
  171. return texColor * _Color;
  172. }
  173.  
  174.  
  175. ENDCG
  176. }
  177. }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement