SceneView / sceneview-android

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin
Apache License 2.0
816 stars 159 forks source link

Environment file looks correct on emulator but dark on device #415

Closed kukabi closed 7 months ago

kukabi commented 7 months ago

I'm trying to load a model and set the environment HDR. It's looking correct on the emulator:

Yet the HDR environment is looking very dark on an actual device, so I get no environment reflection and lighting on the GLB model:

Environment file does get loaded, as you can see it partially in the second dark rotated screenshot, but it's very dark, as if there was an intensity parameter and it turned lower than actual on the device.

I checked whether the problem was with the HDR file, but the sky HDR file in the samples ends up the same.

Code:

fun IdenticonView(modifier: Modifier = Modifier) {
    val engine = rememberEngine()
    val modelLoader = rememberModelLoader(engine)
    val cameraNode =
        rememberCameraNode(engine) {
            position = Position(z = 3.0f)
        }
    val centerNode = rememberNode(engine).addChildNode(cameraNode)
    val environmentLoader = rememberEnvironmentLoader(engine)
    val environment =
        rememberEnvironment(engine) {
            environmentLoader.createHDREnvironment(
                assetFileLocation = "environment/cube_environment.hdr",
            )!!
        }
    val modelNode =
        rememberNode {
            ModelNode(
                modelInstance = modelLoader.createModelInstance("model/cube.glb"),
                scaleToUnits = 1.0f,
            )
        }

    LaunchedEffect(Unit) {
        cameraNode.setProjection(fovInDegrees = 25.0)
    }

    Scene(
        modifier = modifier.background(color = Color.transparent()),
        engine = engine,
        modelLoader = modelLoader,
        cameraNode = cameraNode,
        environmentLoader = environmentLoader,
        onViewCreated = {
            this.setZOrderOnTop(true)
        },
        childNodes = listOf(centerNode, modelNode),
        environment = environment,
    )
}

Thanks.

kukabi commented 7 months ago

Turned out the actual environment HDR file was 2K, I converted it to 1K, and the device displayed it correctly.

I have no idea why it worked, would be happy if someone explained it.