Casper Lindberg
Casper Lindberg

Reputation: 1103

Sceneform Transparent Material

Goal

Transparent material for a cube renderable created with ShapeFactory.

Tried

MaterialFactory.makeTransparentWithColor(context, Color(0f, 0f, 0f, 0f)).thenAccept { material ->

    val size = Vector3(100f,0.001f,100f)
    val center = Vector3(0f,0f,0f)
    val floorRenderable = ShapeFactory.makeCube(size,center,material)
    floorRenderable.isShadowCaster = false
    floorRenderable.isShadowReceiver = false

    floorAnchorNode.renderable = floorRenderable
}

So for Color(0f, 0f, 0f, 0f), the cube does not become invisible, even though it is a little bit transparent.

I have also tried the following with the same result.

context.getColor(R.color.transparent) 

where

<color name="transparent">#00000000</color>

Upvotes: 4

Views: 525

Answers (2)

Andy Jazz
Andy Jazz

Reputation: 58113

If you apply .setFloat() instance methods to a shader object, you can set the appropriate values ​​for the color, metallic, roughness and reflectance channels. The paradox is that for the sphere primitive these settings work fine, but the cube primitive with the same settings doesn't become completely transparent (looks like a system bug). Turning the lighting off (scene's sunlight and light estimation) doesn't affect the residual surface illumination of the cube, even though it has a zero thickness like a plane.

private fun addTransparentPrimitiveToSceneIn(fragment: ArFragment) {
    MaterialFactory.makeTransparentWithColor(this, Color())
        .thenAccept { shader ->
            shader.setFloat4("color", Color(0f,0f,0f,0f))
            shader.setFloat("metallic", 0f)
            shader.setFloat("roughness", 1f)
            shader.setFloat("reflectance", 0f)

            val sphere = ShapeFactory.makeSphere(0.5f, Vector3(), shader)
            val node = TransformableNode(fragment.transformationSystem)
            node.renderable = sphere
            node.worldPosition = Vector3(0f, 0f,-2f)
            fragment.arSceneView.scene.addChild(node)
        }
}

Upvotes: 1

Simon Marquis
Simon Marquis

Reputation: 7526

It's not fully transparent simply because of lighting.

If you need to make something invisible, don't set any renderable. And if you simply want to intercept touch, use collision instead :

floorAnchorNode.collisionShape = Box(size, center)

Upvotes: -1

Related Questions