Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 323
Casper Lindberg Avatar asked Dec 05 '25 18:12

Casper Lindberg


1 Answers

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)
        }
}
like image 136
Andy Jazz Avatar answered Dec 08 '25 07:12

Andy Jazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!