Java Code Examples for com.badlogic.gdx.graphics.g3d.Environment#add()

The following examples show how to use com.badlogic.gdx.graphics.g3d.Environment#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameRenderer.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
public void setEnvironmentLights(Array<BaseLight<?>> lights, Vector3 sunDirection) {
	environment = new Environment();
	environment.add((shadowLight = new DirectionalShadowLight(
			GameSettings.SHADOW_MAP_WIDTH,
			GameSettings.SHADOW_MAP_HEIGHT,
			GameSettings.SHADOW_VIEWPORT_WIDTH,
			GameSettings.SHADOW_VIEWPORT_HEIGHT,
			GameSettings.SHADOW_NEAR,
			GameSettings.SHADOW_FAR))
			.set(GameSettings.SHADOW_INTENSITY,
					GameSettings.SHADOW_INTENSITY,
					GameSettings.SHADOW_INTENSITY,
					sunDirection.nor()));
	environment.shadowMap = shadowLight;

	float ambientLight = GameSettings.SCENE_AMBIENT_LIGHT;
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, ambientLight, ambientLight, ambientLight, 1));
	for (BaseLight<?> light : lights) {
		environment.add(light);
	}
}
 
Example 2
Source File: SimpleRoom.java    From gdx-vr with Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
	assets = new AssetManager();
	String model = "Bambo_House.g3db";
	assets.load(model, Model.class);
	assets.finishLoading();
	modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f));

	DefaultShader.Config config = new Config();
	config.defaultCullFace = GL20.GL_NONE;
	ShaderProvider shaderProvider = new DefaultShaderProvider(config);
	modelBatch = new ModelBatch(shaderProvider);

	ModelBuilder builder = new ModelBuilder();
	float groundSize = 1000f;
	ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0,
			1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0));
	environment = new Environment();
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
	environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

	VirtualReality.renderer.listeners.add(this);
	// VirtualReality.head.setCyclops(true);
}
 
Example 3
Source File: Stage3d.java    From Scene3d with Apache License 2.0 6 votes vote down vote up
public Stage3d (float width, float height, boolean keepAspectRatio) {
	this.width = width;
	this.height = height;

	root = new Group3d();
	root.setStage3d(this);

	modelBatch = new ModelBatch();

	camera =  new Camera3d();
	environment = new Environment();
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.9f, 0.9f, 0.9f, 1f));
	environment.add(new DirectionalLight().set(0.8f, 0f, 0f, -1f, -0.8f, -0.2f));

	setViewport(width, height, keepAspectRatio);
}
 
Example 4
Source File: Renderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public Renderer () {
	try {
		lights = new Environment();
		lights.add(new DirectionalLight().set(Color.WHITE, new Vector3(-1, -0.5f, 0).nor()));

		spriteBatch = new SpriteBatch();
		modelBatch = new ModelBatch();

		backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true);
		backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

		font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"), false);

		camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example 5
Source File: WorldGenerator.java    From Skyland with MIT License 5 votes vote down vote up
public static Environment generateBaseEnvironment(Vector3 sun) {
    Environment environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    environment.set(new ColorAttribute(ColorAttribute.Fog, .3f, .55f, 1, 1));
    environment.add(new DirectionalLight().set(.3f, .3f, .3f, -.2f, 0.6f, .8f));
    environment.add(new DirectionalLight().set(1f, 1f, 1f, .2f, -0.6f, -.8f));
    environment.add(new PointLight().set(1, 1, 1, sun, 200));
    return environment;
}
 
Example 6
Source File: Sprite3DRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private void createEnvirontment() {
	environment = new Environment();

	// environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f,
	// 0.8f, 0.8f, 1f));

	// environment.add(new DirectionalLight().set(1f, 1f, 1f, 1f, -1f,
	// -1f));

	if (celLight == null) {
		Node n = null;

		if (currentSource != null)
			n = ((ModelCacheEntry) currentSource).modelInstance.getNode(celLightName);

		if (n != null) {
			celLight = new PointLight().set(1f, 1f, 1f, n.translation, 1f);
		} else {
			celLight = new PointLight().set(1f, 1f, 1f, 0.5f, 1f, 1f, 1f);
		}
	}

	environment.add(celLight);

	if (renderShadow) {
		shadowEnvironment = new Environment();
		shadowEnvironment.add(shadowLight);
		shadowEnvironment.shadowMap = shadowLight;
	}
}
 
Example 7
Source File: FluidSimulatorGeneric.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
public FluidSimulatorGeneric(FluidSimulatorStarter fluidSimulatorStarter) {
		this.game = fluidSimulatorStarter;
		// LibGDX single batches cannot have a size more than 5460
		batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE);
		font = new BitmapFont();
		camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT);
		camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0);
		immediateRenderer = new ImmediateModeRenderer20(SIZE*6, false, true, 0);
		irt = new Renderer20(SIZE*6, false, true, 1);
		irt2 = new ImmediateModeRenderer20(SIZE*11, false, true, 1);
		shapeRenderer = new ShapeRenderer(SIZE);
		renderer = new Box2DDebugRenderer(true, true, false, true, false, false);
		
		//3D
		camera3D = new PerspectiveCamera(67, WORLD_WIDTH, WORLD_HEIGHT);
		camera3D.position.set(0, 130f, 250f);
		camera3D.lookAt(0,150f,0);
		camera3D.near = 0.1f;
		camera3D.far = 500f;
		camera3D.update();
		ModelBuilder modelBuilder = new ModelBuilder();
