I am using Ardor3D for a game. I made a simple array terrain data provider (creates terrain out of a float array). Then, I used an awtexturesource (provides texture for the terrain) and added a white rectangle that fills the whole terrain. At certain angles, though, it looks like :
What are the random black areas??? What am I doing wrong?
Code: (ExampleBase is a simple base for games that calls initExample() then repeatedly calls updateExample() in a loop)
[spoiler]
public class Level extends ExampleBase {
Node _level=new Node("Level Root");
private final float farPlane = 8000.0f;
private Terrain terrain;
final int SIZE = 2048;
PointLight pl=new PointLight();
private double counter = 0;
private int frames = 0;
public void updateExample(ReadOnlyTimer t){
counter += t.getTimePerFrame();
frames++;
if (counter > 1) {
final double fps = frames / counter;
counter = 0;
frames = 0;
System.out.printf("%7.1f FPS\n", fps);
}
pl.setLocation(_canvas.getCanvasRenderer().getCamera().getLocation());
}
@Override
protected void initExample() {
_canvas.setTitle("Terrain Example");
_canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 10, 0));
_canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(1, -300, 1), Vector3.UNIT_Y);
_canvas.getCanvasRenderer().getCamera().setFrustumPerspective(
70.0,
(float) _canvas.getCanvasRenderer().getCamera().getWidth()
/ _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane);
_canvas.getCanvasRenderer().getRenderer().setBackgroundColor(ColorRGBA.CYAN);
_controlHandle.setMoveSpeed(300);
setupDefaultStates();
AwtTextureSource awt = new AwtTextureSource(8, TextureStoreFormat.RGBA8);
try {
final int SIZE = 2048;
float[] heightMap=new float[SIZE*SIZE];
for(int i=0;i<heightMap.length;i++)heightMap[i]=0f;
final TerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(1, 300, 1));
TerrainBuilder b=new TerrainBuilder(terrainDataProvider, _canvas.getCanvasRenderer().getCamera());
b.addTextureConnection(awt);
terrain = b.setShowDebugPanels(true).build();
terrain.getTextureClipmap().setShowDebug(false);
terrain.reloadShader();
_level.attachChild(terrain);
} catch (final Exception ex1) {
System.out.println("Problem setting up terrain...");
ex1.printStackTrace();
}
AwtShapeElement rectangle = new AwtShapeElement(new Rectangle(2048, 2048));
Transform t = new Transform();
rectangle.setTransform(t);
awt.getProvider().addElement(rectangle);
_root.attachChild(_level);
}
//copied from ArrayTerrainExample
private void setupDefaultStates() {
_lightState.detachAll();
final DirectionalLight dLight = new DirectionalLight();
dLight.setEnabled(true);
dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1));
dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1));
dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1));
dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal());
pl.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1));
pl.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1));
pl.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1));
pl.setAttenuate(false);
_lightState.attach(pl);
_lightState.attach(dLight);
_lightState.setEnabled(true);
final CullState cs = new CullState();
cs.setEnabled(true);
cs.setCullFace(CullState.Face.Back);
_root.setRenderState(cs);
final FogState fs = new FogState();
fs.setStart(farPlane / 2.0f);
fs.setEnd(farPlane);
fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
fs.setDensityFunction(DensityFunction.Linear);
_root.setRenderState(fs);
}
/**
* @param args
*/
public static void main(String[] args) {
start(Level.class);
}
}
[/spoiler]