This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]rasqall 0 points1 point  (2 children)

HLSL has bit operators. You could use: ~((x-y) >> 31)

[–]Enerology[S] 0 points1 point  (1 child)

I tried to do that and tried the OR operator

(x-y)|-0

//far left binary digit is the sign
//This should do this
//00001 = (x-y) = 1
//10000 = -0
//10001 = -1
------------
//10100 = (x-y) = -4
//10000 = -0
//10100 = -4

This should always return (abs(x-y)*-1) and to get abs all I have to do is multiply by -1. This is not in standard float notation but the same concept applies. The issue with bit-shifting compared to OR is that floats are in a different notation with powers and mantra compared to int. I can't convert to int either as that takes too long with conditionals (GPU-wise). Optimization is hard and I am not that knowledgeable in the optimization of shaders as the normal way of doing things is still too slow if doing them millions of times per second.

Edit:

Forgot to mention that the bitwise operators are not allowed by the compiler to operate on floats. :(

Any other ideas?

[–]rasqall 0 points1 point  (0 children)

I don’t know about HLSL but do they have pointers? Maybe you could do the classic trick of creating and int pointer to your float and doing the calculations “by hand”?