[SOLVED] pc.Vec2 and custom shaders


I’ve been working on a custom shader where I would like to use a vector 2 from an attribute on a script to set a vector 2 in the shader. Unfortunately, this results in a type error. I can easily pass a float to the shader so I was wondering if there’s a compatibility issue between pc.Vec2 and the vec2 used in GLSL?

You have to do something like:

this.vec = new pc.Vec2();
this.vecUniform = new Float32Array(2);

this.vecUniform[0] = this.vec.x;
this.vecUniform[1] = this.vec.y;
material/meshInstance.setParameter(uniformName, this.vecUniform);

Thanks, this works :+1:

1 Like