<p>I am trying to project an image overlayed on top of a mesh in screen space back to it's uvs. The UV triangles do not always cover entire pixels so i get this. The red is showing where the texture is transparent:</p>
<p><a href="https://i.sstatic.net/2crVq1M6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2crVq1M6.png" alt="enter image description here" /></a></p>
<p><a href="https://i.sstatic.net/DdZyvXX4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DdZyvXX4.png" alt="enter image description here" /></a></p>
<p>I understand that the triangle is simply not covering enough of the pixel, but i'm not quite sure what needs to happen. I was thinking applying a filter, looking for neighbors and then averaging whatever i find that's not transparent.</p>
<p>I was also thinking of copying the neighbors of each triangle and then aligning them with the edges, if i rasterize this it feels like it would fill all the gaps and actually have the correct value (could be a vastly different part of screen space, not an average of local pixels). No idea how to handle overlaps.</p>
<p><a href="https://i.sstatic.net/UmRMgaoE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UmRMgaoE.png" alt="enter image description here" /></a></p>
<p>How can i get rid of these holes and properly cover the entire mesh with the projection?</p>

CC BY-SA 4.0
2024-05-01T10:37:19.457Z
So you have a texture. The triangles of your mesh contain UV coordinates so that you can draw the entire mesh on the texture (as in your last image). So your problem is that neighboring triangles partially share some pixels of the texture (like in your last picture: there is the rectangle representing a pixel and the two neighboring triangles whose common edge intersect this pixel). The marked rectangle seems to belong to the right triangle and should not be included in the left triangle. Do I understand the question correctly?
Thomas
CC BY-SA 4.0
2024-05-01T18:27:01.817Z
I’m not sure if I understand the comment. Yes some of the pixels are shared between two triangles. I also realized that some are shared between more. Say a fan of 12 triangles meets in one point each triangle will cover a small portion of that pixel. I want to not have these holes and want a triangle to shade a pixel if it just touches it ( I think)
Dusan Bosnjak 'pailhead'
CC BY-SA 4.0
2024-05-01T18:32:51.173Z
Im generating the texture via the projection. So it's not exactly "draw entire mesh on the texture" , i actually draw the mesh and then get the texture. But the pixels i get in that texture don't actually cover the entirety of the triangles. As seen in my sketch, the square would be missing from the solid black triangle. Filtering the texture after it's been generated would cover this but the color would be wrong if interpolated from neighbors.
Dusan Bosnjak 'pailhead'
CC BY-SA 4.0
2024-05-01T21:47:21.233Z
i got some mileage by instancing my geometry and then offsetting it by one full pixel in 8 directions.
Dusan Bosnjak 'pailhead'
<opengl><glsl><webgl><rasterizer>
Projecting a texture onto UVs with GLSL
Dusan Bosnjak 'pailhead'
# Projecting a texture onto UVs with GLSL

(Asked by: username_0 on 2024-04-30)

I am trying to project an image overlayed on top of a mesh in screen space back to it's uvs. The UV triangles do not always cover entire pixels so i get this. The red is showing where the texture is transparent:

[![enter image description here](https://i.sstatic.net/2crVq1M6.png)](https://i.sstatic.net/2crVq1M6.png)

[![enter image description here](https://i.sstatic.net/DdZyvXX4.png)](https://i.sstatic.net/DdZyvXX4.png)

I understand that the triangle is simply not covering enough of the pixel, but i'm not quite sure what needs to happen. I was thinking applying a filter, looking for neighbors and then averaging whatever i find that's not transparent.

I was also thinking of copying the neighbors of each triangle and then aligning them with the edges, if i rasterize this it feels like it would fill all the gaps and actually have the correct value (could be a vastly different part of screen space, not an average of local pixels). No idea how to handle overlaps.

[![enter image description here](https://i.sstatic.net/UmRMgaoE.png)](https://i.sstatic.net/UmRMgaoE.png)

How can i get rid of these holes and properly cover the entire mesh with the projection?

**Tags:** opengl, glsl, webgl, rasterizer

> **Comments:**
> **username_1**: So you have a texture. The triangles of your mesh contain UV coordinates so that you can draw the entire mesh on the texture (as in your last image). So your problem is that neighboring triangles partially share some pixels of the texture (like in your last picture: there is the rectangle representing a pixel and the two neighboring triangles whose common edge intersect this pixel). The marked rectangle seems to belong to the right triangle and should not be included in the left triangle. Do I understand the question correctly?  
> **username_0**: I’m not sure if I understand the comment. Yes some of the pixels are shared between two triangles. I also realized that some are shared between more. Say a fan of 12 triangles meets in one point each triangle will cover a small portion of that pixel. I want to not have these holes and want a triangle to shade a pixel if it just touches it ( I think)  
> **username_0**: Im generating the texture via the projection. So it's not exactly "draw entire mesh on the texture" , i actually draw the mesh and then get the texture. But the pixels i get in that texture don't actually cover the entirety of the triangles. As seen in my sketch, the square would be missing from the solid black triangle. Filtering the texture after it's been generated would cover this but the color would be wrong if interpolated from neighbors.  
> **username_0**: i got some mileage by instancing my geometry and then offsetting it by one full pixel in 8 directions.  

---

## 0 answers

