Skip to content

Instantly share code, notes, and snippets.

@gergely-xyz
Last active May 17, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergely-xyz/f8464ecae063d562e6714e0771d2c5a8 to your computer and use it in GitHub Desktop.
Save gergely-xyz/f8464ecae063d562e6714e0771d2c5a8 to your computer and use it in GitHub Desktop.
Unity Shader Template
Shader "Custom/Example" {
Properties{
_MainTexture("Main texture", 2D) = "white" {}
_Color("Color", Color) = (0,0,0,0)
}
SubShader{
Pass{
CGPROGRAM
// Give the name of the vertex and fragment functions
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc" // Helpful math functions
// Incoming data from the application
struct appdata{
float4 vertex : POSITION; // points from the mesh
float2 uv : TEXCOORD0; // texture coordinates for the mesh
};
// Vertex function output for the frag function
struct v2f{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
// Material variables
sampler2D _MainTexture;
float4 _Color;
// VERTEX
v2f vert(appdata IN){
v2f OUT;
// Apply the Model View Projection transformation (perspective)
// same as OUT.position = mul(UNITY_MATRIX_MVP, IN.vertex);
OUT.position = UnityObjectToClipPos(IN.vertex);
// Pass on the texture coordinates we got
OUT.uv = IN.uv;
return OUT;
}
// FRAGMENT
fixed4 frag(v2f IN) : SV_TARGET{
fixed4 textureColor = tex2D(_MainTexture, IN.uv);
textureColor *= _Color;
return textureColor;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment