ways to refer a sampler in shader

Started by
2 comments, last by MJP 14 years, 4 months ago
hello! I wonder what ways can I refer to a sampler in a HLSL shader. for now I have

texture baseMap;

sampler2D sTex0A = sampler_state {
   Texture = <baseMap>;
   MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
};


and in code I call

tex2D( sTex0A, newTexCoord );


but I would like to know wheather I could refer to a sampler by an integer, like in GLSL. In other words, bind a texture to a sampling unit and call this unit in shader. Any suggestions how I could use texture samplers in a different way?
Advertisement
Yup, you can. To do this you explicitly specify a sampler register, and the index of the sampler corresponds to the index you pass to IDirect3DDevice9::SetTexture.

The syntax is like this:
sampler2D samp0 : register(s0);
thanks!
Can I create an array of samplers? like this
texture baseMap;texture baseMapA;sampler2D samplers[16]={sampler_state {   Texture = <baseMap>;   MinFilter = Linear;    MagFilter = Linear;    MipFilter = Linear;},sampler_state {   Texture = <baseMapA>;   MinFilter = Linear;    MagFilter = Linear;    MipFilter = Linear;},..};

What I am up to is to reference a sampler by an index in pixel shader main code.
I would save very many instruction slots and make shaders runnable on pixel shader target 2.0.
You can create an array of samplers, but it won't do you any good if you're looking to save instructions. The array will just be syntactic sugar, since in ps_2_0 assembly you ultimately have to specify a sampler register. It's not possibly to sample by index, like you can in D3D10 with texture arrays. So ultimately the compiler will generate code that samples from multiple samplers, and then chooses between the correct sample based on a comparison. To do true dynamic branching you need at least ps_3_0.

This topic is closed to new replies.

Advertisement