com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute. 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: Utils3D.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public static void createFloor() {

		ModelBuilder modelBuilder = new ModelBuilder();
		modelBuilder.begin();
		MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES,
				Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(
						ColorAttribute.createDiffuse(Color.WHITE)));
		mpb.setColor(1f, 1f, 1f, 1f);
//		mpb.box(0, -0.1f, 0, 10, .2f, 10);
		mpb.rect(-10, 0, -10, 
				-10, 0, 10,
				10, 0, 10,
				10, 0, -10, 0, 1, 0);
		floorModel = modelBuilder.end();
		floorInstance = new ModelInstance(floorModel);
		
		// TODO Set only when FBO is active
		floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
	}
 
Example #2
Source File: RotateTool.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public RotateHandle(int id, Color color) {
    super(id);
    model = UsefulMeshs.torus(new Material(ColorAttribute.createDiffuse(color)), 20, 1f, 50, 50);
    modelInstance = new ModelInstance(model);
    modelInstance.materials.first().set(getIdAttribute());
    switch (id) {
    case X_HANDLE_ID:
        this.getRotationEuler().y = 90;
        this.getScale().x = 0.9f;
        this.getScale().y = 0.9f;
        this.getScale().z = 0.9f;
        break;
    case Y_HANDLE_ID:
        this.getRotationEuler().x = 90;
        break;
    case Z_HANDLE_ID:
        this.getRotationEuler().z = 90;
        this.getScale().x = 1.1f;
        this.getScale().y = 1.1f;
        this.getScale().z = 1.1f;
        break;
    }
    // mi.transform.translate(0, 100, 0);
}
 
Example #3
Source File: ScaleTool.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
    super(projectManager, goPicker, handlePicker, batch, history);

    this.shapeRenderer = shapeRenderer;

    ModelBuilder modelBuilder = new ModelBuilder();
    Model xPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_X)),
            Vector3.Zero, new Vector3(15, 0, 0));
    Model yPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Y)),
            Vector3.Zero, new Vector3(0, 15, 0));
    Model zPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Z)),
            Vector3.Zero, new Vector3(0, 0, 15));
    Model xyzPlaneHandleModel = modelBuilder.createBox(3, 3, 3,
            new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

    xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
    yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
    zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
    xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);

    handles = new ScaleHandle[] { xHandle, yHandle, zHandle, xyzHandle };
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: PBRShader.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
@Override
protected void bindLights(Renderable renderable, Attributes attributes) {
	
	// XXX update color (to apply intensity) before default binding
	DirectionalLightsAttribute dla = attributes.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type);
	if(dla != null){
		for(DirectionalLight light : dla.lights){
			if(light instanceof DirectionalLightEx){
				((DirectionalLightEx) light).updateColor();
			}
		}
	}
	
	super.bindLights(renderable, attributes);
		
	// XXX
	ColorAttribute ambiantLight = attributes.get(ColorAttribute.class, ColorAttribute.AmbientLight);
	if(ambiantLight != null){
		program.setUniformf(u_ambientLight, ambiantLight.color.r, ambiantLight.color.g, ambiantLight.color.b);
	}
}
 
Example #9
Source File: ModelManager.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
/** players are represented by cubes, with another cube marking the direction it is facing */
public void createPlayerModel() {
	ModelBuilder mb = new ModelBuilder();
	ModelBuilder mb2 = new ModelBuilder();
	long attr = Usage.Position | Usage.Normal;
	float r = 0.5f;
	float g = 1f;
	float b = 0.75f;
	Material material = new Material(ColorAttribute.createDiffuse(new Color(r, g, b, 1f)));
	Material faceMaterial = new Material(ColorAttribute.createDiffuse(Color.BLUE));
	float w = 1f;
	float d = w;
	float h = 2f;
	mb.begin();
	//playerModel = mb.createBox(w, h, d, material, attr);
	Node node = mb.node("box", mb2.createBox(w, h, d, material, attr));
	// the face is just a box to show which direction the player is facing
	Node faceNode = mb.node("face", mb2.createBox(w/2, h/2, d/2, faceMaterial, attr));
	faceNode.translation.set(0f, 0f, d/2);
	playerModel = mb.end();
}
 
