Jump to content
  • Advertisement
Sign in to follow this  

Uploading SamplerComparisonState in HLSL

This topic is 1221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I used effects11, I used to declare them entirely in the shader code. Now I am not using effects11. So, how am I supposed to declare and send SamplerComparisonState to HLSL?


Here is my sampler in HLSL Shader:

SamplerComparisonState SamplerShadow : register(s1);


How shall I declare it in the C++ code and send it to the shader?

Share this post

Link to post
Share on other sites

Don't know, but maybe this doesn't seem to work. I am trying to do shadow mapping and I checked shadow map is getting rendered correctly but all I see is everything is unlit. That means shadow factor is zero. The Shadowmap is ok (I checked). So now, I suspect it's the SamplerComparisonState not getting correctly uploaded or projective texture coordinates not getting correctly or Shadow map not getting correctly uploaded (although I checked this).

This doesn't seem to work sad.png
ShadowFactor[0] is always zero.

float ShadowFactor[MAX_DIR_LIGHTS] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
if (NumDirLights > 0)
float4 ambient = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 spec = float4(0.0f, 0.0f, 0.0f, 0.0f);
ShadowFactor[0] = CalculateShadowFactor(SamShadow, ShadowMap, pin.ShadowPosH);
for (int i = 0; i < NumDirLights; ++i)
float4 A, D, S;
ComputeDirectionalLight(ObjectMaterial, DirLights[i], pin.NormalW, toEye, A, D, S);
ambient += A;
diffuse += D * ShadowFactor[i];
spec += S * ShadowFactor[i];
FinalColor = TexColor * (ambient + diffuse) + spec;
FinalColor.a = ObjectMaterial.Diffuse.a * TexColor.a;

EDIT: I confirmed and I am 200% sure that the issue is related to SamplerComparisonState (SamShadow). Cause I declared a undefined SamplerComparisonState and passed it in CalculateShadowFactor() instead of SamShadow and I got the same result.

EDIT: GOT THE ISSUE! biggrin.png

I used D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT instead of D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT while declaring SamplerComparisonState in D3D11 API. Just one typo made me work all day long on this tongue.png

Edited by newtechnology

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!