   sampler_state not working [solved]
  I can't seem to get my sampler to work and would like to know whats wrong. I create a sampler and try to give it a filter based on the examples from msdn but it seems to just sample as floor(TEXCOORD0) instead of nearest point or bilinear.Pixel Shader v2.0sampler2D x : register(s0) = sampler_state {mipfilter = LINEAR;minfilter = LINEAR;magfilter = LINEAR;};void ps(float2 coords : TEXCOORD0, out float4 color : COLOR) {float2 pos = float2(.75/128.0,0);color = tex2D(x,pos);}which outputs as black with this texture, when it should be either white if nearest point or some offwhite if bilinear. If I change float2(.75/128.0,0) to float2(1/128.0,0) it correctly outputs white.My setup code looks as follows//load textureD3DXCreateTextureFromFile( g_pd3dDevice, "lines.bmp", &pTexture );//renderg_pd3dDevice->BeginScene();g_pd3dDevice->SetTexture( 0, pTexture );g_pd3dDevice->SetTexture( 1, pTexture2 );g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );g_pd3dDevice->SetPixelShader( g_pPixelShader );g_pd3dDevice->SetFVF( FVF );g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );g_pd3dDevice->EndScene();g_pd3dDevice->Present( NULL, NULL, NULL, NULL );Also, if I change the shader to just output tex2D(x,coords) then it correctly displays the texture.[Edited by - StormArmageddon on June 21, 2006 5:55:46 PM]
  Have a look at Directly Mapping Texels to Pixels. Also available in the SDK under the same name.Hope this helps.   ;  Thanks sirob, but doesn't exactly tell why I'm not getting any kind of filtering at all. I changed my sampler_state to use MinFilter = Linear; syntax instead but it didn't change anything.   ;  If you want to sample the center of a pixel, you need to add half a pixel to it's texcoords, or you'll be sampling the edge.   ;  The problem is I don't want to sample the center of a pixel, I want to sample all 4 surrounding pixels using bilinear filtering. All I'm getting is values from the center of a pixel even though what I pass tex2D is clearly not the center of a pixel.   ;  What texture format are you sampling from?You should really be using IDirect3D9::CheckDeviceFormat() with D3DUSAGE_QUERY_FILTER to be sure of anything above POINT filtering.In particular, if you're using any of the FP32 formats you can't/won't get filtering and if you're using FP16 formats you'll only get filtering on recent hardware (Gf6/Gf7 and ATI X1k's)...hthJack   ;  I'm currently using A8R8G8B8 for my texture, so it  doesn't fall under the FP32 or FP16 category (since I assume FP stands for floating point).So basically if I want to blend 4 texels together using my texture format, I need to do it manually in my pixel shader? I would think my Radeon 9800 would be able to do that for me but CheckDeviceFormat() fails with D3DUSAGE_QUERY_FILTER so I guess not.Does HLSL have some prebuild function to do Bilinear Filtering? I suppose I could use lerp(lerp(),lerp(),s) but that seems messy.   ;  hmm, strange...Up until recently I was using a Radeon 9800 - and I know for definite that it does to linear filtering without any clever HLSL tricks. I had to implement bilinear filtering for FP16/FP32 targets (Yes, FP = Floating Point!), but thats to be expected.I'm wondering if your sampler declaration is actually wrong due to the register(s0) part. All my sampler declarations are like:texture texDiffuse;sampler2D sampDiffuseTex = sampler_state{    Texture   = (texDiffuse);    MinFilter = LINEAR;    MagFilter = LINEAR;    MipFilter = LINEAR;};You could try appending : register( s0 ); to the end of the texture texDiffuse; declaration in the above fragment.Bare in mind that mapping to specific samplers isn't always guaranteed. If you're using s0, s1 and s2 but optimizations eliminate s1 then you won't be left with s0 and s2 - it'll move s2 back to s1 such that it only uses s0 and s1...If you're not using the effects framework you should still be able to use the ID3DXConstantTable to decode regular texture declarations without the register qualifier.hthJack   ;  Well, I got it working, just had to change SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ) to SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ). As for sampler_state, I'm guessing it doesn't work under pure pixel shaders and only works under the effects framework.   ;Quote:Original post by StormArmageddonWell, I got it working, just had to change SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ) to SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ).For a generalised solution, you probably want to include both MIN and MAG lines in your application. Otherwise you'll start getting artifacts if/when you make your geometry smaller [smile]Quote:Original post by StormArmageddonAs for sampler_state, I'm guessing it doesn't work under pure pixel shaders and only works under the effects framework.hmm, that could be a slightly obvious answer actually. It's been a while since I last used pure pixel shaders - its easy to forget just how much the effects framework takes care of!Jack