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






