Search in sources :

Example 16 with DirectionalLight

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

the class DefaultShader method begin.

@Override
public void begin(final Camera camera, final RenderContext context) {
    super.begin(camera, context);
    for (final DirectionalLight dirLight : directionalLights) dirLight.set(0, 0, 0, 0, -1, 0);
    for (final PointLight pointLight : pointLights) pointLight.set(0, 0, 0, 0, 0, 0, 0);
    for (final SpotLight spotLight : spotLights) spotLight.set(0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0);
    lightsSet = false;
    if (has(u_time))
        set(u_time, time += Gdx.graphics.getDeltaTime());
}
Also used : DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight) SpotLight(com.badlogic.gdx.graphics.g3d.environment.SpotLight)

Example 17 with DirectionalLight

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

the class KTXTest method create.

@Override
public void create() {
    // Cubemap test
    String cubemapVS = //
    "" + //
    "attribute vec3 a_position;\n" + //
    "uniform mat4 u_projViewTrans;\n" + //
    "uniform mat4 u_worldTrans;\n" + //
    "\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec4 g_position = vec4(a_position, 1.0);\n" + //
    "   g_position = u_worldTrans * g_position;\n" + //
    "   v_cubeMapUV = normalize(g_position.xyz);\n" + //
    "   gl_Position = u_projViewTrans * g_position;\n" + "}";
    String cubemapFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform samplerCube u_environmentCubemap;\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "void main() {\n" + //
    "	gl_FragColor = vec4(textureCube(u_environmentCubemap, v_cubeMapUV).rgb, 1.0);\n" + "}\n";
    modelBatch = new ModelBatch(new DefaultShaderProvider(new Config(cubemapVS, cubemapFS)));
    cubemap = new Cubemap(new KTXTextureData(Gdx.files.internal("data/cubemap.zktx"), true));
    cubemap.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
    environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
    perspectiveCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    perspectiveCamera.position.set(10f, 10f, 10f);
    perspectiveCamera.lookAt(0, 0, 0);
    perspectiveCamera.near = 0.1f;
    perspectiveCamera.far = 300f;
    perspectiveCamera.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    instance = new ModelInstance(model);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(perspectiveCamera)));
    // 2D texture test
    String etc1aVS = //
    "" + //
    "uniform mat4 u_projTrans;\n" + //
    "\n" + //
    "attribute vec4 a_position;\n" + //
    "attribute vec2 a_texCoord0;\n" + //
    "attribute vec4 a_color;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   gl_Position = u_projTrans * a_position;\n" + //
    "   v_texCoord = a_texCoord0;\n" + //
    "   v_color = a_color;\n" + //
    "}\n";
    String etc1aFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform sampler2D u_texture;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec3 col = texture2D(u_texture, v_texCoord.st).rgb;\n" + //
    "   float alpha = texture2D(u_texture, v_texCoord.st + vec2(0.0, 0.5)).r;\n" + //
    "   gl_FragColor = vec4(col, alpha) * v_color;\n" + //
    "}\n";
    etc1aShader = new ShaderProgram(etc1aVS, etc1aFS);
    orthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    image = new Texture("data/egg.zktx");
    batch = new SpriteBatch(100, etc1aShader);
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Config(com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.Config) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) KTXTextureData(com.badlogic.gdx.graphics.glutils.KTXTextureData) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Cubemap(com.badlogic.gdx.graphics.Cubemap) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 18 with DirectionalLight

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

the class VoxelTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    font = new BitmapFont();
    modelBatch = new ModelBatch();
    DefaultShader.defaultCullFace = GL20.GL_FRONT;
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.near = 0.5f;
    camera.far = 1000;
    controller = new FirstPersonCameraController(camera);
    Gdx.input.setInputProcessor(controller);
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    lights.add(new DirectionalLight().set(1, 1, 1, 0, -1, 0));
    Texture texture = new Texture(Gdx.files.internal("data/g3d/tiles.png"));
    TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32);
    MathUtils.random.setSeed(0);
    voxelWorld = new VoxelWorld(tiles[0], 20, 4, 20);
    PerlinNoiseGenerator.generateVoxels(voxelWorld, 0, 63, 10);
    float camX = voxelWorld.voxelsX / 2f;
    float camZ = voxelWorld.voxelsZ / 2f;
    float camY = voxelWorld.getHighest(camX, camZ) + 1.5f;
    camera.position.set(camX, camY, camZ);
}
Also used : DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FirstPersonCameraController(com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 19 with DirectionalLight

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

the class ShaderCollectionTest method create.

@Override
public void create() {
    super.create();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
    environment.add(dirLight = new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
    shaderProvider = new TestShaderProvider();
    shaderBatch = new ModelBatch(shaderProvider);
    cam.position.set(1, 1, 1);
    cam.lookAt(0, 0, 0);
    cam.update();
    showAxes = true;
    onModelClicked("g3d/shapes/teapot.g3dj");
    shaderRoot = (hotLoadFolder != null && Gdx.app.getType() == ApplicationType.Desktop) ? Gdx.files.absolute(hotLoadFolder) : Gdx.files.internal("data/g3d/shaders");
}
Also used : DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 20 with DirectionalLight

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

the class FogTest method create.

@Override
public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(30f, 10f, 30f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 45f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    instance = new ModelInstance(model);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) 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)

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