//        model = modelBuilder.createSphere(5f, 5f, 5f, 4, 4, GL10.GL_TRIANGLES,
//                new Material(ColorAttribute.createDiffuse(Color.GREEN)),
//                Usage.Position | Usage.Normal);
        model = modelBuilder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
        instance = new ModelInstance(model);
        modelBatch = new ModelBatch();
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0, -0.8f, -0.2f));
        camController = new Camera3DController(camera3D);
        camController.setFluidSimulator(this);
		
		world = new World(new Vector2(0, -9.8f), false);
		world.setContactListener(this);
	}
 
Example 8
Source File: View.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public View() {
	ModelManager modelManager = new ModelManager();
	modelManager.init();
	storeSize();
	inst = this;
	gl = Gdx.graphics.getGL20();
	float fov = 67f;
	camera = new PerspectiveCamera(fov, width(), height());
	// camera.far affects frustrum culling, so a shorter distance can boost performance
	camera.far = 60f;
	camera.near = 0.01f;
	resetCamera();

	initShaders();
	modelBatch = new ModelBatch(shaderProvider);

	environ = new Environment();
	basicEnviron = new Environment();
	camLight = new PointLight();
	float intensity = 100f;
	camLight.set(new Color(0.2f, 0.2f, 0.2f, 1f), 0f, 0f, 0f, intensity);
	ColorAttribute ambientLight = ColorAttribute.createAmbient(new Color(0.1f, 0.1f, 0.1f, 1f));
	environ.set(ambientLight);
	ColorAttribute fog = new ColorAttribute(ColorAttribute.Fog);
	fog.color.set(fogColor);
	environ.set(fog);
	environ.add(camLight);
	dirLight = new DirectionalLight();
	dirLight.set(new Color(0.3f, 0.3f, 0.35f, 1f), -0.25f, -0.75f, 0.25f);
	environ.add(dirLight);

	basicEnviron.set(ColorAttribute.createAmbient(0.3f, 0.3f, 0.3f, 1f));

	if (Toggleable.profileGL()) {
		Profiler.enable();
	}

	hud = new HUD();
	
	Sky.createSkyBox(
		Assets.manager.get("textures/skybox/xpos.png", Texture.class),
		Assets.manager.get("textures/skybox/xneg.png", Texture.class),
		Assets.manager.get("textures/skybox/ypos.png", Texture.class),
		Assets.manager.get("textures/skybox/yneg.png", Texture.class),
		Assets.manager.get("textures/skybox/zpos.png", Texture.class),
		Assets.manager.get("textures/skybox/zneg.png", Texture.class)
	);
}