www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: anne_domini on August 23, 2015, 11:25:43 am

Title: Texture projection mapping (android glsl2)
Post by: anne_domini 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"
Title: Re: Texture projection mapping (android glsl2)
Post by: EgonOlsen 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 (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.
Title: Re: Texture projection mapping (android glsl2)
Post by: anne_domini on August 23, 2015, 02:19:29 pm
Thx, i'll look into example. And will share results.
Title: Re: Texture projection mapping (android glsl2)
Post by: anne_domini 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.
Title: Re: Texture projection mapping (android glsl2)
Post by: EgonOlsen 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

Title: Re: Texture projection mapping (android glsl2)
Post by: anne_domini on August 23, 2015, 10:47:00 pm
Thx.
Still investigating and trying to implement.
Title: Re: Texture projection mapping (android glsl2)
Post by: anne_domini 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)
}