Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Last active August 5, 2017 06:03
Show Gist options
  • Select an option

  • Save tklee1975/65912a84c77e6a34abb28f952ba88b18 to your computer and use it in GitHub Desktop.

Select an option

Save tklee1975/65912a84c77e6a34abb28f952ba88b18 to your computer and use it in GitHub Desktop.
// reference: http://danjohnmoran.com/Shaders/101/
Shader "Custom/ShaderCrashCourse/SimpleColorshader"
{
SubShader
{
Tags
{
"PreviewType" = "Plane"
}
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;
};
v2f vertexFunction (appdata _in)
{
v2f _out;
_out.position = UnityObjectToClipPos(_in.vertex); // Convert to screen position
_out.uv = _in.uv; // return the UV mapping
return _out;
}
fixed4 fragFunction (v2f _in) : SV_Target
{
float4 color = float4(_in.uv.x, 0.5, _in.uv.y, 1); // the color is depend the uv position on the mesh
//float4 color = float4(_in.position.x, 0, _in.position.y, 1); // the color is depend the uv position on the mesh
return color;
}
ENDCG
}
}
}
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