Hazoc Posted April 14, 2013 Share Posted April 14, 2013 Hi I've been porting a certain GLSL -shader into VEX and need to replicate few functions from GLSL. One of them is the sign(float A); function that returns -1, 0 or 1 depending on the sign of the argument. The GLSL function also accepts vector type argument and that's what I'm trying to replicate. Does anyone know how the sign of a vector is actually defined? Now I just test each components sign but I doupt I'm doing the right thing. I've been googling all day without really finding any hints or useful source code. My function sign(vector a) : float sign(vector a) { if (a.x == 0.0 && a.y == 0.0 && a.z == 0.0) {return 0;} else if (a.x < 0.0 || a.y < 0.0 || a.z < 0.0) {return -1;} return 1;}[/CODE]Any ideas?Thanks Quote Link to comment Share on other sites More sharing options...
Hazoc Posted April 14, 2013 Author Share Posted April 14, 2013 Maybe it's this way. Just return a vector of signed components. vector sign(vector a) { return set(sign(a.x), sign(a.y), sign(a.z));}[/CODE] Quote Link to comment Share on other sites More sharing options...
edward Posted April 14, 2013 Share Posted April 14, 2013 I think pyro_math.h has a usable definition so... #include <pyro_math.h> Quote Link to comment Share on other sites More sharing options...
Hazoc Posted April 15, 2013 Author Share Posted April 15, 2013 True! Thanks. I'll show them here. float sign(float x) { return (x>0)-(x<0);}[/CODE][CODE]vector sign(vector x) { return set(sign(x.x),sign(x.y),sign(x.z));}[/CODE] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.