Rendering 使用Rajawali渲染器渲染彩色点云

Rendering 使用Rajawali渲染器渲染彩色点云,rendering,opengl-es-2.0,google-project-tango,rajawali,Rendering,Opengl Es 2.0,Google Project Tango,Rajawali,自从yamabe在中发布并使用rajawali渲染器以来,点云不再根据到3D相机的距离而着色。 我尝试将Points.java的代码改编为以下代码,以再次获得相同的功能: public class Points extends Object3D { private static final String sVertexShaderCode = "uniform mat4 uMVPMatrix;" + "attribute vec4 vPosition;" +

自从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);
}
公共类点扩展Object3D{
私有静态最终字符串sVertexShaderCode=“uniform mat4 uMVPMatrix;”
+“属性vec4 vPosition;”“+”可变vec4 vColor;”
+“void main(){”+“gl_PointSize=5.0;”
+“gl_Position=uMVPMatrix*vpposition;”
+“vColor=vPosition;“+”}”;
私有静态最终字符串sffragmentshadercode=“precision mediump float;”
+“可变vec4颜色;”
+“void main(){”
+“gl_FragColor=vec4(vColor);”+“}”;
私有int-mmaxNumberOfVertexts;
公共积分(国际点数){
超级();
mMaxNumberofVertices=numberOfPoints;
init(真);
材质m=新材质(新顶点着色器(sVertexShaderCode)、新碎片着色器(SfFragmentShaderCode));
//m、 setColor(Color.GREEN);
设置材料(m);
}
//初始化点原语的缓冲区。
//因为只使用顶点和索引缓冲区,所以我们只使用setdata调用初始化它们。
受保护的void init(布尔createVBOs){
float[]顶点=新的float[mmaxNumberOfVertexts*3];
int[]索引=新的int[mmaxNumberOfVertexts];
对于(int i=0;i
}

但是这些点只是红色的,没有不同的颜色。 我是Rajawali和OGL的新手,所以有人能告诉我我在point类中缺少了什么样的着色器工作吗


非常感谢peter。

嗨,Dan,最新更新也会发生这种情况吗?嗨,Dan,最新更新也会发生这种情况吗?