<p>We had some related questions lately, so you might find them useful:</p>
<ul>
<li><a href="https://computergraphics.stackexchange.com/questions/10081/paint-pixels-on-the-image-around-the-cursor-for-painting-application">Paint pixels on the image around the cursor for painting application</a></li>
<li><a href="https://computergraphics.stackexchange.com/questions/10034/how-are-textures-projected-onto-3d-models-in-texture-painting-applications">How are textures projected onto 3d models in texture painting applications</a></li>
<li><a href="https://computergraphics.stackexchange.com/questions/10078/get-normalized-device-coordinate-of-an-image-pixel">Get normalized device coordinate of an image pixel</a></li>
</ul>
<p>I can't tell you how the named applications do it, since I don't have access to the code, but painting onto a 3d model could be achieved as follows:</p>
<p>When you click the &quot;paint&quot; button, you cast a ray from the camera position into your 3d scene. For perspective projections, the direction depends on the mouse's screen position. You can look into my answer to <a href="https://computergraphics.stackexchange.com/questions/9954/how-to-unproject-cursor-with-orthographic-projection">this question</a> to get an idea of how this is done.</p>
<p>Now perform a collision check of the ray and your model to find the affected triangle/triangles and vertices. Calculate the <a href="https://en.wikipedia.org/wiki/Barycentric_coordinate_system" rel="nofollow noreferrer">Barycentric coordinates</a> where the ray hits the affected triangle. Use them to interpolate the texture coordinates of the intersection point. From the model data, you should know, which texture is used at the target location.</p>
<p>Now you know where you want to paint in your models' texture. How to proceed depends on what you want to paint. In case you just want to paint a pixel, you have to overwrite the texture's pixel at this location. You can do this either on the CPU or on the GPU using the rendering pipeline.</p>
<p>If you don't understand some things I mentioned yet, read the links I provided and continue <a href="https://learnopengl.com/" rel="nofollow noreferrer">learning OpenGL</a>. Things will get clearer as soon as you know the rendering pipeline and get used to working with textures. If something is still not clear after that, feel free to ask.</p>

CC BY-SA 4.0
2020-08-10T13:57:42.567Z
Thanks, this helped a lot and yes i'm going through [learnopengl](https://learnopengl.com/).
Abdelbaki Boukerche
CC BY-SA 4.0
2020-08-10T12:54:50.930Z
2020-08-10T12:54:50.930Z
wychmaster
<p>I am new to graphics programming and i'm learning opengl. I managed to make a really simple renderer where i can import models display theirs textures with all lighting. My goal is to make a simple painting software like <strong>Substance painter</strong> or <strong>Mari</strong> but much much simpler and i don't have any idea on how they work ? I googled but couldn't find a good answer.</p>
<p>Thanks.</p>

<opengl><texture><3dtexture>
How 3D painting software works
Abdelbaki Boukerche
# How 3D painting software works

(Asked by: username_0 on 2020-08-10)

I am new to graphics programming and i'm learning opengl. I managed to make a really simple renderer where i can import models display theirs textures with all lighting. My goal is to make a simple painting software like **Substance painter** or **Mari** but much much simpler and i don't have any idea on how they work ? I googled but couldn't find a good answer.

Thanks.

**Tags:** opengl, texture, 3dtexture


---

## 1 answers

### Answer by username_1 on 2020-08-10. Score: 3 | Accepted answer

We had some related questions lately, so you might find them useful:

* [Paint pixels on the image around the cursor for painting application](https://computergraphics.stackexchange.com/questions/10081/paint-pixels-on-the-image-around-the-cursor-for-painting-application)
* [How are textures projected onto 3d models in texture painting applications](https://computergraphics.stackexchange.com/questions/10034/how-are-textures-projected-onto-3d-models-in-texture-painting-applications)
* [Get normalized device coordinate of an image pixel](https://computergraphics.stackexchange.com/questions/10078/get-normalized-device-coordinate-of-an-image-pixel)

I can't tell you how the named applications do it, since I don't have access to the code, but painting onto a 3d model could be achieved as follows:

When you click the "paint" button, you cast a ray from the camera position into your 3d scene. For perspective projections, the direction depends on the mouse's screen position. You can look into my answer to [this question](https://computergraphics.stackexchange.com/questions/9954/how-to-unproject-cursor-with-orthographic-projection) to get an idea of how this is done.

Now perform a collision check of the ray and your model to find the affected triangle/triangles and vertices. Calculate the [Barycentric coordinates](https://en.wikipedia.org/wiki/Barycentric_coordinate_system) where the ray hits the affected triangle. Use them to interpolate the texture coordinates of the intersection point. From the model data, you should know, which texture is used at the target location.

Now you know where you want to paint in your models' texture. How to proceed depends on what you want to paint. In case you just want to paint a pixel, you have to overwrite the texture's pixel at this location. You can do this either on the CPU or on the GPU using the rendering pipeline.

If you don't understand some things I mentioned yet, read the links I provided and continue [learning OpenGL](https://learnopengl.com/). Things will get clearer as soon as you know the rendering pipeline and get used to working with textures. If something is still not clear after that, feel free to ask.

> **Comments:**
> **username_0**: Thanks, this helped a lot and yes i'm going through [learnopengl](https://learnopengl.com/).  

---

