Advertisement

How to do projective Texturing and save the piece of projected image into the mesh's texture?

Started by September 26, 2018 10:41 AM
2 comments, last by _WeirdCat_ 6 years, 4 months ago

Hi,guys.

    I need to project a picture from a projector(maybe a camera) onto some meshes and save those into the mesh texture according to the mesh's unfolded UV.It  just like the light map which encode the lighting-info into the texture instead of the project-info.

    The following picture is an example(But it just project without writting into texture).I noticed blender actually has this function that allow you to draw a texture on to a mesh.But i have no idea on how to save those project pixel into the mesh's texture.

    I think maybe i can finish this function if i have a better understanding about how to produce Light map.Any advises or matertials can help me out?(any idea,any platform,or reference)>?

20161101235403215.png

I can tell you some basic stuff ..

  • you have a matrix which determines how you want to lay out your texture onto the world from B (analogous to a 'light camera' in shadow mapping). I would call it projection matrix, but that term may cause confusion so I'll just call 'matrix B'
  • This gives you the UV coord of the source texture you are splatting for each vertex of each triangle.
  • You know the uv coord of the target texture (assuming it has uv mapping)
  • Interpolate across the texels of the target texture for each triangle, you can calculate the source texture uv by interpolation.

What methods you use exactly to do this will depend on your application, whether you want it to be realtime on the GPU, or done on the CPU, whether you want nice filtering etc etc.

You might for example have the target texture as your render target, then drawing the triangle have a shader that takes the render position from the target UV, and texture maps from the source texture using the original vertex position multiplied by the matrix from B as the UV.

It is kind of similar to Projective Texture mapping, maybe you will get some good ideas from those tutorials. You are just drawing in UV space to a texture instead of via a regular camera to the screen.

Advertisement

More to say its like a vertex shader since you need 2 well maybe 3 matrices you do each vertex uv is (for opengl thingy)

You calculate screen coordinate 

Depending if uts ogl or d3d implementatiin this will differ for acreen coord byt not that much

vec3 txcrd = ((model_matrix*view_matrix)*projection_matrix ) * vertex

Then divide result by w component of the result txcrd.xy = txcrd.xy / txcrd.w;

This should give you so called ndc which is in range -1..1 now xy coord are yours texture uv simply do * 0.5 + 0.5 and youll get uv coord now you need to rwmember how you load textures so obe might flip y coord or even x (when using sdl for example)

Aint that that simple?:)

This topic is closed to new replies.

Advertisement