Adding a light to Sceneform node has no effect
Asked Answered
B

1

8

I'm following the google developers guide on adding Light to a Node in SceneView:

https://developers.google.com/sceneform/develop/build-scene

Light spotLightYellow =
    Light.builder(this, Light.Type.FOCUSED_SPOTLIGHT)
        .setColor(new Color(android.graphics.Color.YELLOW))
        .setShadowCastingEnabled(true)
        .build();

However it doesn't seem to do anything to my rendered model.

Is there anything else I'm missing?

 ModelRenderable.builder()
                .setSource(
                        this,
                        Uri.parse(card)
                )
                .build()
                .thenAccept(
                        modelRenderable -> {

                            node.setParent(scene);
                            node.setLocalPosition(vector3);
                            node.setLocalScale(new Vector3(1.4f, 1.4f, 1.4f));
                            node.setName("Test");

                            Light light =
                                   Light.builder(Light.Type.FOCUSED_SPOTLIGHT)
                                   .setColor(new Color(android.graphics.Color.YELLOW))
                                   .setShadowCastingEnabled(true)
                                   .build();

                            node.setLight(light);

                            node.setRenderable(modelRenderable);


                        })
                .exceptionally(
                        throwable -> {
                            Toast toast =
                                    Toast.makeText(this, "Unable to load Fox renderable" + throwable, Toast.LENGTH_LONG);
                            toast.setGravity(Gravity.CENTER, 0, 0);
                            toast.show();
                            return null;
                        });
Buehrer answered 21/6, 2020 at 17:57 Comment(3)
What material are you using on your model? Materials usually are "lit" or "unlit" meaning the shader that is used to render the model uses light information when calculating the colors. If your model is using a material that does not use lighting information, adding the light will make no difference.Uric
I'm not sure if the Material is lit or unlit. In my assets folder, the .sfb file for the model doesn't have a key named lit or unlit. But what I've noticed is, the default sun node in the Scene lights up my 3D model otherwise it's dark in the Android Studio 3D viewer. I'm now trying to add an additional light node (FOCUSED_SPOTLIGHT), but that doesn't make a difference to the rendered model.Buehrer
If you haven't already, check out github.com/googlesamples/sceneform-samples. there is a lighting sample in there. It is somewhat old, but i just built and ran it OK.Uric
I
1

Lighting in Sceneform

There are four light types that Sceneform scenes support: directional light (a.k.a. sun), point light (a.k.a. light bulb), and two types of spot light (a.k.a. stage spot).

public enum class Type {
    POINT,                    
    DIRECTIONAL,              // default intensity = 420 lumen
    SPOTLIGHT,               
    FOCUSED_SPOTLIGHT         
}

When you use directional light, just its direction matters. If you use point light, just its position matters. And only spots must be not only rotated but also positioned. Note that directional light intensity is considerably lower than focused spotlight intensity.

Important

By default, SPOTLIGHT and FOCUSED_SPOTLIGHT are created at a distance of 1.0 meter (along z-axis) from AR camera, so use outer cone angle parameter and then make sure your model's positioned under light rays.

Here's a working code of scene lighting (Sceneform 1.15, ARCore 1.45):

val scene = fragment.arSceneView.scene

val light = Light
    .builder(Light.Type.FOCUSED_SPOTLIGHT)
    .setColor(Color(android.graphics.Color.BLUE))
    .setShadowCastingEnabled(true)
    .setIntensity(9000f)
    .setOuterConeAngle(0.9f)
    .build()

    val lightNode = Node()
    lightNode.light = light
    lightNode.worldPosition = Vector3(1f,0f,0f)    // 1m offset X
    lightNode.setParent(scene)
Irvin answered 27/4, 2022 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.