com.badlogic.gdx.graphics.g3d.environment.PointLight Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.environment.PointLight. 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: LightUtils.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public static LightsInfo getLightsInfo(LightsInfo info, Iterable<BaseLight> lights){
	info.reset();
	for(BaseLight light : lights){
		if(light instanceof DirectionalLight){
			info.dirLights++;
		}else if(light instanceof PointLight){
			info.pointLights++;
		}else if(light instanceof SpotLight){
			info.spotLights++;
		}else{
			info.miscLights++;
		}
	}
	return info;
}
 
Example #2
Source File: Scene.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
protected BaseLight createLight(BaseLight from) {
	if(from instanceof DirectionalLight){
		return new DirectionalLightEx().set((DirectionalLight)from);
	}
	if(from instanceof PointLight){
		return new PointLightEx().set((PointLight)from);
	}
	if(from instanceof SpotLight){
		return new SpotLightEx().set((SpotLight)from);
	}
	throw new GdxRuntimeException("unknown light type " + from.getClass().getName());
}
 
Example #3
Source File: Scene.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private void syncLights(){
	for(Entry<Node, BaseLight> e : lights){
		Node node = e.key;
		BaseLight light = e.value;
		transform.set(node.globalTransform).mul(modelInstance.transform);
		if(light instanceof DirectionalLight){
			((DirectionalLight)light).direction.set(0,0,-1).rot(transform);
		}else if(light instanceof PointLight){
			((PointLight)light).position.setZero().mul(transform);
		}else if(light instanceof SpotLight){
			((SpotLight)light).position.setZero().mul(transform);
			((SpotLight)light).direction.set(0,0,-1).rot(transform);
		}
	}
}
 
Example #4
Source File: PointLightEx.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public PointLight set (final PointLight copyFrom) {
	if(copyFrom instanceof PointLightEx){
		return set(copyFrom.color, copyFrom.position, copyFrom.intensity, ((PointLightEx)copyFrom).range);
	}else{
		return set(copyFrom.color, copyFrom.position, copyFrom.intensity);
	}
}
 
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: GLTFLightExporter.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
public static GLTFLight map(GLTFLight glLight, BaseLight light) {
	float intensityScale;
	if(light instanceof DirectionalLight){
		glLight.type = GLTFLight.TYPE_DIRECTIONAL;
		if(light instanceof DirectionalLightEx){
			glLight.intensity = ((DirectionalLightEx) light).intensity;
		}else{
			glLight.intensity = 1;
		}
		intensityScale = 1;
	}
	else if(light instanceof PointLight){
		glLight.type = GLTFLight.TYPE_POINT;
		if(light instanceof PointLightEx){
			glLight.intensity = ((PointLightEx) light).intensity;
			glLight.range = ((PointLightEx) light).range;
		}else{
			glLight.intensity = 1;
		}
		intensityScale = 10;
	}
	else if(light instanceof SpotLight){
		glLight.type = GLTFLight.TYPE_SPOT;
		glLight.spot = new GLTFSpotLight();
		if(light instanceof SpotLightEx){
			glLight.intensity = ((SpotLightEx) light).intensity;
			glLight.range = ((SpotLightEx) light).range;
		}else{
			glLight.intensity = 1;
		}
		intensityScale = 10;
		// https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md#inner-and-outer-cone-angles
		// inverse formula
		float cosDeltaAngle = 1f / ((SpotLight)light).exponent;
		float cosOuterAngle = -((SpotLight)light).cutoffAngle / ((SpotLight)light).exponent;
		glLight.spot.outerConeAngle = (float)Math.acos(cosOuterAngle);
		glLight.spot.innerConeAngle = (float)Math.acos(cosOuterAngle + cosDeltaAngle);
	}
	else{
		throw new GdxRuntimeException("unsupported light type " + light.getClass());
	}
	
	// rescale color based on intensity
	glLight.color = GLTFExportTypes.rgb(light.color.cpy().mul(1f / glLight.intensity));
	glLight.intensity *= intensityScale;
	
	return glLight;
}
 
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)
	);
}