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>
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)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With