Example #10
Source File: ColorAttributeUI.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
public ColorAttributeUI(Skin skin, final ColorAttribute attribute) {
	super(skin);
	if(attribute == null) return;
	this.attribute = attribute;
	add(ColorAttribute.getAttributeAlias(attribute.type));
	for(int i=0 ; i<4 ; i++){
		if(i != 0) add();
		final Slider slider = new Slider(0, 1, .01f, false, skin);
		add(slider).row();
		slider.setValue(get(i));
		final int index = i;
		slider.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				set(index, slider.getValue());
			}
		});
		sliders.add(slider);
	}
}
 
Example #11
Source File: Actor3d.java    From Scene3d with Apache License 2.0 5 votes vote down vote up
public void setColor(Color color){
	ColorAttribute ca = new ColorAttribute(ColorAttribute.Diffuse, color);
	if(getMaterial("Color") != null)
		getMaterial("Color").set(ca);
	else
		materials.add(new Material("Color", ca));
		model.materials.add(new Material("Color", ca));
}
 
Example #12
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 #13
Source File: GLTFDemoUI.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
protected void setMaterial(String materialID) {
	materialTable.clearChildren();
	if(materialID == null || materialID.isEmpty()) return;
	
	final Material material = materialMap.get(materialID);
	
	// base color
	materialTable.add(new ColorAttributeUI(getSkin(), material.get(ColorAttribute.class, PBRColorAttribute.BaseColorFactor))).row();
	addMaterialTextureSwitch("Color Texture", material, PBRTextureAttribute.BaseColorTexture);

	// emissive
	materialTable.add(new ColorAttributeUI(getSkin(), material.get(ColorAttribute.class, PBRColorAttribute.Emissive))).row();
	addMaterialTextureSwitch("Emissive Texture", material, PBRTextureAttribute.EmissiveTexture);
	
	// metallic roughness
	materialTable.add(new FloatAttributeUI(getSkin(), material.get(PBRFloatAttribute.class, PBRFloatAttribute.Metallic))).row();
	materialTable.add(new FloatAttributeUI(getSkin(), material.get(PBRFloatAttribute.class, PBRFloatAttribute.Roughness))).row();
	addMaterialTextureSwitch("MR Texture", material, PBRTextureAttribute.MetallicRoughnessTexture);
	
	// normal
	materialTable.add(new FloatAttributeUI(getSkin(), material.get(PBRFloatAttribute.class, PBRFloatAttribute.NormalScale))).row();
	addMaterialTextureSwitch("Normal Texture", material, PBRTextureAttribute.NormalTexture);
	
	// occlusion
	materialTable.add(new FloatAttributeUI(getSkin(), material.get(PBRFloatAttribute.class, PBRFloatAttribute.OcclusionStrength))).row();
	addMaterialTextureSwitch("Occlusion Texture", material, PBRTextureAttribute.OcclusionTexture);
}
 
Example #14
Source File: HeightMapModel.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public HeightMapModel(HeightMap hm) {
	this.heightMap = hm;
	String groundTexName = "textures/hm_paint.png";
	groundTexture = new Texture(Gdx.files.internal(groundTexName), true);
	groundTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
	groundTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.Linear);
	groundMat = new Material(TextureAttribute.createDiffuse(groundTexture)
			, ColorAttribute.createSpecular(specular)
	);
	createGround();
}
 
