SampleCmp() always returns zero #249
-
I have a very basic question about the use of I'm using an immutable sampler in the pixel shader (DX12) to call the method. Generally, I have the sampler set to clamp all axes and with linear filtering and comparison mode set to less than. But even when I set the comparison mode to always, I still get zero. Is there any reason something like this would be happening that comes to mind? I've verified that the texture and surrounding code is all working correctly by doing a manual comparison ( I've run out of ideas as to what might be causing this. I thought maybe my sampler in code is not linking up correctly with my shader sampler, but that should throw an error. Any ideas what might be going wrong here? Edit: this is how I've defined these elements in code:
Edit 2: I'm getting some really strange behavior from further testing, such as this: |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Does shadow map tutorial work properly? |
Beta Was this translation helpful? Give feedback.
-
I can't think of anything obvious which is why I am suggesting to copy the working version verbatim and start changing it step-by-step until you find at which step it breaks |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, it uses separate pipeline states, and my engine uses a shared global resource signature. That fact makes it difficult to test things. If I remember correctly, the only sample that uses the shared pipeline architecture is the ray tracing sample, but it won't run on my hardware. If you ever find the time, some basic tutorials with shared resource signatures would be really helpful. I assume most complex game engines will need to use them, so that many entities can share resources. Although its been a while since I used anything else, so its hard to remember all of the differences. But as far as the issue - I'm not going to say I'm sure its not something I've caused, but if it is, it would be something that exclusively makes I guess another good test would be to use the comparison sampler with another sampling function, to see if it is the sampler or the function that is not working correctly. But I don't think any other sampler functions exist that use it. |
Beta Was this translation helpful? Give feedback.
-
I'm still trying to narrow down the problem with this, but I did stumble onto a similar post online where a DX11 user was getting depth value reads from SampleCmp() instead of true/false reads, and it turned out he set up his filter incorrectly. That leads me to believe that any type of issue with the sampler properties may cause SampleCmp to do something weird and unexpected - something its not designed to do. Apparently the function does some type of "I can't do my job, so I'll do this instead". I really need to learn to use the pix debugger, or some other shader debugger. It would probably be very useful in situations like this. |
Beta Was this translation helpful? Give feedback.
-
Well, I figured it out. And wow do I feel like an idiot. While looking over the shadowmap tutorial again, for the 20th time, I finally noticed it is using a specific type of linear filter for shadowmap sampling: |
Beta Was this translation helpful? Give feedback.
I can't think of anything obvious which is why I am suggesting to copy the working version verbatim and start changing it step-by-step until you find at which step it breaks