PDA

View Full Version : project section of a texture



Vexator
11-04-2007, 08:50 AM
i have this texture:
http://www.desertsatori.com/vexator/spot2.jpg

i only want one of those circles to been projected on the scene.
i can offset the projection coordinates to limit it to the lower left circle:


vec2 p = vec2( proj.x*0.333, proj.y*0.5 );
Attenuation *= texture2D( texture, p/proj.w ).r;

http://www.desertsatori.com/vexator/spot.jpg

question: how do i have to offset the projection coordinates so that the other circles are projected? i guess those are not fixed values, but depend on the projector/fragment distance..

btw: i cannot post topics with firefox anymore, the forums always tell me that "the host from which you are accessing the board is not recognized as a valid host."

Humus
11-04-2007, 05:08 PM
You essentially want a scale-bias of the texture coordinates that work under projection, right? Well, you've figured out the scale already. For the bias all you have to do is multiply your bias with .w since that's what you divide with in the end.

For instance, clip-space to texture coordinates:

texCoord = clipPosition;
texCoord.xy *= 0.5;
texCoord.xy += 0.5 * texCoord.w;

The last line there offsets by 0.5.

Vexator
11-05-2007, 05:48 AM
works fine, thanks! :D