Search in sources :

Example 21 with DirectionalLight

use of com.badlogic.gdx.graphics.g3d.environment.DirectionalLight in project libgdx by libgdx.

the class ViewportTest3 method create.

public void create() {
    modelBatch = new ModelBatch();
    modelBuilder = new ModelBuilder();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    shadowLight = new DirectionalLight();
    shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(shadowLight);
    modelBatch = new ModelBatch();
    camera = new PerspectiveCamera();
    camera.fieldOfView = 67;
    camera.near = 0.1f;
    camera.far = 300f;
    camera.position.set(0, 0, 100);
    camera.lookAt(0, 0, 0);
    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();
    names = ViewportTest1.getViewportNames();
    name = names.first();
    ModelBuilder modelBuilder = new ModelBuilder();
    Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    boxInstance = new ModelInstance(boxModel);
    boxInstance.transform.rotate(1, 0, 0, 30);
    boxInstance.transform.rotate(0, 1, 0, 30);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) InputAdapter(com.badlogic.gdx.InputAdapter) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 22 with DirectionalLight

use of com.badlogic.gdx.graphics.g3d.environment.DirectionalLight in project nhglib by VoidZombie.

the class ShaderUtils method createPrefix.

public static String createPrefix(Renderable renderable, boolean skinned) {
    String prefix = "";
    final int n = renderable.meshPart.mesh.getVertexAttributes().size();
    for (int i = 0; i < n; i++) {
        final VertexAttribute attr = renderable.meshPart.mesh.getVertexAttributes().get(i);
        if (attr.usage == VertexAttributes.Usage.BoneWeight) {
            prefix += "#define boneWeight" + attr.unit + "Flag\n";
        }
    }
    if (skinned) {
        prefix += "#define skinningFlag\n";
    }
    Environment environment = renderable.environment;
    // Ambient lighting
    ColorAttribute ambientLightAttribute = (ColorAttribute) environment.get(ColorAttribute.AmbientLight);
    if (ambientLightAttribute != null) {
        prefix += "#define ambientLighting\n";
    }
    // Directional lighting
    DirectionalLightsAttribute directionalLightsAttribute = (DirectionalLightsAttribute) environment.get(DirectionalLightsAttribute.Type);
    if (directionalLightsAttribute != null) {
        Array<DirectionalLight> directionalLights = directionalLightsAttribute.lights;
        if (directionalLights.size > 0) {
            prefix += "#define numDirectionalLights " + directionalLights.size + "\n";
        }
    }
    // Point lighting
    PointLightsAttribute pointLightsAttribute = (PointLightsAttribute) environment.get(PointLightsAttribute.Type);
    if (pointLightsAttribute != null) {
        Array<PointLight> pointLights = pointLightsAttribute.lights;
        if (pointLights.size > 0) {
            prefix += "#define numPointLights " + pointLights.size + "\n";
        }
    }
    // Spot lighting
    SpotLightsAttribute spotLightsAttribute = (SpotLightsAttribute) environment.get(SpotLightsAttribute.Type);
    if (spotLightsAttribute != null) {
        Array<SpotLight> spotLights = spotLightsAttribute.lights;
        if (spotLights.size > 0) {
            prefix += "#define numSpotLights " + spotLights.size + "\n";
        }
    }
    return prefix;
}
Also used : SpotLight(com.badlogic.gdx.graphics.g3d.environment.SpotLight) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) Environment(com.badlogic.gdx.graphics.g3d.Environment) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight)

Aggregations

DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)22 Environment (com.badlogic.gdx.graphics.g3d.Environment)17 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)16 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)11 Material (com.badlogic.gdx.graphics.g3d.Material)10 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)9 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 PointLight (com.badlogic.gdx.graphics.g3d.environment.PointLight)7 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)7 SpotLight (com.badlogic.gdx.graphics.g3d.environment.SpotLight)5 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4 Texture (com.badlogic.gdx.graphics.Texture)4 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)4 Model (com.badlogic.gdx.graphics.g3d.Model)3 DirectionalLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)2 PointLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute)2 SpotLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.SpotLightsAttribute)2