Vertex&frag

Source: Internet
Author: User

The Vertex&frag type of shader uses shader methods for vertex calculations and pixel calculations.

For example: first through the vertex shader, calculate the model's coordinates and textures, and then pass the pixel shader to calculate the color value.

* Note

_maintex_st and Transform_tex are correspondence, calculating the offset and spread of texture coordinates.

The range of clipping space is [ -1,1], that is, after the MVP matrix, the range of O.POS.X/O.POS.W and O.POS.Y/O.POS.W is [ -1,1] so the clipping space coordinates can be converted to relative screen position of the UV coordinates, as follows O.UV = FLOAT2 ((o.pos.x/o.pos.w+1) *0.5, (o.pos.y/o.pos.w+1) *0.5);

Source:

1Shader"Jqm/vertexandfrag"                                            //file name and path2 {3Properties//Properties4     {5_maintex ("Texture", 2D) =" White" {}6     }7 Subshader8     {9 Ten Pass One         { ACgprogram//Vertex&frag type of shader with CG language -             #pragmaVertex vert -             #pragmaFragment Frag the              -#include"Unitycg.cginc" -  -Sampler2d _maintex;//Property Declaration + float4 _maintex_st; -  +             structAppData A             { at float4 vertex:position; - float2 uv:texcoord0; -             }; -  -             structv2f -             { in float4 pos:sv_position; - float2 uv:texcoord0; to             }; +  -              thev2f Vert (AppData v)//Vertex program *             { $ v2f o;Panax NotoginsengO.pos = Mul (UNITY_MATRIX_MVP, V.vertex);//model View projection matrix, which transfers the model coordinates to the camera coordinates, in the projection to the screen coordinates -O.UV = Transform_tex (V.uv, _maintex);//calculate the values between Uvs and maps the                 returno; +             } A              theFixed4 Frag (v2f i): COLOR//fragment program, Force return color value of color type +             { -                 //Sample The texture $Fixed4 col = tex2d (_maintex, I.UV);//Texture Sampling $                 returnCol; -             } - ENDCG the         } -     }Wuyi}
View Code

Vertex&frag

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.