Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the GLSL sign() function cause branching and how does it work?

Tags:

glsl

It seems like some functions that have outputs in cases might use an if statement as the underlying implementation, thus causing branching. I don't think it does, but I wonder.

For sign(x), if the number is positive, negative, or zero, it reruns 1, -1 and 0 respectively.

So how does this function work?

like image 407
Thomas Avatar asked Feb 15 '23 06:02

Thomas


1 Answers

Implementation details are always implementation-specific. So how this construct is implemented depends entirely on the vendor (and ultimatively, the abilities of the underlying hardware).

However, it is extremely unlikely that any real-world implementation would use a branch for the sign() opertation. The sign can be easily determined by looking at the sign bit which is present in most real-world floating-point formats, especially IEE 754. This can be easily implemented with logic - much easier as your typical floating point arithmetic function.

like image 52
derhass Avatar answered May 19 '23 02:05

derhass