vasturiano / globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/globe.gl/example/world-population/
MIT License
2.03k stars 301 forks source link

Day and night textures at the same time #50

Open snshn opened 3 years ago

snshn commented 3 years ago

Is your feature request related to a problem? Please describe. Based on your solar-terminator example, I'm trying to make the globe feature two textures: one of the day Earth, and one of the night.

Describe the solution you'd like Some way to pass earth-blue-marble.jpg as a texture for

            .tileMaterial(() => new THREE.MeshLambertMaterial({
                color: '#ffff00',
                opacity: 0.2,
                transparent: true,
            }))

while keeping earth-night.jpg as the primary texture of the globe.

Describe alternatives you've considered Somehow making a second set of tiles rotate on the opposite side of the planet simultaneously with the solar one.

Additional context Screenshot from 2021-06-19 09-48-00

vasturiano commented 3 years ago

@snshn that's an interesting idea, thanks for mentioning it.

It's certainly doable to load an image as the tile by setting the map property of your material to an image texture (previously loaded using TextureLoader).

What will be more challenging is to crop/translate the image to be the right frame so that it aligns perfectly with the sun position on the globe, particularly when the sun is not directly facing the equator (which really only happens on equinox).

snshn commented 3 years ago

Hi Vasco, thank you for the fast response.

Sounds tricky... not a math magician, but will try to pull it off, thank you for the hint!

Alternatively, is there any way to assign multiple textures to the globe, revealing one of them and hiding the other when it's behind the lit area? Not sure if THREE.js can do that, but if it can, I could leverage the already existing texture stretching mechanism.

Love the library... dream come true, thank you for creating it!

vasturiano commented 3 years ago

@snshn you can access and assign a new material to the globe via the method .globeMaterial. If there's a way in ThreeJS to assign multiple textures to a material (and possibly show/hide them using alphaMap), your idea may work out. 👍

snshn commented 3 years ago

Found related questions on StackOverflow:

Seems like it should be possible to accomplish using simple shader combined with custom blending. Will post my solution here once it's working.