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;
                        });
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
  • 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. – Clayton Wilkinson Jun 29 '20 at 18:05
  • 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. – DIRTY DAVE Jul 01 '20 at 00:18
  • 1
    If you haven't already, check out https://github.com/googlesamples/sceneform-samples. there is a lighting sample in there. It is somewhat old, but i just built and ran it OK. – Clayton Wilkinson Jul 01 '20 at 20:42

1 Answers1

1

Make sure that DIRECTIONAL light's intensity is considerably lower than FOCUSED_SPOTLIGHT's intensity. A position and direction of a spotlight do matter, however a directional light is controlled by direction only (as its name suggests). If FOCUSED_SPOTLIGHT still doesn't work, try regular SPOTLIGHT.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220