使用Rajawalirenderer渲染彩色pointcloud

时间:2015-11-12 17:25:29

标签: rendering opengl-es-2.0 google-project-tango rajawali

由于在https://github.com/googlesamples/tango-examples-java/tree/master/PointCloudJava中发布了yamabe并且使用了rajawali渲染器,因此根据与3D相机的距离不再对点云进行着色。 我尝试将Points.java的代码调整为以下内容,以便再次获得相同的功能:

public class Points extends Object3D {


    private static final String sVertexShaderCode = "uniform mat4 uMVPMatrix;"
            + "attribute vec4 vPosition;" + "varying vec4 vColor;"
            + "void main() {" + "gl_PointSize = 5.0;"
            + "  gl_Position = uMVPMatrix * vPosition;"
            + "  vColor = vPosition;" + "}";
    private static final String sFragmentShaderCode = "precision mediump float;"
            + "varying vec4 vColor;"
            + "void main() {"
            + "  gl_FragColor = vec4(vColor);" + "}";





private int mMaxNumberofVertices;


public Points(int numberOfPoints) {
    super();
    mMaxNumberofVertices = numberOfPoints;
    init(true);
    Material m = new Material(new VertexShader(sVertexShaderCode), new FragmentShader(sFragmentShaderCode));
    //m.setColor(Color.GREEN);
    setMaterial(m);
}

// Initialize the buffers for Points primitive.
// Since only vertex and Index buffers are used, we only initialize them using setdata call.
protected void init(boolean createVBOs) {
    float[] vertices = new float[mMaxNumberofVertices*3];
    int[] indices = new int[mMaxNumberofVertices];
    for(int i = 0; i < indices.length; ++i){
        indices[i] = i;
    }
    setData(vertices, GLES20.GL_STATIC_DRAW,
            null, GLES20.GL_STATIC_DRAW,
            null, GLES20.GL_STATIC_DRAW,
            null, GLES20.GL_STATIC_DRAW,
            indices, GLES20.GL_STATIC_DRAW,
            true);

}

// Update the geometry of the points once new Point Cloud Data is available.
public void updatePoints(FloatBuffer pointCloudBuffer, int pointCount) {
    pointCloudBuffer.position(0);
    mGeometry.setNumIndices(pointCount);
    mGeometry.getVertices().position(0);
    mGeometry.changeBufferData(mGeometry.getVertexBufferInfo(), pointCloudBuffer, 0, pointCount * 3);
}

public void preRender() {
    super.preRender();
    setDrawingMode(GLES20.GL_POINTS);
    GLES10.glPointSize(5.0f);
}

}

但这些点只是红色而不是有不同的颜色。 我对Rajawali和OGL很新,所以有人可以告诉我,我错过了什么部分才能让着色器在点类上工作。

非常感谢彼得。

0 个答案:

没有答案