com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute.
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 |
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: ModelManager.java From gdx-proto with Apache License 2.0 | 6 votes |
public void createBillboardTest() { ModelBuilder mb = new ModelBuilder(); mb.begin(); long attr = Usage.TextureCoordinates | Usage.Position | Usage.Normal; TextureRegion region = Assets.getAtlas().findRegion("sprites/test-guy"); Material mat = new Material(TextureAttribute.createDiffuse(region.getTexture())); boolean blended = true; float opacity = 1f; mat.set(new BlendingAttribute(blended, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, opacity)); MeshPartBuilder mpb = mb.part("rect", GL20.GL_TRIANGLES, attr, mat); mpb.setUVRange(region); // the coordinates are offset so that we can easily set the center position to align with the entity's body float sz = 2f; // size float b = -sz/2; // base float max = sz/2; // max Vector3 bl = new Vector3(b, b, 0f); Vector3 br = new Vector3(b, max, 0f); Vector3 tr = new Vector3(max, max, 0f); Vector3 tl = new Vector3(max, b, 0f); Vector3 norm = new Vector3(0f, 0f, 1f); mpb.rect(bl, tl, tr, br, norm); billboardTestModel = mb.end(); }
Example #3
Source File: Shadow.java From gdx-proto with Apache License 2.0 | 6 votes |
public static void init() { list = new Array<>(); ModelBuilder mb = new ModelBuilder(); Vector3 norm = new Vector3(0f, 1f, 0f); Texture texture = Assets.manager.get("textures/shadow.png", Texture.class); Material material = new Material(TextureAttribute.createDiffuse(texture)); material.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.7f)); //material.set(new DepthTestAttribute(0)); // disable depth testing long attr = Usage.Position | Usage.TextureCoordinates; float s = 1f; model = mb.createRect( -s, 0f, -s,// bl -s, 0f, s, // tl s, 0f, s, // tr s, 0f, -s, // br norm.x, norm.y, norm.z, material, attr ); }
Example #4
Source File: SceneRenderableSorter.java From gdx-gltf with Apache License 2.0 | 5 votes |
@Override public int compare(Renderable o1, Renderable o2) { // original (blending and hints) final boolean b1 = o1.material.has(BlendingAttribute.Type) && ((BlendingAttribute)o1.material.get(BlendingAttribute.Type)).blended; final boolean b2 = o2.material.has(BlendingAttribute.Type) && ((BlendingAttribute)o2.material.get(BlendingAttribute.Type)).blended; final Hints h1 = o1.userData instanceof Hints ? (Hints)o1.userData : null; final Hints h2 = o2.userData instanceof Hints ? (Hints)o2.userData : null; if(h1 != h2){ if(h1 == Hints.OPAQUE_LAST){ return b2 ? -1 : 1; } if(h2 == Hints.OPAQUE_LAST){ return b1 ? 1 : -1; } } // simple switch limitation by identifying same context. int shaderCompare = compareIdentity(o1.shader, o2.shader); if(shaderCompare != 0) return shaderCompare; int envCompare = compareIdentityNullable(o1.environment, o2.environment); if(envCompare != 0) return envCompare; int materialCompare = compareIdentity(o1.material, o2.material); if(materialCompare != 0) return materialCompare; int meshCompare = compareIdentity(o1.meshPart.mesh, o2.meshPart.mesh); if(meshCompare != 0) return meshCompare; // classic with distance getTranslation(o1.worldTransform, o1.meshPart.center, tmpV1); getTranslation(o2.worldTransform, o2.meshPart.center, tmpV2); final float dst = (int)(camera.position.dst2(tmpV1)) - (int)(camera.position.dst2(tmpV2)); final int result = dst < 0 ? -1 : (dst > 0 ? 1 : 0); return b1 ? -result : result; }
Example #5
Source File: GameRenderer.java From Radix with MIT License | 5 votes |
private void drawBlockSelection() { int curProgressInt = Math.round(RadixClient.getInstance().getPlayer().getBreakPercent() * 10) - 1; if ((blockBreakModel == null || blockBreakStage != curProgressInt) && curProgressInt >= 0) { if (blockBreakModel != null) blockBreakModel.dispose(); blockBreakStage = curProgressInt; ModelBuilder builder = new ModelBuilder(); blockBreakModel = builder.createBox(1f, 1f, 1f, new Material(TextureAttribute.createDiffuse(blockBreakStages[blockBreakStage]), new BlendingAttribute(), FloatAttribute.createAlphaTest(0.25f)), VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates); blockBreakModelInstance = new ModelInstance(blockBreakModel); } Vec3i curBlk = RadixClient.getInstance().getSelectedBlock(); if (curBlk != null && curProgressInt >= 0) { Gdx.gl.glPolygonOffset(100000, 2000000); blockOverlayBatch.begin(RadixClient.getInstance().getCamera()); blockBreakModelInstance.transform.translate(curBlk.x + 0.5f, curBlk.y + 0.5f, curBlk.z + 0.5f); blockOverlayBatch.render(blockBreakModelInstance); blockBreakModelInstance.transform.translate(-(curBlk.x + 0.5f), -(curBlk.y + 0.5f), -(curBlk.z + 0.5f)); blockOverlayBatch.end(); Gdx.gl.glPolygonOffset(100000, -2000000); } }
Example #6
Source File: ModelFactory.java From GdxDemo3D with Apache License 2.0 | 5 votes |
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 #7
Source File: GLTFMaterialExporter.java From gdx-gltf with Apache License 2.0 | 4 votes |
private void export(Material material) { if(base.materialMapping.contains(material, true)) return; base.materialMapping.add(material); GLTFMaterial m = new GLTFMaterial(); if(base.root.materials == null) base.root.materials = new Array<GLTFMaterial>(); base.root.materials.add(m); m.name = material.id; boolean blending = false; for(Attribute a : material){ if(a.type == ColorAttribute.Diffuse){ pbr(m).baseColorFactor = GLTFExportTypes.rgba(defaultNull(Color.WHITE, (ColorAttribute)a)); } else if(a.type == PBRColorAttribute.BaseColorFactor){ pbr(m).baseColorFactor = GLTFExportTypes.rgba(defaultNull(Color.WHITE, (PBRColorAttribute)a)); } else if(a.type == ColorAttribute.Emissive){ m.emissiveFactor = GLTFExportTypes.rgb(defaultNull(Color.BLACK, (ColorAttribute)a)); } else if(a.type == BlendingAttribute.Type){ blending = true; } else if(a.type == IntAttribute.CullFace){ m.doubleSided = defaultNull(true, ((IntAttribute)a).value == 0); } else if(a.type == FloatAttribute.AlphaTest){ m.alphaCutoff = ((FloatAttribute)a).value; } else if(a.type == PBRFloatAttribute.Metallic){ pbr(m).metallicFactor = ((PBRFloatAttribute)a).value; } else if(a.type == PBRFloatAttribute.Roughness){ pbr(m).roughnessFactor = ((PBRFloatAttribute)a).value; } else if(a.type == PBRTextureAttribute.BaseColorTexture){ pbr(m).baseColorTexture = texture((PBRTextureAttribute)a); } else if(a.type == PBRTextureAttribute.MetallicRoughnessTexture){ pbr(m).metallicRoughnessTexture = texture((PBRTextureAttribute)a); } else if(a.type == PBRTextureAttribute.EmissiveTexture){ m.emissiveTexture = texture((PBRTextureAttribute)a); } else if(a.type == PBRTextureAttribute.NormalTexture){ m.normalTexture = normalTexture((PBRTextureAttribute)a, material); } else if(a.type == PBRTextureAttribute.OcclusionTexture){ m.occlusionTexture = occlusionTexture((PBRTextureAttribute)a, material); } } if(blending){ if(m.alphaCutoff != null){ m.alphaMode = "MASK"; }else{ m.alphaMode = "BLEND"; } } }
Example #8
Source File: Chunk.java From Radix with MIT License | 4 votes |
private void updateModelInstances() { if(opaqueFaces != null) { if(opaqueModel != null) opaqueModel.dispose(); Mesh opaqueMesh = mesher.meshFaces(opaqueFaces, meshBuilder); modelBuilder.begin(); modelBuilder.part(String.format("c-%d,%d", startPosition.x, startPosition.z), opaqueMesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()))); opaqueModel = modelBuilder.end(); opaqueModelInstance = new ModelInstance(opaqueModel) { @Override public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) { super.getRenderable(out, node, nodePart); if(RadixClient.getInstance().isWireframe()) { out.primitiveType = GL20.GL_LINES; } else { out.primitiveType = GL20.GL_TRIANGLES; } return out; } }; opaqueFaces = null; } if(translucentFaces != null) { if(translucentModel != null) translucentModel.dispose(); Mesh translucentMesh = mesher.meshFaces(translucentFaces, meshBuilder); modelBuilder.begin(); modelBuilder.part(String.format("c-%d,%d-t", startPosition.x, startPosition.z), translucentMesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()), new BlendingAttribute(), FloatAttribute.createAlphaTest(0.25f))); translucentModel = modelBuilder.end(); translucentModelInstance = new ModelInstance(translucentModel) { @Override public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) { super.getRenderable(out, node, nodePart); if(RadixClient.getInstance().isWireframe()) { out.primitiveType = GL20.GL_LINES; } else { out.primitiveType = GL20.GL_TRIANGLES; } return out; } }; translucentFaces = null; } }