Created
August 4, 2017 08:07
-
-
Save tklee1975/16dc968f1520a980e8a84ff7bcde494b to your computer and use it in GitHub Desktop.
Unity Basic Shader Crash Course
This file contains hidden or 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/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