• Advertisement
Sign in to follow this  

ways to refer a sampler in shader

This topic is 2981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement