float4x4 WVP;
texture cubeTexture;
sampler TextureSampler = sampler_state
{
texture = <cubeTexture>;
MipFilter = Point;
MagFilter = Point;
MinFilter = Point;
AddressU = Wrap;
AddressV = Wrap;
MaxAnisotropy = 16;
};
Run Code Online (Sandbox Code Playgroud)
因此,如果我没有弄错,这告诉采样器状态我正在使用什么纹理.我正在为许多精灵使用一个效果文件,因此这允许我使用一个纹理(图集).我可以把我所有纹理的地图集合成一个大爸爸地图册,但我担心这些并发症.
有没有办法让像素着色器通过其参数使用某个纹理?我是HLSL的新手,对我来说很困惑.
如果您为着色器提供语义来引用寄存器,就像这样
// HLSL
sampler TextureSampler : register(s1);
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用GraphicsDevice.Textures游戏代码中的属性在代码中指定纹理
// C#
Texture2D texture2D = Content.Load<Texture2D>("contentfile");
graphicsDevice.Textures[1] = texture2D;
Run Code Online (Sandbox Code Playgroud)
我使用寄存器1而不是0,因为纹理参数Spritebatch.Draw()使用寄存器0.如果你不是spritebatching,可以随意使用寄存器0;