libgdx point light not working on generated mesh

sav*_*sun 10 3d android opengl-es libgdx

I've been trying to illuminate plane meshes generated by the following:

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;
}
Run Code Online (Sandbox Code Playgroud)

and are rendered using:

//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();
Run Code Online (Sandbox Code Playgroud)

The meshes display correctly (UVs, textured) and seem to be properly affected by directional and ambient lighting.

When I try to add a point light (see above environment) none of the planes generated from createPlane(...) are affected. I've tried creating another bit of geometry using the ModelBuilder class's createBox(...) and it seems to properly respond to the point light. Because of that I'm assuming that I'm not generating the plane correctly, but the fact that it's apparently being affected by directional/ambient light is throwing me off a bit.

It's worth noting that the size of the planes generated vary, I'm not particularly sure if a point light would affect 4 vertices very much but I expected more than nothing. Moving the point light around (closer to certain vertices) doesn't do anything either.

Any help would be greatly appreciated.

Thanks!

and*_*dre 0

很高兴知道您正在使用哪种着色器。默认的那个?我不确定他们是否已经修复了这个问题,他们不久前遇到了一个错误,点光源只能在某些设备上工作(这与制造商实施 opengles 有关。我个人使用我自己的着色器修复了这个问题。

编辑:这似乎是固定的

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

    // 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");
    }
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助!