mapbox / mapbox/mapbox-gl-js

[v3] Casting light from 3D models / layer interactions

Open
#12,936 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

3d :triangular_ruler:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Before Mapbox v3 beta, I had implemented the building layer and additional models using the third party Threebox library; this enabled me to cast light from models and have it interact with surrounding buildings.

For example, in the image below you can see the white dot casting blue light onto the surrounding buildings.
image

I have since switched to v3 and have been able to import models with the recommended approaches (looks awesome - thanks!!!), but have been unable to implement any sort of lighting. I have attempted to add light sources to my .glb

glb = {
...
  "extensions": {
    "KHR_lights_punctual": {
      "lights": [
        {
          "color": [
            1,
            1,
            1
          ],
          "intensity": 1,
          "type": "point",
          "range": 100
        }
      ]
    }
  },
  "extensionsUsed": [
    "KHR_lights_punctual"
  ]
...
}

but this has no evident effect on the output model layer in Mapbox. I have also tried to add additional lights utilizing the new lights API, to no avail.

image

I'm wondering if there is any recommended way to implement point light sources that interact with other layers (building / trees) or another raycasting sort of feature that achieves the same effect? Additionally, as can be seen in the image above, I am not able to get shadows between the model layer and tree layer to behave in the expected way when dealing with a opacity gradient in my source model (the tree shadow is cut off); I have changed the model-cast-shadows and model-recieve-shadows layer attributes, but this has no effect. I have also not been able to place the model layer above the tree layer as when I set the before? parameter in addLayer to 'trees' or 'trees\u001fbasemap', I recieve an error that this layer cannot be found, even when I can successfully query for it with betaMap.style.getLayer('trees\u001fbasemap').

Thanks for your help.

@mourner @astojilj

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the v3 model-layer lighting, shadow, and addLayer ordering behavior described here, comparing the GLB KHR_lights_punctual setup with the new lights API. A useful result would document whether point lights can affect surrounding building and tree layers, whether opacity-gradient shadows are supported, and why the requested before-layer identifier is rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
computer-graphics, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.