Author Topic: Texture projection mapping (android glsl2)  (Read 2929 times)

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Texture projection mapping (android glsl2)
« on: August 23, 2015, 11:25:43 am »
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"

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture projection mapping (android glsl2)
« Reply #1 on: August 23, 2015, 12:26:29 pm »
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.

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Texture projection mapping (android glsl2)
« Reply #2 on: August 23, 2015, 02:19:29 pm »
Thx, i'll look into example. And will share results.

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Texture projection mapping (android glsl2)
« Reply #3 on: August 23, 2015, 06:16:47 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture projection mapping (android glsl2)
« Reply #4 on: August 23, 2015, 10:43:07 pm »
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
« Last Edit: August 23, 2015, 11:22:41 pm by EgonOlsen »

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Texture projection mapping (android glsl2)
« Reply #5 on: August 23, 2015, 10:47:00 pm »
Thx.
Still investigating and trying to implement.

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Texture projection mapping (android glsl2)
« Reply #6 on: October 05, 2015, 02:35:22 pm »
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
Code: [Select]
pseudo code
if(currentTextureCoods in decalBounds){
gl_FragColor = sample2D(recalcTexCoordsToDecalCoords(currentTextureCoods), textureUnit2)
}
else {
gl_FragColor = sample2D(currentTextureCoods, textureUnit1)
}