0

I use an if-statement without else block. As the images below show, it seems like that the compiler has done some optimizations, making gDiffuseMap_NormalMapping null. However, when I replace the conditional TRUE with a variable of boolean type, which value is set by the application, the shader works. So, I think the differences between static-value optimization and dynamic-value optimization might be the reason why the shader couldn’t work correctly. I would like it explained to me.

if-statement with else block:
image 1: if-statement with else block

if-statement without else block:
image 2: if-statement without else block

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • The two images show the only difference in the shader code is the presence of an empty 'else' block but your question says that the only difference is swapping a hardcoded 'true' with a boolean set by the application (presumably via a uniform). Can you clarify exactly what changes between the working and non-working version. Also what version of DirectX. – Columbo Jun 18 '16 at 21:40
  • I use DirectX11 SM5. There is one one question here. When I use a hardcoded 'true' if-statement without else block, the shader can't work well, just as the images show. I guess it is because the compiler has done some kind of optimization so that the texture sample method has no effect. But when I swap the 'true' with a Boolean set by application, it works. So, the question is now the tautological if-statement without 'else' block doesn't work, if-statement using dynamic conditional without 'else' block works, and if-statement with 'else' block always works. Why and how to fix it? – Aer Lambert Jun 19 '16 at 03:51

0 Answers0