2.1 为我们的shader增加贴图
Step 1: 在我们的Empty Effect中:
float4x4 WorldViewProj : WorldViewProjection;
下面一行按右键,选择”Insert Snippets”
在右边的框中选择”Texture and Sampler”
在打了一个框的Name上面双击,修改为diffuse,这样所有的”Name”就自动变 为了”diffuse”了
Step 2: 添加程序段,使得代码变为
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();
}
}