But if x is not a scalar, obviously I can't use the "<" operator.
You can simply do this:
if (x < 0 || y < 0 ) discard;
According to clip(x) documentation (emphasis mine):
Use the clip HLSL intrinsic function to simulate clipping planes if
each component of the x parameter represents the distance from a
plane.
According to the docs x
could be a scalar a vector or a matrix.
Which means, if any of the components where less than zero it discards the pixel, this is true since if each of x
,y
,z
represented a distance to a plane, this means than anyone of them being less than zero means the pixel should be clipped/discarded. Which makes the implementation boils down to the original form:
if (x < 0 || y < 0 || z < 0 ) discard;
but I will be surprised if the compiler was not able to detect this pattern and optimize by replacing it with it's appropriate assembly instruction.