Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android libgdx点光源在生成的网格上不工作_Android_Opengl Es_3d_Libgdx - Fatal编程技术网

Android libgdx点光源在生成的网格上不工作

Android libgdx点光源在生成的网格上不工作,android,opengl-es,3d,libgdx,Android,Opengl Es,3d,Libgdx,我一直在尝试照亮由以下内容生成的平面网格: private Model createPlane(float w, float h, Texture texture) { Mesh mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"),

我一直在尝试照亮由以下内容生成的平面网格:

private Model createPlane(float w, float h, Texture texture) {
   Mesh mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"),
           new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"),
           new VertexAttribute(Usage.Normal, 3, "a_normal")); 

   float w2 = w * this.CELL_SIZE;
   float h2 = h * this.CELL_SIZE;

    mesh.setVertices(new float[]
            { w2, 0f, h2, 0, 0, 0, 1, 0,
            w2, 0f, -h2, 0, h, 0, 1, 0,
            -w2, 0f, h2, w, 0, 0, 1, 0,
            -w2, 0f, -h2 , w,h, 0, 1, 0
            });
    mesh.setIndices(new short[] { 0, 1, 2, 1, 3, 2});
    Model model = ModelBuilder.createFromMesh(mesh, GL10.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(texture)));
    return model;
}
并使用以下方式渲染:

//the environment setup
env = new Environment();
        env.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
        env.add(new PointLight().set(Color.ORANGE, 5f, 1f, 5f, 10f));
        env.add(new DirectionalLight().set(Color.WHITE, -1f, -0.8f, -0.2f));
...
//the render method
batch.begin();
batch.render(inst, env);//inst is a ModelInstance created using the Model generated from createPlane(...)
batch.end();
网格显示正确(UV、纹理),并且似乎受到定向照明和环境照明的适当影响

当我尝试添加点光源(请参见上面的环境)时,从createPlane(…)生成的任何平面都不会受到影响。我尝试过使用ModelBuilder类的createBox(…)创建另一个几何体,它似乎能够正确响应点光源。正因为如此,我假设我没有正确地生成平面,但它显然受到方向光/环境光的影响这一事实让我有点不舒服

值得注意的是,生成的平面大小会有所不同,我不太确定点光源是否会对4个顶点产生很大影响,但我期望的不仅仅是没有。移动点光源(靠近某些顶点)也不会产生任何效果

任何帮助都将不胜感激


谢谢

如果知道您使用的是哪个着色器,那就太好了。默认值是多少?我不确定他们是否已经修复了这个问题,他们之前有一个bug,pointlightning只在一些设备上工作(这与制造商的opengles实现有关。我个人使用自己的着色器修复了这个问题)

编辑:

我检查了我正在使用的代码。问题是确定着色器中正确的灯光阵列。 到底是这样的:

//在某些设备上,这是可行的
int u_lightPosition=program.getUniformLocation(“u_lightPosition[0]”);
int u_lightColors=program.getUniformLocation(“u_lightColor[0]”);
if(u_lightPosition<0&&u_lightColors<0){
//对其他人来说,这是有效的
u_lightPosition=程序.getUniformLocation(“u_lightPosition”);
u_lightColors=program.getUniformLocation(“u_lightColor”);
}

我希望这会有所帮助!

我会尝试将灯光直接放在网格的一个角上,并将其强度大幅放大,以查看其中一个是否是您的问题。四顶点网格不会很好地响应到达距离不超过顶点之间距离两倍的点光源,除非使用具有per的着色器-像素照明。
    // on some devices this was working
    int u_lightPosition = program.getUniformLocation("u_lightPosition[0]");
    int u_lightColors = program.getUniformLocation("u_lightColor[0]");
    if(u_lightPosition < 0 && u_lightColors < 0) {
        // on others this was working
        u_lightPosition = program.getUniformLocation("u_lightPosition");
        u_lightColors = program.getUniformLocation("u_lightColor");
    }