Example usage for com.badlogic.gdx.graphics.g3d Attributes get

List of usage examples for com.badlogic.gdx.graphics.g3d Attributes get

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d Attributes get.

Prototype

public final Array<Attribute> get(final Array<Attribute> out, final long type) 

Source Link

Document

Get multiple attributes at once.

Usage

From source file:com.badlogic.gdx.tests.g3d.shadows.system.realistic.MainShader.java

License:Apache License

public void bindDirectionalShadows(final Attributes attributes) {
    final DirectionalLightsAttribute dla = attributes.get(DirectionalLightsAttribute.class,
            DirectionalLightsAttribute.Type);
    final Array<DirectionalLight> dirs = dla == null ? null : dla.lights;

    if (dirLightsLoc >= 0) {
        for (int i = 0; i < directionalLights.length; i++) {
            if (dirs == null || dirs.size <= i) {
                continue;
            }//  w w w. j av a  2s . c  o  m

            int idx = dirShadowsLoc + i * dirShadowsSize;

            // Shadow
            ObjectMap<DirectionalLight, LightProperties> dirCameras = shadowSystem.getDirectionalCameras();

            DirectionalLight dl = dirs.get(i);
            if (shadowSystem.hasLight(dl)) {
                // UVTransform
                final TextureRegion tr = dirCameras.get(dl).region;
                Camera cam = dirCameras.get(dl).camera;

                if (cam != null) {
                    program.setUniformf(idx + dirShadowsUvTransformOffset, tr.getU(), tr.getV(),
                            tr.getU2() - tr.getU(), tr.getV2() - tr.getV());

                    // ProjViewTrans
                    idx = dirShadowMapProjViewTransLoc + i * dirShadowMapProjViewTransSize;
                    program.setUniformMatrix(idx, dirCameras.get(dl).camera.combined);
                }
            }

            if (dirLightsSize <= 0)
                break;
        }
    }
}

From source file:com.badlogic.gdx.tests.g3d.shadows.system.realistic.MainShader.java

License:Apache License

public void bindSpotShadows(final Attributes attributes) {
    final SpotLightsAttribute sla = attributes.get(SpotLightsAttribute.class, SpotLightsAttribute.Type);
    final Array<SpotLight> spots = sla == null ? null : sla.lights;

    if (spotLightsLoc >= 0) {
        for (int i = 0; i < spotLights.length; i++) {
            if (spots == null || spots.size <= i) {
                continue;
            }/*from  w  w  w  .  j ava2 s .c om*/

            int idx = spotShadowsLoc + i * spotShadowsSize;

            // Shadow
            ObjectMap<SpotLight, LightProperties> spotCameras = shadowSystem.getSpotCameras();

            SpotLight sl = spots.get(i);
            if (shadowSystem.hasLight(sl)) {
                // UVTransform
                final TextureRegion tr = spotCameras.get(sl).region;
                Camera cam = spotCameras.get(sl).camera;

                if (cam != null) {
                    program.setUniformf(idx + spotShadowsUvTransformOffset, tr.getU(), tr.getV(),
                            tr.getU2() - tr.getU(), tr.getV2() - tr.getV());

                    // ProjViewTrans
                    idx = spotShadowMapProjViewTransLoc + i * spotShadowMapProjViewTransSize;
                    program.setUniformMatrix(idx, spotCameras.get(sl).camera.combined);
                }
            }

            if (spotLightsSize <= 0)
                break;
        }
    }
}