Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vec2, vec3, vec4 support #7

Closed
fuzzie360 opened this issue Feb 19, 2016 · 6 comments
Closed

vec2, vec3, vec4 support #7

fuzzie360 opened this issue Feb 19, 2016 · 6 comments

Comments

@fuzzie360
Copy link
Member

Vectors are very useful for graphical computations so it would be very useful to support vec variables and function arguments and function returns.

When it's implemented it could look like:

function kernel() {
    var v = this.vec2( 1, 2 );
    var mag = Math.sqrt(v.x*v.x + v.y*v.y);
}

The "this" context variable can provide the vec2 function in fallback mode just like this.thread.x and etc.

Challenges:

  • Appear to need type inference for variable v which might not be feasible. Either that or commented annotations like: /*vec3*/var v = ... which might look very ugly.
@sawman
Copy link
Contributor

sawman commented Feb 19, 2016

I think type inference for variables for now is a good target to work towards. We can work on type inference for functions if we move on to higher order functions.

@sawman sawman self-assigned this Feb 19, 2016
@PicoCreator
Copy link
Contributor

As of now, the addFunction, allows one to overwrite the return type.

    ///
    /// Function: addFunction
    ///
    /// Adds additional functions, that the kernel may call.
    ///
    /// Parameters: 
    ///     jsFunction      - {JS Function}  JS Function to do conversion   
    ///     paramTypeArray  - {[String,...]} Parameter type array, assumes all parameters are "float" if null
    ///     returnType      - {String}       The return type, assumes "float" if null
    ///
    /// Retuns:
    ///     {GPU} returns itself
    ///
    function addFunction( jsFunction, paramTypeArray, returnType  ) {

This is without the "auto-voodoo" type inference. A similar implementation can be done for the kernel creation function.

Note that internally the kernal also use the FunctionBuilder.addFunction call. But has isRootKernel set to true for some conditional voodoo.

Successful implementation of voodoo can jack into this.

@PicoCreator PicoCreator modified the milestone: who-knows-when-beta Apr 19, 2016
@sawman
Copy link
Contributor

sawman commented Apr 29, 2016

For now we go with this.vec2(0,1) to declare vecs bah, so that in jsland we can have a.x, a.y type syntax. I'll go with that and implement the proper objects.

@fuzzie360
Copy link
Member Author

Okay let's formalize this.

Let's support the following operations:

this.vec3(1) => (1,1,1)
this.vec3(1,2,3) + this.vec3(1,2,3) => (2,4,6)
this.vec3(1,2,3) - this.vec3(1,2,3) => (0,0,0)
this.vec3(1,2,3) + 1 => (2,3,4)
this.vec3(1,2,3) * 2 => (2,4,6)
this.vec4(1, this.vec3(2,3,4)) => (1,2,3,4)
this.vec3(1,2,3).r => 1
this.vec3(1,2,3).x => 1
this.vec3(1,2,3).s => 1
this.vec3(1,2,3).zyx => (3,2,1)
var x = this.vec3(1,2,3)
x.zyx = x.xyz; => (3,2,1)
x.xxx => (1,1,1)

And of course, bonus would be

var x = [1,2,3] => auto vec3

@robertleeplummerjr
Copy link
Member

I believe this is solved, can anyone confirm?

@robertleeplummerjr
Copy link
Member

Fully supported now in v2 rc 13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants