Texture projection mapping (android glsl2)

Started by anne_domini, August 23, 2015, 11:25:43 AM

Previous topic - Next topic

anne_domini

I have some textured object and image. I need to project this image on object.
Also i have
"rayStart" - vector3, the point i'm looking from.
"rayEnd" - vector3, the point i'm looking at.
"rayUp" - vector3, which defines rotation of image

And i cant figure out how to write vert and frag shaders, and looking for help to get this working. I was trynig make some use of tutorial from ozone3d.net, but stuck at the very beginning with "TexGenMatrix"

EgonOlsen

Projective texture mapping is a part of shadow mapping, because in shadow mapping, you project the depth map onto the scene. In projective texturing, you simply project a "real" texture instead of a depth map, so it's actually a little easier. That said, there's this shadow mapping example here: http://www.jpct.net/forum2/index.php/topic,4333.msg30172.html#msg30172. It contains shader and Java code for doing basic shadow mapping and that includes the projective part. You "just" have to strip the shadow related parts out of it and you should end up with basic projective texture mapping.

anne_domini

Thx, i'll look into example. And will share results.

anne_domini

Well, i've managed to project my texture to plane, like in example (actual.png).
As i understand example, we render to texture needed objects from point of light and blend this shadow texture with our "receiver object"

Now i'm stuck how to get projection like in "needed.png" where i need to project given image to another object to given point.
I was speaking of "rayStart" - now i'm understand it's the position where "image source" located (like a light source in shadow example)
"rayEnd" - position of center of our resulting projection, "rayUp" - defines rotation.

To be more clear, i want to get the result like on this image https://worldoftanks.ru/dcont/fb/image/wot_object_268_1024x600_noc_ru.jpg
I have a model of tank, and the red star is projected like a decal to the texture. And position of this decal is defined by 3 vectors mentioned above.

EgonOlsen

#4
I don't think that projective texture mapping is a good solution to this problem. You'll end up with all kinds of problems (like projections on polygons behind the actual target polygon) and it's difficult to do this for more then one decal on one object.
For this case, i would rather


  • use different textures for different decals
  • or use an additional texture layer, at least for the polygons that should receive the decal, assign your decal texture and blend it with the base texture

anne_domini

Thx.
Still investigating and trying to implement.

anne_domini

Managed to get it work. But without texture projecting.
1. Calc polygon intersection point with my ray.
2. recalc 3d coords into UV
3. Determining "up direction"
These calculations are done with python, as preprocessing, and stored in the db (u, v and roation)
Next just simple shader like

pseudo code
if(currentTextureCoods in decalBounds){
gl_FragColor = sample2D(recalcTexCoordsToDecalCoords(currentTextureCoods), textureUnit2)
}
else {
gl_FragColor = sample2D(currentTextureCoods, textureUnit1)
}