Shader "Custom/Outline"
{
Properties //variables
{
_MainTex("Main Texture (RGB)",2D) = "white" {} // allows for a texture property
_Color("Color", Color) = (1,1,1,1) // allows for a color property
_OutlineTex("Outline Texture", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (1,1,1,1)
_OutlineWidth("Outline Width", Range(1.0,10.0)) = 1.1
}
Subshader
{
Tags
{
"Queue" = "Transparent"
}
Pass
{
Name "OUTLINE"
ZWrite Off
CGPROGRAM // allows talk between two languages: shader lab and nvidia C for graphics
// Function Defines - defines the name for the vertex and fragment functions
// Define for the building function.
// Has information of the shape and tells program how to build it
#pragma vertex vert
// Define for coloring function
#pragma fragment frag
// Includes
#include "UnityCG.cginc" // build in shader functions.
// Structures - can get data like - vertices's, normal, color, uv
//appdata basically says how the vertex function has going to get inforamtions
struct appdata // vertex information
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
// how fragments get its data
struct v2f // fragment inforamtion
{
//without SV_ this shader doesnt work on playstation and some other platforms
float4 pos : SV_POSITION;
float2 uv: TEXCOORD0;
};
// Imports - Re-import property from shader lab to nvidia cg
// properties have to same the same name like in shader lab part
float4 _OutlineColor;
sampler2D _OutlineTex;
float _OutlineWidth;
// Vertex function - builds the object
//vertex to fragment
//put struct appdata (above) into IN and convert it into a v2f
v2f vert(appdata IN)
{
//get all vertexes of the shape and it's going to
//times it by the outline width
// and so its gonna make it either the same size if its 1 or more than one
// SO its gonna get the shape and then its goona increase it a bit bigger than the actual shape size
IN.vertex.xyz *= _OutlineWidth;
v2f OUT;
// its gonna take the object form the object space and
// put it into camera clip space so it's gonna allow it to appear
// on the screen
OUT.pos = UnityObjectToClipPos(IN.vertex);
// swapping the uvs to our uvs
OUT.uv = IN.uv;
return OUT;
}
// fragment function - color it in
fixed4 frag(v2f IN) : SV_Target
{
//gets the teture and wraps it around the uvs of the objects
float4 texColor = tex2D(_OutlineTex, IN.uv);
return texColor * _OutlineColor;
}
ENDCG
}
Pass
{
Name "OBJECT"
CGPROGRAM // allows talk between two languages: shader lab and nvidia C for graphics
// Function Defines - defines the name for the vertex and fragment functions
// Define for the building function.
// Has information of the shape and tells program how to build it
#pragma vertex vert
// Define for coloring function
#pragma fragment frag
// Includes
#include "UnityCG.cginc" // build in shader functions.
// Structures - can get data like - vertices's, normal, color, uv
//appdata basically says how the vertex function has going to get inforamtions
struct appdata // vertex information
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
// how fragments get its data
struct v2f // fragment inforamtion
{
//without SV_ this shader doesnt work on playstation and some other platforms
float4 pos : SV_POSITION;
float2 uv: TEXCOORD0;
};
// Imports - Re-import property from shader lab to nvidia cg
// properties have to same the same name like in shader lab part
float4 _Color;
sampler2D _MainTex;
// Vertex function - builds the object
//vertex to fragment
//put struct appdata (above) into IN and convert it into a v2f
v2f vert(appdata IN)
{
v2f OUT;
// its gonna take the object form the object space and
// put it into camera clip space so it's gonna allow it to appear
// on the screen
OUT.pos = UnityObjectToClipPos(IN.vertex);
// swapping the uvs to our uvs
OUT.uv = IN.uv;
return OUT;
}
// fragment function - color it in
fixed4 frag(v2f IN) : SV_Target
{
//gets the teture and wraps it around the uvs of the objects
float4 texColor = tex2D(_MainTex, IN.uv);
return texColor * _Color;
}
ENDCG
}
}
}
Comments
0 B
|👍
/👎