Rendering projected textures with vertex program.

Started by
2 comments, last by Yann L 19 years ago
In my app I use a vertex program, but this excludes projected textures, which I need anyway. Partially I figured out how does this equation work, I use DP4 temp.x, fx , in_pos; DP4 temp.y, fy , in_pos; DP4 temp.w, fz , in_pos; where fx,fy,fz is the projection matrix and temp goes out to result.texcoord, but however the texture is always centered at (0,0), and I would like it to be centered at the middle of the texture (0.5,0.5). Anyone did this before? //Mr.WereWolf//
Advertisement
There's a quick chapter about projective texture mapping with range correction in a vertex shader (probably what you want) in my water article. Scroll down to "A word on projective texturing".

Anyway, the trick is to use a complete 4x4 projective matrix, and encode the (0.5, 0.5, 0) translation into it. Then, a simple sequence of 3 or 4 DP4's will create the desired effect. Don't forget to use a projective texture lookup in the fragment shader, though, otherwise the homogeneous q component will be ignored.
Quote:Original post by Yann L
There's a quick chapter about projective texture mapping with range correction in a vertex shader (probably what you want) in my water article. Scroll down to "A word on projective texturing".

Anyway, the trick is to use a complete 4x4 projective matrix, and encode the (0.5, 0.5, 0) translation into it. Then, a simple sequence of 3 or 4 DP4's will create the desired effect. Don't forget to use a projective texture lookup in the fragment shader, though, otherwise the homogeneous q component will be ignored.


Sorry if I am jumping in on this thread but I would like to clear up YannL posting for my own clarification...

So if I setup the projective matrix in a texture unit with all the necessary math done to the matrix including the translation and scaling and call that data in the VP and then I can do the 3 or 4 DP4 commands and send that data out as texcoords into the FP and use TXP to sample the shadowmap or whatever texture unit that has the incoming texture coordinates, that should be all I need to do if I am understanding you correctly? BTW will I need the ARB_fragment_program_shadow extension for this? Thanks
Quote:Original post by MARS_999
So if I setup the projective matrix in a texture unit with all the necessary math done to the matrix including the translation and scaling and call that data in the VP and then I can do the 3 or 4 DP4 commands and send that data out as texcoords into the FP and use TXP to sample the shadowmap or whatever texture unit that has the incoming texture coordinates, that should be all I need to do if I am understanding you correctly?

Exactly.

Quote:
BTW will I need the ARB_fragment_program_shadow extension for this?

No, you don't. Keep in mind, that vertex programs are independent of fragment programs. So, you can very well compute projective texture coordinates in your VP, and just have a simple TXP in your fragment program.

ARB_fragment_program_shadow adds three new texture targets, that encapsulate the depth comparison operation (which is usually defined by ARB_shadow) in a way that makes it more elegant and consistent with the programmable fragment pipeline paradigm.

This topic is closed to new replies.

Advertisement