com.badlogic.gdx.graphics.g3d.Environment Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.Environment. 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: 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 #2
Source File: Renderer.java    From VuforiaLibGDX with MIT License 6 votes vote down vote up
public Renderer() {

        lights = new Environment();
        lights.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));

        camera = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        camera.near = 1.0F;
        camera.far = 1000.0F;
        //set camera into "Vuforia - style" direction
        camera.position.set(new Vector3(0,0,0));
        camera.lookAt(new Vector3(0,0,1));

        IntBuffer buffer = BufferUtils.newIntBuffer(16);
        Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, buffer);
        int units = buffer.get(0);
        Log.d("TAG", "Max texture units: "+units);
        modelBatch = new ModelBatch(new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 0)));
    }
 
Example #3
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 #4
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 #5
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 #6
Source File: EnvironmentCache.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
/**
 * fast way to copy only references
 * @param env
 */
public void setCache(Environment env){
	this.mask = env.getMask();
	this.attributes.clear();
	for(Attribute a : env) this.attributes.add(a);
	this.shadowMap  = env.shadowMap;
	this.sorted = true;
}
 
Example #7
Source File: BulletWorld.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void render (ModelBatch batch, Environment lights, Iterable<BulletEntity> entities) {
	if (renderMeshes) super.render(batch, lights, entities);
	if (debugDrawer != null && debugDrawer.getDebugMode() > 0) {
		batch.flush();
		debugDrawer.begin(batch.getCamera());
		collisionWorld.debugDrawWorld();
		debugDrawer.end();
	}
}
 
Example #8
Source File: TerrainChunk.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public void render(ModelBatch batch, Environment env) {
	batch.render(modelInstance, env);
	
	for (ModelInstance m : sceneObjects) {
		batch.render(m, env);
	}
}
 
Example #9
Source File: Stage3d.java    From Scene3d with Apache License 2.0 5 votes vote down vote up
public Stage3d (float width, float height, PerspectiveCamera camera, Environment environment) {
	this.width = width;
	this.height = height;
	root = new Group3d();
	root.setStage3d(this);
	modelBatch = new ModelBatch();
	this.camera = camera;
	this.environment = environment;
}
 
Example #10
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 #11
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 #12
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 #13
Source File: SceneSkybox.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public SceneSkybox(Cubemap cubemap){
	super();
	
	// create shader provider
	Config shaderConfig = new Config();
	String basePathName = "net/mgsx/gltf/shaders/skybox";
	shaderConfig.vertexShader = Gdx.files.classpath(basePathName + ".vs.glsl").readString();
	shaderConfig.fragmentShader = Gdx.files.classpath(basePathName + ".fs.glsl").readString();
	shaderProvider =  new DefaultShaderProvider(shaderConfig);
	
	// create box
	float boxScale = (float)(1.0 / Math.sqrt(2.0));
	boxModel = new ModelBuilder().createBox(boxScale, boxScale, boxScale, new Material(), VertexAttributes.Usage.Position);
	box = boxModel.nodes.first().parts.first().setRenderable(new Renderable());
	
	// assign environment
	Environment env = new Environment();
	env.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
	env.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));
	box.environment = env;
	
	// set hint to render last but before transparent ones
	box.userData = SceneRenderableSorter.Hints.OPAQUE_LAST;
	
	// set material options : preserve background depth
	box.material = new Material(ColorAttribute.createDiffuse(Color.WHITE));
	box.material.set(new DepthTestAttribute(false));
	
	
	// assign shader
	box.shader = shaderProvider.getShader(box);
}
 
Example #14
Source File: EnvironmentUtil.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public static int getLightCount(Environment environment){
	int count = 0;
	DirectionalLightsAttribute dla = environment.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type);
	if(dla != null) count += dla.lights.size;
	PointLightsAttribute pla = environment.get(PointLightsAttribute.class, PointLightsAttribute.Type);
	if(pla != null) count += pla.lights.size;
	SpotLightsAttribute sla = environment.get(SpotLightsAttribute.class, SpotLightsAttribute.Type);
	if(sla != null) count += sla.lights.size;
	return count;
}
 
Example #15
Source File: LightUtils.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public static LightsInfo getLightsInfo(LightsInfo info, Environment environment){
	info.reset();
	DirectionalLightsAttribute dla = environment.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type);
	if(dla != null) info.dirLights = dla.lights.size;
	PointLightsAttribute pla = environment.get(PointLightsAttribute.class, PointLightsAttribute.Type);
	if(pla != null) info.pointLights = pla.lights.size;
	SpotLightsAttribute sla = environment.get(SpotLightsAttribute.class, SpotLightsAttribute.Type);
	if(sla != null) info.spotLights = sla.lights.size;
	return info;
}
 
