Introduction to CG 21:fragment shader-2d texture Sampling

Source: Internet
Author: User

Body Texture: What is it? Tex2d previously can only sample the UV coordinate system in the fragment program: In fact, the point is the lower left corner, the range is "0,1", U is the x axis, V is the Y axis

texture.wrapmode Cycle mode: texturewrapmode.clamp: Set texture full stretch use texturewrapmode.repeat:Texture Repeat tile useIf you use Repeat, then the u>=1 is equal to the picture on the right side of the map
texture.filtermode Filter Mode:Point : Pixel filtering (Do not filter )Bilinear: bilineartrilinear: three- wire
UV Texture Sampling:UV Texture
Post-Map effect: The UV coordinates of the stereo space are the upper left corner, U is the horizontal right direction, V is the vertical downward direction, the default range [0,1]
Source:
Shader "Sbin/texshader" {Properties{_maintex ("Texture", 2D) = "White" {}_u ("U", Range ( -0001,0.001)) = 0_v ("V", Range (0,1 ) = 0}subshader{pass{cgprogram#pragma Vertex vert#pragma fragment Frag#include "Unitycg.cginc" sampler2d _MainTex; float _u;float _v;struct v2f{float4 pos:position;float2 uv:texcoord0;}; v2f Vert (Appdata_base v) {v2f O;o.pos = Mul (UNITY_MATRIX_MVP, V.vertex); o.uv = V.texcoord.xy;return o;} Fixed4 Frag (v2f v): color{fixed4 col = tex2d (_maintex, V.UV);//First parameter: texture, second parameter UV vector return col;} ENDCG}}}


texture tiling scale and offset:
Tiling: Scaling the model UV texture sampling coordinates, for example: Tiling x=2, the model UV coordinates of the u to expand twice times, the U range value into 2, if the WrapMode select Repeat, then the U-axis direction will be texture sampling two times. V-Axis similarly
Offset: Offsets the model UV texture sample coordinates; For example: offset x = 0.1, which means to compile the model UV coordinates to the left and then sample the UV texture map.

Both of these actions result in the following effects:

Introduction to CG 21:fragment shader-2d texture Sampling

Related Article

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.