Book Image

Learning LibGDX Game Development- Second Edition

Book Image

Learning LibGDX Game Development- Second Edition

Overview of this book

Table of Contents (21 chapters)
Learning LibGDX Game Development Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Having fun with shadows


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...