Example #16
Source File: Group3d.java    From Scene3d with Apache License 2.0 4 votes vote down vote up
/** Draws the group and its children. The default implementation calls {@link #applyTransform(Batch, Matrix4)} if needed, then
 * {@link #drawChildren(Batch, float)}, then {@link #resetTransform(Batch)} if needed. */
@Override
public void draw(ModelBatch modelBatch, Environment environment) {
	super.draw(modelBatch, environment);
	drawChildren(modelBatch, environment);
}
 
Example #17
Source File: Group3d.java    From Scene3d with Apache License 2.0 4 votes vote down vote up
public void drawChildren(ModelBatch modelBatch, Environment environment){
     //modelBatch.render(children, environment); maybe faster 
     SnapshotArray<Actor3d> children = this.children;
	 Actor3d[] actors = children.begin();
	 visibleCount = 0;
	 for (int i = 0, n = children.size; i < n; i++){
		 if(actors[i] instanceof Group3d){
    		 ((Group3d) actors[i]).drawChildren(modelBatch, environment);
    	 }
		 else{
				float offsetX = x, offsetY = y, offsetZ = z;
				float offsetScaleX = scaleX, offsetScaleY = scaleY, offsetScaleZ = scaleZ;
				float offsetYaw = yaw, offsetPitch = pitch, offsetRoll = roll;
				x = 0;
				y = 0;
				z = 0;
				scaleX = 0;
				scaleY = 0;
				scaleZ = 0;
				yaw = 0;
				pitch = 0;
				roll = 0;
				Actor3d child = actors[i];
				if (!child.isVisible()) continue;
				/*Matrix4 diff = sub(child.getTransform(), getTransform());
				Matrix4 childMatrix = child.getTransform().cpy();
				child.getTransform().set(add(diff, childMatrix));
				child.draw(modelBatch, environment);*/
				float cx = child.x, cy = child.y, cz = child.z;
				float sx = child.scaleX, sy = child.scaleY, sz = child.scaleZ;
				float ry = child.yaw, rp = child.pitch, rr = child.roll;
				//child.x = cx + offsetX;
				//child.y = cy + offsetY;
				//child.z = cz + offsetZ;
				child.setPosition(cx + offsetX, cy + offsetY, cz + offsetZ);
				child.setScale(sx + offsetScaleX, sy + offsetScaleY, sz + offsetScaleZ);
				child.setRotation(ry + offsetYaw, rp + offsetPitch, rr +offsetRoll);
		        if (child.isCullable(getStage3d().getCamera())) {
		        	child.draw(modelBatch, environment);
		            visibleCount++;
		        }
				child.x = cx;
				child.y = cy;
				child.z = cz;
				x = offsetX;
				y = offsetY;
				z = offsetZ;
				child.scaleX = sx;
				child.scaleY = sy;
				child.scaleZ = sz;
				scaleX = offsetScaleX;
				scaleY = offsetScaleY;
				scaleZ = offsetScaleZ;
				child.yaw = ry;
				child.pitch = rp;
				child.roll = rr;
				yaw = offsetYaw;
				pitch = offsetPitch;
				roll = offsetRoll;
		 }
	 }
	 children.end();
}
 
Example #18
Source File: Actor3d.java    From Scene3d with Apache License 2.0 4 votes vote down vote up
public void draw(ModelBatch modelBatch, Environment environment){
	modelBatch.render(this, environment);
}
 
Example #19
Source File: Stage3d.java    From Scene3d with Apache License 2.0 4 votes vote down vote up
public void setEnvironment(Environment environment){
	this.environment = environment;
}
 
Example #20
Source File: Stage3d.java    From Scene3d with Apache License 2.0 4 votes vote down vote up
public Environment getEnvironment(){
	return environment;
}
 
Example #21
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)
	);
}
 
Example #22
Source File: BaseWorld.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public void render (final ModelBatch batch, final Environment lights) {
	render(batch, lights, entities);
}
 
Example #23
Source File: BaseWorld.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public void render (final ModelBatch batch, final Environment lights, final Iterable<T> entities) {
	for (final T e : entities) {
		batch.render(e.modelInstance, lights);
	}
}
 
Example #24
Source File: BaseWorld.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public void render (final ModelBatch batch, final Environment lights, final T entity) {
	batch.render(entity.modelInstance, lights);
}