Skip to content

Bombshell 01 Blending

contriteobserver edited this page Jul 17, 2017 · 2 revisions

Blending

(Just dumping information here at the moment, this will be more coherent)

Blending controls how an Object3D is applied to a current scene. The following example is a scene with a red, green, and blue sphere placed around the origin

protected void initScene() {
    getCurrentScene().setBackgroundColor(Color.LTGRAY);

    Material red = new Material();
    red.setColor(Color.argb(0x7f, 0xff, 0x00, 0x00));

    Material green = new Material();
    green.setColor(Color.argb(0x7f, 0x00, 0xff, 0x00));

    Material blue = new Material();
    blue.setColor(Color.argb(0x7f, 0x00, 0x00, 0xff));

    Object3D alpha = new Sphere(1.5f, 16, 16);
    alpha.setX(Math.sin(2d*Math.PI/3d));
    alpha.setY(Math.cos(2d*Math.PI/3d));
    alpha.setMaterial(green);
    alpha.setTransparent(true);
    getCurrentScene().addChild(alpha);

    Object3D beta = new Sphere(1.5f, 16, 16);
    beta.setX(Math.sin(4d*Math.PI/3d));
    beta.setY(Math.cos(4d*Math.PI/3d));
    beta.setMaterial(blue);
    beta.setTransparent(true);
    getCurrentScene().addChild(beta);

    Object3D gamma = new Sphere(1.5f, 16, 16);
    gamma.setX(Math.sin(6d*Math.PI/3d));
    gamma.setY(Math.cos(6d*Math.PI/3d));
    gamma.setMaterial(red);
    gamma.setTransparent(true);
    getCurrentScene().addChild(gamma);

    getCurrentCamera().setPosition(new Vector3(0,0,11));
    getCurrentCamera().setLookAt(Vector3.ZERO);
}

Interpolative Blending

The default approach is interpolative blending, semi-transparent materials look like tinted glass.

Additive Blending

In additive blending, the object's color is added to the scene, good for prompts, cursors, clouds, planets and stars.

    getCurrentScene().setBackgroundColor(Color.DKGRAY);
    alpha.setBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE);
    beta.setBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE);
    gamma.setBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE);

Clone this wiki locally