【发布时间】:2014-01-19 13:26:20
【问题描述】:
我一直在尝试照亮以下生成的平面网格:
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 个顶点产生很大影响,但我期望多于没有。移动点光源(靠近某些顶点)也没有任何作用。
任何帮助将不胜感激。
谢谢!
【问题讨论】:
-
我会尝试将您的灯直接放在网格的一个角上,然后将其强度放大很多,看看其中一个是否是您的问题。除非您使用具有逐像素照明的着色器,否则四顶点网格不会很好地响应范围不大于顶点之间距离的两倍的点光源。
标签: android opengl-es 3d libgdx