Jump to content

  • Log In with Google      Sign In   
  • Create Account


[DX11] HLSL 5 setting SamplerState from within the shader isn't working


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 RythBlade   Members   -  Reputation: 152

Like
1Likes
Like

Posted 20 April 2012 - 03:35 AM

Hi there,
I'm having some trouble with a hlsl shader I've written for a deferred shader to do texture mapping onto a road in my game.
Basically I define a SamplerState at the top of my shader which I then use to sample my textures to map onto the surface.
I've defined it based on the MSDN documentation so that I shouldn't need to create and set and Samplers from within my C++ code and it can all be done from within the shader.
However when I run it, the sampler seems to be ignored. The directx debug gives the following warning:

D3D11: WARNING: ID3D11DeviceContext::Draw: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.  [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET ]

Here are the relevant code snippets from my shader:
// textures are passed in from my application
Texture2D widthMap  : register ( t0 );
Texture2D lengthMap  : register ( t1 );
// the sampler state defined in shader code so that my application
// doesn't have to
SamplerState MySampler
{
Filter = MIN_MAG_MIP_POINT;
    AddressU = Wrap;
    AddressV = Wrap;
};
// pixel shader which samples the texture
POut PShader(PIn input)
{
.....
output.colour = float4(lengthMap.Sample(MySampler, float2(input.texCoord.y, 0.0f)));
......
return output;
}


Ignore the dodgy texture coordinate - the premise for my texture sampling is to "build" the actual texture out of 2 textures which define the u colour and v colour - when both the u and v are filled in then I use the colour, otherwise that pixel is set to black - I'm using it to generate the road lines so that I can define any road line layout I want based on 2 very small textures.

I've dug through a few of the DirectX samples and I can see them declaring the SamplerState at the top just like I have and seem to have no such problems.
I've also tried declaring a samplerstate for each texture I want to sample and within each state I set the "Texture" field to the target texture. I changed it to the current version as this is how the directx samples seem to do it.

This problem is also present everywhere I sample a texture in my deferred shaders as well!

I've got no idea what I've missed. I can't see any settings that I need to set to tell DirectX to use what ever the shader itself supplies, as far as I was aware - declaring it in my shader should work fine.

I can post more examples of my shader files if needed.

Has anyone got any suggests???

Thanks very much!!
I've got a new blog!! I post details of my projects, useful things I find around and about the place and some tutorials on various technologies I'm experimenting with.

Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2338

Like
2Likes
Like

Posted 20 April 2012 - 03:49 AM

Are you using the effect framework? If not, as far as I know, you'll need to create the sampler (with the desired settings) in the program side and bind it to the register.

Best regards!

#3 RythBlade   Members   -  Reputation: 152

Like
1Likes
Like

Posted 20 April 2012 - 04:02 AM

No I'm not.....goddamn it! I was hoping for a quick win.....Ok. Yeah it looks like you're right, just stumbled onto this post after reading your reply. It seems my google-fu is still not as strong as I'd hoped.
Thanks very much for the help!
I've got a new blog!! I post details of my projects, useful things I find around and about the place and some tutorials on various technologies I'm experimenting with.

#4 RythBlade   Members   -  Reputation: 152

Like
1Likes
Like

Posted 20 April 2012 - 04:05 AM

For all those that are interested - just found this post which discusses a nice way to deal with this situation, which is what I'm now going to do. The developer automatically sets up a set of SamplerState objects in their engine and set them in the shaders by default. The shaders have a common include containing the register references for all of these so that all shaders have access to set of samplers etc automatically.

[Edit:] Though I'd give a quick update - this method works fantastically - all my shaders now have immediate access to any samplers they might need and its simplified my some parts of my engine code a lot! Works perfectly.
I've got a new blog!! I post details of my projects, useful things I find around and about the place and some tutorials on various technologies I'm experimenting with.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS