Skip to content

Instantly share code, notes, and snippets.

@lincerely
Created February 2, 2018 10:36
Show Gist options
  • Save lincerely/5b2f4b25fd96bb38c03c2209adb489bd to your computer and use it in GitHub Desktop.
Save lincerely/5b2f4b25fd96bb38c03c2209adb489bd to your computer and use it in GitHub Desktop.
Shaderlab sample with notes in comment
Shader "Unlit/UnityShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100 //level of detail
Pass
{
CGPROGRAM
#pragma vertex vert //define vertex function
#pragma fragment frag //define fragment function
#include "UnityCG.cginc" // some predefined helper function
// property data for vertex function,
// which takes the shape of the model and modifies it
struct appdata
{
float4 vertex : POSITION; // x,y,z,w // [POSITION] tell shader we will use this for rendering
float2 uv : TEXCOORD0;
};
// property data for fragment function
// which applies color to the shape output by the vert function
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION; // screen space position
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex); //apply tiling and offset of texture
return o;
}
fixed4 frag (v2f i) : SV_Target // render target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment