Unity3d Tutorial Shader: The third lecture vertex&fragment Shader

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.