original articles should be reproduced please specify: Reproduced from the Wind Yu Chong Unity3d Tutorial CollegeVertex and Fragment Shader: The most powerful type of Shaderis also the focus of this series, hereinafter referred to as V&f Shader, which belongs to the programmable rendering pipeline. The CG/HLSL syntax is used. Divided into 2 parts vertex vertex and fragment pixel portions.the following still learn by writing a few simple shader.
Example one: displaying a decal
Create a new Unity project, create a new cube cube, create a new Shader named EXAM1 (Project View->create->shader), and enter the following code.
Shader "custom/exam1" { Properties { _maintex ("Texture", 2D) = "White" {} } subshader { pass< c6/>{ cgprogram #pragma vertex vert #pragma fragment frag #include "unitycg.cginc" sampler2d _ Maintex; FLOAT4 _maintex_st; struct V2F { float4 pos:sv_position; Float2 uv:texcoord0; }; v2f Vert (Appdata_base v) { v2f o; O.pos = Mul (Unity_matrix_mvp,v.vertex); O.UV = Transform_tex (V.texcoord,_maintex); return o; } FLOAT4 Frag (v2f i): COLOR { float4 texcol = tex2d (_MAINTEX,I.UV); FLOAT4 outp = Texcol; return OUTP; } ENDCG }}}
Detailed explanations such as
We then set the shader of the previously created cube to exam1,inspector with corresponding texture. Then the third line of code "Texture" changed to "Exam 1 Texture", then back to the Inspector panel, you will find what? Yes, the name hints of the stickers have changed accordingly. As simple as this, you have learned to assign arbitrary maps to arbitrary models.
Unity3d Tutorial Shader: The third lecture vertex&fragment Shader