# Buffer geometry and normal map not working

**URL:** <https://discourse.threejs.org/t/buffer-geometry-and-normal-map-not-working/35094>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [February 20, 2022, 6:24pm UTC](https://discourse.threejs.org/t/buffer-geometry-and-normal-map-not-working/35094 "2022-02-20T18:24:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![girole](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@girole](https://discourse.threejs.org/u/girole)\
**Post date:** [February 20, 2022, 6:24pm UTC](https://discourse.threejs.org/t/buffer-geometry-and-normal-map-not-working/35094/1 "2022-02-20T18:24:47Z")

</div>

Hi,

When adding my normal map to a plane geometry, it appears fine, but from a BufferGeometry, nothing is shown:

```javascript
  {
                        var spotLight = new DirectionalLight(0xffaaaa, 3);
                        spotLight.position.set(-18, 50, 78);
                        spotLight.lookAt(-9, 75);
                        spotLight.castShadow = true;
                        scene.add(spotLight);

                        const geometry = new PlaneGeometry(10, 10);
                        const material = //material variable
                        const cube = new Mesh(geometry, material);
                        cube.position.set(-67, 1, 130)
                        scene.add(cube);
                        }
                        {

                                const geometry = new BufferGeometry();
           
                                const vertices = new Float32Array([
                                        -1.0, -1.0, 1.0,
                                        1.0, -1.0, 1.0,
                                        1.0, 1.0, 1.0,

                                        1.0, 1.0, 1.0,
                                        -1.0, 1.0, 1.0,
                                        -1.0, -1.0, 1.0
                                ]);

                         
                                geometry.setAttribute('position', new BufferAttribute(vertices, 3));
                                const material = //material variable

                                geometry.computeVertexNormals();
                            
                                const mesh = new Mesh(geometry, material);
                                mesh.position.set(-87, 1, 130)
                                scene.add(mesh);
                        }

```

why the first version works fine and has the NM, but the second one not?

thanks

---

<div class="post-metadata">

**Author:** ![avseoul](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/avseoul/32/3243_2.png) [@avseoul](https://discourse.threejs.org/u/avseoul)\
**Post date:** [February 20, 2022, 6:28pm UTC](https://discourse.threejs.org/t/buffer-geometry-and-normal-map-not-working/35094/2 "2022-02-20T18:28:53Z")

</div>

I think you need tangent for normal mapping. Try geometry.computeTangent() [three.js docs](https://threejs.org/docs/#api/en/core/BufferGeometry.computeTangents).

> The computation is only supported for indexed geometries and if position, normal, and uv attributes are defined.

So you would need to provide uv (and possibly indices too?) as well before run computeTangent

---

<div class="post-metadata">

**Author:** ![girole](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@girole](https://discourse.threejs.org/u/girole)\
**Post date:** [February 20, 2022, 8:53pm UTC](https://discourse.threejs.org/t/buffer-geometry-and-normal-map-not-working/35094/3 "2022-02-20T20:53:21Z")

</div>

Thank you,

So, I have that code:

```javascript
let uvs = new Float32Array(raw_data.length)

for (let x = 0, xs = r; x < xs; x += 6) {
       uvs[x] = 0.0; 
       uvs[x + 1] = 1.0;
       uvs[x + 2] = 1.0;
       uvs[x + 3] = 1.0;
       uvs[x + 4] = 1.0;
       uvs[x + 5] = 0.0;
 }

console.log(raw_data.length)
geometry = new BufferGeometry();
geometry.setAttribute('position', new BufferAttribute(raw_data, 3));
geometry.setAttribute('uv', new BufferAttribute(uvs, 2))

```

 ![issue_texture](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/3/c/3cf9cbc07349780367de8febb575fdf6256c1e7b.jpeg)

Now, I have my texture on MOST of the triangles

of the plane BUT it is perfect nonsense.

The problem is the above mapping will cause each triangle to have difference texture orientation.  
On top of the picture you can even see that no texture is applied… wow…

My goal is to have my texture nicely laid on the surface, irrespective of the triangles  
Any tips?

Thanks

**Edit:**  
To be clear: I have a script generating those triangles. Inside three.js, I don’t use the indice version, just 3 consecutive array elements shaping a triangle.

Maybe I do it all wrong… I need some lights 🙂

**Edit2:**  
Tomorrow, I will try to give three the indices to see if it helps

**Edit3**  
Ok, I need the indices to reference the uv coordinates which value is between 0 and 1. The uv map is a square and each triangle is a coordinate in that square. I think I get it right now. Seems logical now. Let’s try this tomorrow…
