Hyluss

Outline shader part 1

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