Shader learning experience (2): Insert snippets for FX functions and implementation of texture shader

Source: Internet
Author: User

 The following tutorial is original from the technical hut of turtles and donkeys.ArticleSource, and keep this paragraph, do not infringe. Shader learning experience 2: insert snippets of FX function, and texture: 2.1 adds texture for our shader

Step 1:In ourEmpty EffectMedium:

Float4x4 worldviewproj: worldviewprojection;

Right-click the following line,Select"Insert snippets"

Select"Texture and sampler"

InNameDouble-click,ChangeDiffuse,So all"Name"It is automatically changed"Diffuse"Now

Step 2: AddProgramSegment,MakeCodeChange

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 ();

}

}

Step 2:Select ourEmpty EffectFile,In the upper-right cornerPropertyTableParameterIn"Diffuse texture"Select a texture file you like.

Step 3:PressCTRL + F7,CompileShader,ThenShaderDrag to the object we want to display

2.2 explain the meaning of the Code

Texture diffuse <

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

String uiname = "diffuse texture ";

String resourcetype = "2D ";

>;

Many people may<... >The content in,In factDirectXIs of little use,The main function is to makeFX composerCan identify our parameters,In addition, the parameter panel displays,Easy to modify

 

Return tex2d (diffusesampler, Tex );

AccordingDiffusesampleSamplezer,PairTexInterpolation of corresponding texture coordinates,If you do not understand this Code clearly,Please search for this by yourselfHLSLRelated books.The number of references starting with Chapter 1 may be helpful to you

 

2.3 Running Effect

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.