Search code examples
xnatextureshlsl

How to get the texture size in HLSL?


For a HLSL shader I'm working on (for practice) I'm trying to execute a part of the code if the texture coordinates (on a model) are above half the respective size (that is x > width / 2 or y > height / 2). I'm familiar with C/C++ and know the basics of HLSL (the very basics). If no other solution is possible, I will set the texture size manually with XNA (in which I'm using the shader, as a matter of fact). Is there a better solution? I'm trying to remain within Shader Model 2.0 if possible.


Solution

  • The default texture coordinate space is normalized to 0..1 so x > width / 2 should simply be texcoord.x > 0.5.