Jump to content


Projecting texture model (spraypainting simulator)


1 reply to this topic

#1 Martoon

    New Member

  • Members
  • Pip
  • 1 posts

Posted 25 August 2005 - 12:17 PM

I'm starting on a spraypainting simulator for our Ogre-based VR simulation framework. The heart of this simulation needs to take a spray pattern texture (a fuzzy-edged circle) and project it from the spray gun onto the model being painted. I'm looking for some thoughts and pointers on the best way to go about doing this. I'd like to leverage any freely available code, etc. I'm guessing this is probably similar to realtime lightmapping (which I've never done).

My initial, naive guess would be to do something like this (bad pseudocode to follow):

The model to be painted has been uv mapped in an external application. The particular uv mapping doesn't matter, as long as each triangle is mapped seperately, and the triangles are not badly distorted in the uv map. When the model is initially loaded into the simulator, an "unpainted" texture is set for its material.

Each time the painting sim is updated, we do the following:

Using the position and orientation of the paint gun, we generate a projection transform matrix (in the local space of the model to be painted) that transforms points from the paint spray frustum to a unit cube. This lets us take the xyz of any vertex in the model, and get the corresponding uv in the paint pattern texture. This gives us a function like this:

uv PaintTransform(Vertex3 modelVert)

We then process the triangles in the model one at a time. For each model triangle, we create a new, corresponding triangle. This new triangle will be rendered on to the model's texture. Each vertex of this new triangle is defined as follows:

newTriVert[i].vert.x = modelTriVert[i].uv.u
newTriVert[i].vert.y = modelTriVert[i].uv.v
newTriVert[i].vert.z = 0

newTriVert[i].uv = PaintTransform(modelTriVert[i].vert)

We then render this new triangle on to the model’s texture, using our paint pattern texture.

The dot product of the model triangle's normal with the vector to the paint gun could be used to set blending properties, since paint applies differently flat-on than it does at a glancing angle (and of course a negative dot product would exclude the triangle from painting).

This technique seems like it would work, except for the glaring problem of occlusion shadowing. Triangles closer to the paint gun won't block paint from reaching triangles behind them. This one issue seems to make the whole problem significantly more complicated. I keep thinking there must be some z-buffer trick to handle this, but I haven't figured one out yet. This will be running on machines with recent gaming cards (GeForce 6 series), so if there are any buffer or shader tricks, they would most likely apply.

Any tips, ideas, or pointers to other resources greatly appreciated.

#2 SimmerD

    New Member

  • Members
  • Pip
  • 5 posts

Posted 27 August 2005 - 02:51 PM

Martoon said:

I'm starting on a spraypainting simulator for our Ogre-based VR simulation framework. The heart of this simulation needs to take a spray pattern texture (a fuzzy-edged circle) and project it from the spray gun onto the model being painted. I'm looking for some thoughts and pointers on the best way to go about doing this. I'd like to leverage any freely available code, etc. I'm guessing this is probably similar to realtime lightmapping (which I've never done).

My initial, naive guess would be to do something like this (bad pseudocode to follow):

The model to be painted has been uv mapped in an external application. The particular uv mapping doesn't matter, as long as each triangle is mapped seperately, and the triangles are not badly distorted in the uv map. When the model is initially loaded into the simulator, an "unpainted" texture is set for its material.

Each time the painting sim is updated, we do the following:

Using the position and orientation of the paint gun, we generate a projection transform matrix (in the local space of the model to be painted) that transforms points from the paint spray frustum to a unit cube. This lets us take the xyz of any vertex in the model, and get the corresponding uv in the paint pattern texture. This gives us a function like this:

uv PaintTransform(Vertex3 modelVert)

We then process the triangles in the model one at a time. For each model triangle, we create a new, corresponding triangle. This new triangle will be rendered on to the model's texture. Each vertex of this new triangle is defined as follows:

newTriVert[i].vert.x = modelTriVert[i].uv.u
newTriVert[i].vert.y = modelTriVert[i].uv.v
newTriVert[i].vert.z = 0

newTriVert[i].uv = PaintTransform(modelTriVert[i].vert)

We then render this new triangle on to the model’s texture, using our paint pattern texture.

The dot product of the model triangle's normal with the vector to the paint gun could be used to set blending properties, since paint applies differently flat-on than it does at a glancing angle (and of course a negative dot product would exclude the triangle from painting).

This technique seems like it would work, except for the glaring problem of occlusion shadowing. Triangles closer to the paint gun won't block paint from reaching triangles behind them. This one issue seems to make the whole problem significantly more complicated. I keep thinking there must be some z-buffer trick to handle this, but I haven't figured one out yet. This will be running on machines with recent gaming cards (GeForce 6 series), so if there are any buffer or shader tricks, they would most likely apply.

Any tips, ideas, or pointers to other resources greatly appreciated.

View Post


I did some research in this area a while ago. There are a couple of issues that come up. For the occlusion issue, simply use shadow mapping. Obviously you don't use the uvs for the shadow map check, but the world space xyz mapped into paint gun view space.

The other issue to keep in mind is chart seams. You may have filtering problems unless you are careful to render textured lines around chart seams in order to grab neighboring texels in world space that are disjoint in texture space. A hack is to use a dilation filter on the paint reception texture instead after each paint application. This would be way simpler to do, and for spraypaint would probably look fine.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users