Multipication of vector4 and matrix4x4 in OpenCL node

   1285   1   0
User Avatar
Member
59 posts
Joined: April 2006
Offline
Hi,
I am translating some VEX code to OpenCL. The code gets the screen 2d position from a 3d point, given a camera (basically I am trying to reproduce the toNDC function in OpenCL). After getting the needed values, I have this operation working fine in VEX:
pos *= invert(cam) * persp;

Where pos is a vector 4 and cam and persp are matrix4.

Unfortunately this gives me an error in OpenCL, I believe I have to operate in a different fashion but I cannot find how. It appears I cannot use “invert” and I have to somehow use the same scale. Any help is very much appreciated.

These are the errors I get:
OpenCL Exception:
<kernel>:33:14: warning: implicit declaration of function 'invert' is invalid in C99
     pos *= invert(cam) * persp;
<kernel>:34:11: error: can't convert between vector values of different size ('__attribute__((address_space(16776963))) float4' and 'float __attribute__((ext_vector_type(16)))')
     pos *= invert(cam) * persp;

Thanks!
Edited by perpen - Dec. 26, 2019 15:36:02
User Avatar
Member
59 posts
Joined: April 2006
Offline
After some wall head hitting this worked for me:

    float3 pos = vload3(idx, P);
    float4 Ph = (float4)((pos[0]*camMatrix[0])+(pos[1]*camMatrix[4])+(pos[2]*camMatrix[8])+(1*camMatrix[12]),
                            (pos[0]*camMatrix[1])+(pos[1]*camMatrix[5])+(pos[2]*camMatrix[9])+(1*camMatrix[13]),
                            (pos[0]*camMatrix[2])+(pos[1]*camMatrix[6])+(pos[2]*camMatrix[10])+(1*camMatrix[14]),
                            (pos[0]*camMatrix[3])+(pos[1]*camMatrix[7])+(pos[2]*camMatrix[11])+(1*camMatrix[15]));

Based on this:
https://gamedev.stackexchange.com/questions/136573/multiply-matrix4x4-with-vec4 [gamedev.stackexchange.com]
  • Quick Links