Sign in to follow this  
JohnnyCode

ways to refer a sampler in shader

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this