# Creating a new sampler state without a shader?

## Recommended Posts

_damN_    127
Hi! Im trying to create a new sampler state using D3D10,so i can add texture filtering but i dont want to do it within a shader. I dont think its working because i cant seem to see a difference at all? This is what it looks like...
Quote:
I cant find any decent DX10 examples on the net and if i do find one they use a shader. Can anybody help? Thanks!

##### Share on other sites
elurahu    258
I find your question a bit confusing - Since DX10 only allows rendering to be done through shaders what would you do with a device with texture filtering applied?

Secondly the sampler creation below doesn't require a shader interface, only a functional device.

Could you try and specify what exactly you need to do.

##### Share on other sites
Neilo    290
I think he wants to specify the sampler state in C++ code as opposed to in a D3D10 Effects file.

When you declare the sampler in HLSL did you specify a register to put it in?

##### Share on other sites
_damN_    127
Apologies... Let me try and clear things up. Im pretty new to directX. I want to turn on texture filtering so i can render my cube using the filter D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR or D3D10_FILTER_ANISOTROPIC and play around with texture qualities.

Are you saying i will only be able to do this in a shader? There are so few tutorials on DX10 on the net its difficult to know how to do this properly. I have a book which shows you how to do this in a shader but i dont really wanto do it in a shader, i wanto do it it my code(source file) itself. There has to be a way, surely!

Does that make a bit more sense? How would i fill the descriptor and set it to active?

Thanks

##### Share on other sites
_damN_    127
I nice code example would be greatly apreciated!

Quote:
 I think he wants to specify the sampler state in C++ code as opposed to in a D3D10 Effects file.When you declare the sampler in HLSL did you specify a register to put it in?

What do you mean? Isnt that only when i use a shader? You are right, i want to do it in C++ code instead of in an effect file.

##### Share on other sites
Neilo    290
Well, the code sample you showed is correct, but you still need a pixel shader and you need to refer to the sampler state in it even if you set it in code.

If you're new to all of this, I would just stick to declaring states in a .fx file. The Effect Framework is there to make your life easier.

##### Share on other sites
MJP    19788
Your code for filling out the D3D10_SAMPLER_DESC looks okay. However you want to create sampler states at initialization time, not at runtime. At runtime you only want to set states. Make sure you set the sampler state after applying an effect pass, otherwise the effect pass will override your state. Also, make sure that you're setting the sampler state to the correct sampler index. You can manually bind a sampler to an index in your HLSL like this:
SamplerState LinearSampler : register(s0);

##### Share on other sites
_damN_    127
You mean like so...

SamplerState gTriLinearSam: register(s0)
{
Filter = MIN_MAG_MIP_LINEAR;
};

???

##### Share on other sites
DieterVW    724
Quote:
 Original post by _damN_You mean like so... SamplerState gTriLinearSam: register(s0){ Filter = MIN_MAG_MIP_LINEAR;};???

That is effects code when you include the initializer data. The pure HLSL bit is just

SamplerState gTriLinearSam: register(s0);

You don't need anything else in the HLSL code. The creation and binding will all happen in the runtime code by you.

##### Share on other sites
_damN_    127
There we go! It works! Thanks dude!

##### Share on other sites
_damN_    127
Sorry, i thought it was working because i saw a change in texture quality, but its not working. If i change the filter value, there is no difference.

I done as you said and put the
SamplerState LinearSampler : register(s0);

in the effect file. What could the problem be?

##### Share on other sites
_damN_    127
God i can be such an idiot.

I was applying it before the effect pass.. Sorry it is working..

THANKS! :-D