This is using the default shader and depth shader from LibGdx. It creates lines at the blocks intersections.
This is what I use to create the blocks models for now:
private Model createModel(Color color) {
Model model = modelBuilder.createBox(
cellSize, cellSize, cellSize,
new Material(ColorAttribute.createDiffuse(color)),
Usage.Position | Usage.Normal);
return model;
}
...
for(int x = 0; x < data.models.length; x++) {
for(int y = 0; y < data.models[x].length; y++) {
int z = data.getElevation(x, y);
ModelInstance instance = new ModelInstance(model);
instance.transform.setTranslation(new Vector3(cellSize * x + cellSize/2, cellSize * y + cellSize/2, z * cellSize - cellSize/2));
getWorld().addToCache(instance);
}
}
This sets the environment lights:
getEnvironment().set(new ColorAttribute(ColorAttribute.AmbientLight, getAmbiantBrightness(), getAmbiantBrightness(), getAmbiantBrightness() , 1f));
getEnvironment().set(new ColorAttribute(ColorAttribute.Specular, getAmbiantBrightness(), getAmbiantBrightness(), getAmbiantBrightness() , 1f));
getEnvironment().add((shadowLight = new DirectionalShadowLight(1024*4, 1024*4, 600f, 600f, 0.1f, 100f)).set(db, db, db, dx, dy, dz));
getEnvironment().shadowMap = shadowLight;
This is how I render:
@Override
public void render(float delta) {
getWorld().buildCache();
clearScreen();
renderShadows(delta);
controls.update(delta);
renderWorld(delta);
renderHud(delta);
}
public void clearScreen() {
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClearColor(getBGColor().r, getBGColor().g, getBGColor().b, getBGColor().a);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
}
protected void renderShadows(float delta) {
shadowLight.begin(Vector3.Zero, getCam().direction);
shadowBatch.begin(shadowLight.getCamera());
shadowBatch.render(world.cache, env);
getWorld().tempModels.forEach(m -> shadowBatch.render(m, env));
shadowBatch.end();
shadowLight.end();
}
protected void renderWorld(float delta) {
getBatch().begin(getCam());
// render the cached models
getBatch().render(getWorld().cache, getEnvironment());
// render the temp models
getWorld().tempModels.forEach(m -> getBatch().render(m, getEnvironment()));
getBatch().end();
}
I tried to copy the default fragment and vertex shader and edit the PCFoffset with random values, but the result wasn't better.
float getShadow()
{
float pcfOffset = 0.0f;
return (//getShadowness(vec2(0,0)) +
getShadowness(vec2(pcfOffset, pcfOffset)) +
getShadowness(vec2(-pcfOffset, pcfOffset)) +
getShadowness(vec2(pcfOffset, -pcfOffset)) +
getShadowness(vec2(-pcfOffset, -pcfOffset))) * 0.25;
}
Should I code the lights/shadows myself using Lwjgl instead of using LibGdx defaults? Seems like a lot of work for something I expected to be included.