Example #15
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 #16
Source File: ModelFactory.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
public static Model buildCompassModel() {
	float compassScale = 5;
	ModelBuilder modelBuilder = new ModelBuilder();
	Model arrow = modelBuilder.createArrow(Vector3.Zero,
			Vector3.Y.cpy().scl(compassScale), null,
			VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
	modelBuilder.begin();

	Mesh zArrow = arrow.meshes.first().copy(false);
	zArrow.transform(new Matrix4().rotate(Vector3.X, 90));
	modelBuilder.part("part1", zArrow, GL20.GL_TRIANGLES,
			new Material(ColorAttribute.createDiffuse(Color.BLUE)));

	modelBuilder.node();
	Mesh yArrow = arrow.meshes.first().copy(false);
	modelBuilder.part("part2", yArrow, GL20.GL_TRIANGLES,
			new Material(ColorAttribute.createDiffuse(Color.GREEN)));

	modelBuilder.node();
	Mesh xArrow = arrow.meshes.first().copy(false);
	xArrow.transform(new Matrix4().rotate(Vector3.Z, -90));
	modelBuilder.part("part3", xArrow, GL20.GL_TRIANGLES,
			new Material(ColorAttribute.createDiffuse(Color.RED)));

	arrow.dispose();
	return modelBuilder.end();
}
 
Example #17
Source File: ModelFactory.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
public static Model buildBillboardModel(Texture texture, float width, float height) {
	TextureRegion textureRegion = new TextureRegion(texture, texture.getWidth(), texture.getHeight());
	Material material = new Material();
	material.set(new TextureAttribute(TextureAttribute.Diffuse, textureRegion));
	material.set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));
	material.set(new BlendingAttribute());
	return ModelFactory.buildPlaneModel(width, height, material, 0, 0, 1, 1);
}
 
Example #18
Source File: ModelFactory.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
public static void createOutlineModel(Model model, Color outlineColor, float fattenAmount) {
	fatten(model, fattenAmount);
	for (Material m : model.materials) {
		m.clear();
		m.set(new IntAttribute(IntAttribute.CullFace, Gdx.gl.GL_FRONT));
		m.set(ColorAttribute.createDiffuse(outlineColor));
	}
}
 
Example #19
Source File: BaseEntity.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
public void setColor (float r, float g, float b, float a) {
	color.set(r, g, b, a);
	if (modelInstance != null) {
		for (Material m : modelInstance.materials) {
			ColorAttribute ca = (ColorAttribute)m.get(ColorAttribute.Diffuse);
			if (ca != null) ca.color.set(r, g, b, a);
		}
	}
}
 
Example #20
Source File: TranslateTool.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public TranslateTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ModelBatch batch, CommandHistory history) {

    super(projectManager, goPicker, handlePicker, batch, history);

    ModelBuilder modelBuilder = new ModelBuilder();

    Model xHandleModel = modelBuilder.createArrow(0, 0, 0, 1, 0, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
            GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_X)),
            VertexAttributes.Usage.Position);
    Model yHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 1, 0, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
            GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Y)),
            VertexAttributes.Usage.Position);
    Model zHandleModel = modelBuilder.createArrow(0, 0, 0, 0, 0, 1, ARROW_CAP_SIZE, ARROW_THIKNESS, ARROW_DIVISIONS,
            GL20.GL_TRIANGLES, new Material(ColorAttribute.createDiffuse(COLOR_Z)),
            VertexAttributes.Usage.Position);
    Model xzPlaneHandleModel = modelBuilder.createSphere(1, 1, 1, 20, 20,
            new Material(ColorAttribute.createDiffuse(COLOR_XZ)), VertexAttributes.Usage.Position);

    xHandle = new TranslateHandle(X_HANDLE_ID, xHandleModel);
    yHandle = new TranslateHandle(Y_HANDLE_ID, yHandleModel);
    zHandle = new TranslateHandle(Z_HANDLE_ID, zHandleModel);
    xzPlaneHandle = new TranslateHandle(XZ_HANDLE_ID, xzPlaneHandleModel);
    handles = new TranslateHandle[] { xHandle, yHandle, zHandle, xzPlaneHandle };

    gameObjectModifiedEvent = new GameObjectModifiedEvent(null);
}
 
Example #21
Source File: MaterialAsset.java    From Mundus with Apache License 2.0 5 votes vote down vote up
/**
 * Applies this material asset to the libGDX material.
 *
 * @param material
 * @return
 */
public Material applyToMaterial(Material material) {
    if (diffuseColor != null) {
        material.set(new ColorAttribute(ColorAttribute.Diffuse, diffuseColor));
    }
    if (diffuseTexture != null) {
        material.set(new TextureAttribute(TextureAttribute.Diffuse, diffuseTexture.getTexture()));
    } else {
        material.remove(TextureAttribute.Diffuse);
    }
    material.set(new FloatAttribute(FloatAttribute.Shininess, shininess));

    return material;
}
 
Example #22
Source File: ModelShader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void render(Renderable renderable) {
    final MundusEnvironment env = (MundusEnvironment) renderable.environment;

    setLights(env);
    set(UNIFORM_TRANS_MATRIX, renderable.worldTransform);

    // texture uniform
    TextureAttribute diffuseTexture = ((TextureAttribute) (renderable.material.get(TextureAttribute.Diffuse)));
    ColorAttribute diffuseColor = ((ColorAttribute) (renderable.material.get(ColorAttribute.Diffuse)));

    if (diffuseTexture != null) {
        set(UNIFORM_MATERIAL_DIFFUSE_TEXTURE, diffuseTexture.textureDescription.texture);
        set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 1);
    } else {
        set(UNIFORM_MATERIAL_DIFFUSE_COLOR, diffuseColor.color);
        set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 0);
    }

    // shininess
    float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
    set(UNIFORM_MATERIAL_SHININESS, shininess);

    // Fog
    final Fog fog = env.getFog();
    if (fog == null) {
        set(UNIFORM_FOG_DENSITY, 0f);
        set(UNIFORM_FOG_GRADIENT, 0f);
    } else {
        set(UNIFORM_FOG_DENSITY, fog.density);
        set(UNIFORM_FOG_GRADIENT, fog.gradient);
        set(UNIFORM_FOG_COLOR, fog.color);
    }

    // bind attributes, bind mesh & render; then unbinds everything
    renderable.meshPart.render(program);
}
 
Example #23
Source File: DemoMotionGdxAdapter.java    From thunderboard-android with Apache License 2.0 5 votes vote down vote up
public void turnOffLights() {
    for (Material mat : lightMaterials) {
        if (mat.has(ColorAttribute.Emissive)) {
            mat.remove(ColorAttribute.Emissive);
        }
    }
}
 
Example #24
Source File: PBRShader.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) {
	ColorAttribute attribute = combinedAttributes.get(ColorAttribute.class, PBRColorAttribute.BaseColorFactor);
	Color color = attribute == null ? Color.WHITE : attribute.color;
	shader.set(inputID, color);
}
 
Example #25
Source File: SceneManager.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public SceneManager(ShaderProvider shaderProvider, DepthShaderProvider depthShaderProvider, RenderableSorter renderableSorter)
{
	this.renderableSorter = renderableSorter;
	
	batch = new ModelBatch(shaderProvider, renderableSorter);
	
	depthBatch = new ModelBatch(depthShaderProvider);
	
	float lum = 1f;
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, lum, lum, lum, 1));
}
 
