How to map each Pixel to Vertex effectively with OpenGL ES on iOS?Ask Question


Basically, I am trying to build some effect like that on iOS with GLSL.

With what I know, the first step should be create one vertex for each pixel, and then map each vertex with pixel. If this step done, I can adjust the z position of vertex in vertexShader with some logic, then accomplish this effect.

The problem is too slow,such as the front camera is 2MP, there will be 2M vertices in the array.

static const GLfloat squareVertices[] = {
    -1.0f, -1.0f, // bottom left
    1.0f, -1.0f, // bottom right
    -1.0f,  1.0f, // top left
    1.0f,  1.0f, // top right

static const float textureVertices[] = {
   0.0f, 0.0f, // bottom left
   1.0f, 0.0f, // bottom right
   0.0f,  1.0f, // top left
   1.0f,  1.0f, // top right

glVertexAttribPointer( ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices );
glEnableVertexAttribArray( ATTRIB_VERTEX );
glVertexAttribPointer( ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices );
glEnableVertexAttribArray( ATTRIB_TEXTUREPOSITON );

Are there any GL api can do this easily and fast? I am guessing the key might be in THREE.BufferGeometry() and THREE.Points() How did three.js made that?

标签: opengl-es three.js shader
© 2014 TuiCode, Inc.