It appears that something is missing since we have light and reflection but no shadows. Shadow in LibGDX is still evolving. The way of using shadows might change in the next version. However, we will simply put a shadow here just to make the scene look more complete:
DirectionalShadowLight shadowLight; ModelBatch shadowBatch; @Override public void create() { . . . environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); shadowLight = new DirectionalShadowLight(1024, 1024, 60, 60, 1f, 300); shadowLight.set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f); environment.add(shadowLight); environment.shadowMap = shadowLight; shadowBatch = new ModelBatch(new DepthShaderProvider()); . . . } @Override public void render() { //update the world . . . shadowLight.begin(Vector3.Zero, cam.direction); shadowBatch.begin(shadowLight.getCamera()); for (UserData data : UserData.data) { shadowBatch.render(data.getInstance()); } shadowBatch.end(); shadowLight.end(); . . . // draw the modelBatch } @Override public void dispose() { . . . shadowBatch.dispose(); shadowLight.dispose(); }
The shadowLight
object is an object of DirectionalShadowLight
and shadowBatch
is ModelBatch
with a depth shader. The model instances are rendered using shadowBatch
to simulate the shadows near the actual model instances.
Here is the screenshot of the scene with shadows enabled:
To know about shadow mapping, visit the Wikipedia page at http://en.wikipedia.org/wiki/Shadow_mapping.