Last active
May 17, 2019 14:38
-
-
Save gergely-xyz/f8464ecae063d562e6714e0771d2c5a8 to your computer and use it in GitHub Desktop.
Unity Shader Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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