Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Created August 4, 2017 08:07
Show Gist options
  • Select an option

  • Save tklee1975/16dc968f1520a980e8a84ff7bcde494b to your computer and use it in GitHub Desktop.

Select an option

Save tklee1975/16dc968f1520a980e8a84ff7bcde494b to your computer and use it in GitHub Desktop.
Unity Basic Shader Crash Course
Shader "Custom/ShaderCrashCourse/Emptyshader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vertexFunction
#pragma fragment fragFunction
#include "UnityCG.cginc"
// Input Data
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
// Output Vertex Data
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
};
sampler2D _MainTex;
v2f vertexFunction (appdata IN)
{
v2f output;
output.position = mul(UNITY_MATRIX_MVP, IN.vertex); // Convert to screen position
output.uv = IN.uv; // return the UV mapping
return output;
}
fixed4 fragFunction (v2f IN) : SV_Target
{
// sample the texture
fixed4 fragColor = tex2D(_MainTex, IN.uv); // return color for each pixel
return fragColor;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment