Search in sources :

Example 6 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class ParticleShader method bindMaterial.

protected void bindMaterial(final Renderable renderable) {
    if (currentMaterial == renderable.material)
        return;
    int cullFace = config.defaultCullFace == -1 ? GL20.GL_BACK : config.defaultCullFace;
    int depthFunc = config.defaultDepthFunc == -1 ? GL20.GL_LEQUAL : config.defaultDepthFunc;
    float depthRangeNear = 0f;
    float depthRangeFar = 1f;
    boolean depthMask = true;
    currentMaterial = renderable.material;
    for (final Attribute attr : currentMaterial) {
        final long t = attr.type;
        if (BlendingAttribute.is(t)) {
            context.setBlending(true, ((BlendingAttribute) attr).sourceFunction, ((BlendingAttribute) attr).destFunction);
        } else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) {
            DepthTestAttribute dta = (DepthTestAttribute) attr;
            depthFunc = dta.depthFunc;
            depthRangeNear = dta.depthRangeNear;
            depthRangeFar = dta.depthRangeFar;
            depthMask = dta.depthMask;
        } else if (!config.ignoreUnimplemented)
            throw new GdxRuntimeException("Unknown material attribute: " + attr.toString());
    }
    context.setCullFace(cullFace);
    context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar);
    context.setDepthMask(depthMask);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) Attribute(com.badlogic.gdx.graphics.g3d.Attribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) DepthTestAttribute(com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute) IntAttribute(com.badlogic.gdx.graphics.g3d.attributes.IntAttribute) DepthTestAttribute(com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute)

Example 7 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class PointSpriteParticleBatch method allocRenderable.

protected void allocRenderable() {
    renderable = new Renderable();
    renderable.meshPart.primitiveType = GL20.GL_POINTS;
    renderable.meshPart.offset = 0;
    renderable.material = new Material(new BlendingAttribute(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA, 1f), new DepthTestAttribute(GL20.GL_LEQUAL, false), TextureAttribute.createDiffuse((Texture) null));
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) Material(com.badlogic.gdx.graphics.g3d.Material) DepthTestAttribute(com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute)

Example 8 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class SkeletonTest method onLoaded.

@Override
protected void onLoaded() {
    if (currentlyLoading == null || currentlyLoading.isEmpty())
        return;
    instances.clear();
    animationControllers.clear();
    final ModelInstance instance = new ModelInstance(assets.get(currentlyLoading, Model.class));
    for (Material m : instance.materials) m.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.8f));
    instances.add(instance);
    if (instance.animations.size > 0)
        animationControllers.put(instance, new AnimationController(instance));
    currentlyLoading = null;
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material)

Example 9 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project libgdx by libgdx.

the class MaterialTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
    // Create material attributes. Each material can contain x-number of attributes.
    textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture);
    colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE);
    blendingAttribute = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    ModelBuilder builder = new ModelBuilder();
    model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    model.manageDisposable(texture);
    modelInstance = new ModelInstance(model);
    modelInstance.transform.rotate(Vector3.X, 45);
    material = modelInstance.materials.get(0);
    builder.begin();
    MeshPartBuilder mpb = builder.part("back", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates, new Material(textureAttribute));
    mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1);
    backModel = builder.end();
    background = new ModelInstance(backModel);
    modelBatch = new ModelBatch();
    camera = new PerspectiveCamera(45, 4, 4);
    camera.position.set(0, 0, 3);
    camera.direction.set(0, 0, -1);
    camera.update();
    Gdx.input.setInputProcessor(this);
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) Texture(com.badlogic.gdx.graphics.Texture) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 10 with BlendingAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute in project bdx by GoranM.

the class BDXShaderProvider method render.

public void render(Renderable renderable, Attributes combinedAttributes) {
    if (renderable.material.has(BlendingAttribute.Type)) {
        BlendingAttribute ba = (BlendingAttribute) renderable.material.get(BlendingAttribute.Type);
        Gdx.gl.glBlendFuncSeparate(ba.sourceFunction, ba.destFunction, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
    IntAttribute shadeless = (IntAttribute) renderable.material.get(Scene.BDXIntAttribute.Shadeless);
    if (shadeless == null)
        set(u_shadeless, 0);
    else
        set(u_shadeless, shadeless.value);
    ColorAttribute tint = (ColorAttribute) renderable.material.get(Scene.BDXColorAttribute.Tint);
    if (tint == null)
        set(u_tintColor, new Color());
    else
        set(u_tintColor, tint.color);
    ColorAttribute emit = (ColorAttribute) renderable.material.get(Scene.BDXColorAttribute.Emit);
    if (emit == null)
        set(u_emitColor, new Color());
    else
        set(u_emitColor, emit.color);
    if (shaderProvider.scene != null) {
        ColorAttribute fog = (ColorAttribute) renderable.environment.get(ColorAttribute.Fog);
        if (fog == null)
            set(u_fogRange, 0f, 0f);
        else
            set(u_fogRange, shaderProvider.scene.fogRange().x, shaderProvider.scene.fogRange().y);
        set(u_camRange, shaderProvider.scene.camera.near(), shaderProvider.scene.camera.far());
    }
    super.render(renderable, combinedAttributes);
}
Also used : BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) IntAttribute(com.badlogic.gdx.graphics.g3d.attributes.IntAttribute) Color(com.badlogic.gdx.graphics.Color) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)10 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)5 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)4 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)4 Material (com.badlogic.gdx.graphics.g3d.Material)3 DepthTestAttribute (com.badlogic.gdx.graphics.g3d.attributes.DepthTestAttribute)3 IntAttribute (com.badlogic.gdx.graphics.g3d.attributes.IntAttribute)3 Texture (com.badlogic.gdx.graphics.Texture)2 Attribute (com.badlogic.gdx.graphics.g3d.Attribute)2 Model (com.badlogic.gdx.graphics.g3d.Model)2 FloatAttribute (com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute)2 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 Color (com.badlogic.gdx.graphics.Color)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)1 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)1 CubemapAttribute (com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute)1 DirectionalLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute)1