Example #26
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 #27
Source File: GLTFDemo.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
@Override
public void render() {
	float delta = Gdx.graphics.getDeltaTime();
	stage.act();
	
	// recreate shaders if needed
	validateShaders();

	sceneManager.update(delta);
	
	if(cameraControl != null){
		cameraControl.update();
	}
	
	Gdx.gl.glClearColor(ui.fogColor.value.r, ui.fogColor.value.g, ui.fogColor.value.b, 0f);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
	
	sceneManager.setAmbientLight(ui.ambiantSlider.getValue());
	
	ColorAttribute fog = sceneManager.environment.get(ColorAttribute.class, ColorAttribute.Fog);
	if(fog != null) fog.color.set(ui.fogColor.value);
	
	FogAttribute fogEquation = sceneManager.environment.get(FogAttribute.class, FogAttribute.FogEquation);
	if(fogEquation != null){
		fogEquation.value.set(
				MathUtils.lerp(sceneManager.camera.near, sceneManager.camera.far, (ui.fogEquation.value.x + 1f) / 2f),
				MathUtils.lerp(sceneManager.camera.near, sceneManager.camera.far, (ui.fogEquation.value.y + 1f) / 2f),
				10f * (ui.fogEquation.value.z + 1f) / 2f
				);
	}
	
	skybox.getColor().set(ui.skyBoxColor.value);
	
	DirectionalLight light = sceneManager.getFirstDirectionalLight();
	if(light != null){
		float lum = ui.lightSlider.getValue();
		if(light instanceof DirectionalLightEx){
			DirectionalLightEx lightEx = (DirectionalLightEx)light;
			lightEx.intensity = lum;
			lightEx.updateColor();
		}
		light.direction.set(ui.lightDirectionControl.value).nor();
		
		PBRFloatAttribute shadowBias = sceneManager.environment.get(PBRFloatAttribute.class, PBRFloatAttribute.ShadowBias);
		shadowBias.value = ui.shadowBias.getValue() / 50f;
	}

	sceneManager.render();

	if(ui.outlinesEnabled.isOn()){
		captureDepth();

		outlineShader.begin();
		float size = 1 - ui.outlinesWidth.getValue();
		
		// float depthMin = ui.outlineDepthMin.getValue() * .001f;
		float depthMin = (float)Math.pow(ui.outlineDepthMin.getValue(), 10); // 0.35f
		float depthMax = (float)Math.pow(ui.outlineDepthMax.getValue(), 10); // 0.9f
		
		// TODO use an integer instead and divide w and h
		outlineShader.setUniformf("u_size", Gdx.graphics.getWidth() * size, Gdx.graphics.getHeight() * size);
		outlineShader.setUniformf("u_depth_min", depthMin);
		outlineShader.setUniformf("u_depth_max", depthMax);
		outlineShader.setUniformf("u_inner_color", ui.outlineInnerColor.getValue());
		outlineShader.setUniformf("u_outer_color", ui.outlineOuterColor.getValue());
		
		if(ui.outlineDistFalloffOption.isOn()){
			
			float distanceFalloff = ui.outlineDistFalloff.getValue();
			if(distanceFalloff <= 0){
				distanceFalloff = .001f;
			}
			outlineShader.setUniformf("u_depthRange", sceneManager.camera.far / (sceneManager.camera.near * distanceFalloff));
		}
		
		spriteBatch.enableBlending();
		spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1);
		spriteBatch.setShader(outlineShader);
		spriteBatch.begin();
		spriteBatch.draw(depthFbo.getColorBufferTexture(), 0, 0, 1, 1, 0f, 0f, 1f, 1f);
		spriteBatch.end();
		spriteBatch.setShader(null);
	}
	
	renderOverlays();
	
	int shaderCount = 0;
	ShaderProvider shaderProvider = sceneManager.getBatch().getShaderProvider();
	if(shaderProvider instanceof PBRShaderProvider){
		shaderCount = ((PBRShaderProvider) shaderProvider).getShaderCount();
	}
	ui.shaderCount.setText(String.valueOf(shaderCount));
	
	stage.draw();
}
 
Example #28
Source File: TranslateTool.java    From Mundus with Apache License 2.0 4 votes vote down vote up
public void changeColor(Color color) {
    ColorAttribute diffuse = (ColorAttribute) modelInstance.materials.get(0).get(ColorAttribute.Diffuse);
    diffuse.color.set(color);
}
 
Example #29
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 #30
Source File: TerrainChunk.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public TerrainChunk setSpecularColor(Color specular) {
	modelInstance.materials.get(0).set(ColorAttribute.createSpecular(specular));
	return this;
}