# .lightmap second set of uv coordinates

**URL:** <https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189>\
**Category:** Questions\
**Tags:** uv-mapping, textures, materials\
**Created:** [November 30, 2018, 7:56am UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189 "2018-11-30T07:56:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_w\_starovoitenko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/_w_starovoitenko/32/3431_2.png) [@\_w\_starovoitenko](https://discourse.threejs.org/u/_w_starovoitenko)\
**Post date:** [November 30, 2018, 7:56am UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/1 "2018-11-30T07:56:58Z")

</div>

Hello!  
I really need the help of responsive people. Help create a second set of uv coordinates for lightmap.

There is a 3d car model (\* .fbx), stands on a plane (PlaneBufferGeometry), which has a texture (TARMAC2.jpg). It is necessary to place the shadow of the car (shadow.jpg) and the light from the headlights (light.jpg) on ​​the PlaneBufferGeometry object.

Lighting does not give realistic shadows under the car. Rendered the shadow separately in Blender. How to put a shadow under the car, the texture of the light from the headlights and glare on the headlights as in this example: [https://renaultespace.littleworkshop.fr/](https://renaultespace.littleworkshop.fr/)? Thanks for any info !!! in threejs newbie.

Here is how it is loaded now using lightmap. Problem: the lm-texture with a shadow stretches across the surface. I can not imagine how to create a second set of uv coordinates for lightmap.

```
var groundGeo = new THREE.PlaneBufferGeometry( 10000, 10000 );
var groundMat = new THREE.TextureLoader().load("model/TARMAC2.jpg", function ( map ) {
map.wrapS = THREE.RepeatWrapping;
map.wrapT = THREE.RepeatWrapping;
map.anisotropy = 10;
map.repeat.set( 10, 10 );
groundTexture = map;
} );
var lm = new THREE.TextureLoader().load("model/shadow_copy514.jpg");
var groundMaterial = new THREE.MeshBasicMaterial(
                {
color: 0xdad8d5,
lightMap: lm,
map: groundMat
});
var uvs = groundGeo.attributes.uv.array;
console.log(uvs);
groundGeo.addAttribute( 'uv2', new THREE.BufferAttribute( uvs, 2 ) );
var ground = new THREE.Mesh(groundGeo, groundMaterial);
ground.rotation.x = - Math.PI / 2;
ground.position.y = -3;
scene.add( ground );

```

![final](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/d/d17734f8ad88bcf2e329381c2ef870ec94ec6286.jpeg)  
 ![now](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/b/b44ab36bf633ad743a86d263518c2c1fa7bf09bc.jpeg)

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [November 30, 2018, 10:03am UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/2 "2018-11-30T10:03:27Z")

</div>

How about doing this:

```auto
var uvs = [0, 1, 1, 1, 0, 0, 1, 0];
groundGeo.addAttribute( 'uv2', new Float32BufferAttribute( uvs, 2 ) );

```

The light map should cover the entire ground with this uv coordinates.

---

<div class="post-metadata">

**Author:** ![\_w\_starovoitenko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/_w_starovoitenko/32/3431_2.png) [@\_w\_starovoitenko](https://discourse.threejs.org/u/_w_starovoitenko)\
**Post date:** [November 30, 2018, 12:59pm UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/3 "2018-11-30T12:59:45Z")

</div>

thanks for the answer))

nothing has changed ((((.  
“The light map should cover the entire ground with this uv coordinates.” - what does it mean? if you create lightmap (shadow\_copy514.jpg) = 10000х10000px, the file is very heavy. I don’t need a lightmap to cover the whole earth. The lightmap should only be under the car (in the center of PlaneBufferGeometry).  
if I use THREE.ShaderMaterial () - I get the same result (lightmap = ground)

![prim](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/2/22612bfaf32ccbad7a00c184a0447b26eed7edd0.jpeg)

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [November 30, 2018, 1:50pm UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/4 "2018-11-30T13:50:47Z")

</div>

Ah, now I see. Um, that makes it hard to generate the texture coordinates on the fly.

@donmccurdy Any chances @_w_starovoitenko creates its ground in Blender and the export the model as `glTF`? Are light maps and a second set of uv coordinates supported?

---

<div class="post-metadata">

**Author:** ![\_w\_starovoitenko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/_w_starovoitenko/32/3431_2.png) [@\_w\_starovoitenko](https://discourse.threejs.org/u/_w_starovoitenko)\
**Post date:** [November 30, 2018, 2:08pm UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/5 "2018-11-30T14:08:54Z")

</div>

```
//model
var loader = new THREE.FBXLoader();

loader.load('model/bmw_opt.fbx',
function (fbx){
 bmw = fbx;
 fbx.add( light );
fbx.add( lightHolder );

 fbx.traverse( function ( child ) {
        if ( child.isMesh ) {
          child.castShadow = true;
          child.receiveShadow = true;
          child.material.envMap = envMap;
          child.material.envMapPol = envMapPol;
          if(child.name == "body")
    {
      fbxParts.body = child;
    }
     if(child.name == "glass")
{
 fbxParts.glass = child;
 child.receiveShadow = false;
```

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [November 30, 2018, 6:02pm UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/6 "2018-11-30T18:02:17Z")

</div>

Is a lightmap the right way to represent a single shadow like this? If your lighting and car position are fixed, why not bake it into the ground texture or use a [decal](https://threejs.org/examples/?q=decal#webgl_decals)? If the lighting and car position are _not_ fixed, I’m not sure how you will use the second set of UVs here.

Note that in the link above, they use an ambient occlusion map for the shadow beneath the car. But I suppose the issues would be the same.

Exporting to glTF will let you create a second set of UVs and include them in the model. You can also attach an AO map. But glTF does not include light maps so you’d need to load that separately with TextureLoader. For how to set up the material, see [https://github.com/KhronosGroup/glTF-Blender-Exporter/blob/master/docs/user.md](https://github.com/KhronosGroup/glTF-Blender-Exporter/blob/master/docs/user.md).

---

<div class="post-metadata">

**Author:** ![\_w\_starovoitenko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/_w_starovoitenko/32/3431_2.png) [@\_w\_starovoitenko](https://discourse.threejs.org/u/_w_starovoitenko)\
**Post date:** [December 3, 2018, 12:00pm UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/7 "2018-12-03T12:00:46Z")

</div>

The lighting and position of the car are fixed.  
The texture of the earth is shifted along the Y axis (groundTexture.offset.y - = speed / 2;).

I will try to deal with the decal example (it is not yet possible to achieve the desired result).

Maybe I can understand glTF, thanks

---

<div class="post-metadata">

**Author:** ![FrankSilvaHM](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/franksilvahm/32/117_2.png) [@FrankSilvaHM](https://discourse.threejs.org/u/FrankSilvaHM)\
**Post date:** [December 4, 2018, 3:11am UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/8 "2018-12-04T03:11:23Z")

</div>

Whoa, hold on a sec… Don, how many UVs total does glTF support? I never even thought of glTF having more than one UV. Even if it is just two, that is **double** what I thought…

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [December 4, 2018, 3:24am UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/9 "2018-12-04T03:24:44Z")

</div>

The glTF format supports any number of UVs, but at the moment three.js only supports two. Lightmap and AO use the second UV set in three.js, other textures use the first UV set.

---

<div class="post-metadata">

**Author:** ![\_w\_starovoitenko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/_w_starovoitenko/32/3431_2.png) [@\_w\_starovoitenko](https://discourse.threejs.org/u/_w_starovoitenko)\
**Post date:** [December 5, 2018, 7:53am UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/10 "2018-12-05T07:53:06Z")

</div>

donmccurdy - professional!!!

thanks to all!!!  
problem solved)  
all as in the example [https://github.com/mrdoob/three.js/blob/master/examples/webgl\_materials\_cars.html](https://github.com/mrdoob/three.js/blob/master/examples/webgl_materials_cars.html)

This example did not work for me correctly. Solution: reducing the size of the land from 100,000 to 10,000)))))

New question:  
Maybe someone knows how to implement the headlights?  
[https://partner.viscircle.com/VWPolo/](https://partner.viscircle.com/VWPolo/)  
The headlights of the car - this texture changes on the object or the texture is loaded separately … ![light](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/6/65d1fd163d005f37bec8a6bd3e80da35b4d34246.jpeg)

Maybe PointLight

---

<div class="post-metadata">

**Author:** ![Atul\_Mourya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/atul_mourya/32/1155_2.png) [@Atul\_Mourya](https://discourse.threejs.org/u/Atul_Mourya)\
**Post date:** [December 5, 2018, 9:30am UTC](https://discourse.threejs.org/t/lightmap-second-set-of-uv-coordinates/5189/11 "2018-12-05T09:30:13Z")

</div>

1. Bake emissiveMap for all the enlightened parts of the head lamp
2. Get a proper Sprite image for the flare
3. Turn off depthWrite property of Transparent glass of headlight
4. Apply the emissiveMap that was baked earlier to all the corresponding head lamp parts
5. Position the sprite object inside the head lamp container
6. Write a script to reduce the scale of the sprite and emissiveIntensity of component to which emissiveMap has been applied, so that, if camera view is from the front (i.e near ), the scale and intensity to be maximum and to be minimum if the camera view is from left, right or back ( i.e far ).

For switching on and off, simply hide the sprite object and set the emissiveIntensities to zero and vice-versa
