Shader learning Experience (2): The function of FX insert Snippets, and the shader implementation of the map

Source: Internet
Author: User
Tags insert

2.1 Add maps for our shader

Step 1: In our empty effect:

float4x4 worldviewproj:worldviewprojection;

Right-click the following line and select Insert Snippets

Select "Texture and Sampler" in the box to the right

Double-click on the name of a box and modify it to diffuse so that all "Name" becomes "diffuse" automatically.

Step 2: Add the program segment so that the code becomes

float4x4 worldviewproj:worldviewprojection;

Texture Diffuse <

String resourcename = "";//optional default file name

String uiname = "diffuse texture";

String resourcetype = "2D";

>;

Sampler2d Diffusesampler = sampler_state {

Texture = <diffuse>;

Minfilter = Linear;

Magfilter = Linear;

Mipfilter = Linear;

Addressu = Wrap;

ADDRESSV = Wrap;

};

struct Vs_output

{

FLOAT4 pos:position;

FLOAT2 tex:texcoord0;

};

Vs_output Mainvs (float4 pos:position,float2 tex:texcoord0) {

Vs_output vsout;

Vsout.pos = Mul (pos,worldviewproj);

Vsout.tex = Tex;

return vsout;

}

Float4 Mainps (float2 tex:texcoord0): COLOR {

Return tex2d (Diffusesampler, Tex);

}

Technique TECHNIQUE0 {

Pass P0 {

VertexShader = Compile vs_3_0 Mainvs ();

PixelShader = Compile ps_3_0 Mainps ();

}

}

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.