View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Reposting, hopefully easier to understand....get texcoord of passed position

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1danromeo  Members

Posted 05 March 2012 - 01:20 PM

I'm working from the following code, which draws an image in the middle of my skydome. How can I draw the image centered on a Vector3 position passed from the program? I.E., the code maps the image to texcoords, but I want to center the image on Vector3. Is there a way to either project the texcoords into a Vector3 position OR project the Vector3 position into texcoords? Hope this makes sense. Thanks.

if (PSIn.TexCoords.x > 0.49f && PSIn.TexCoords.x < 0.51f)
{
if (PSIn.TexCoords.y > 0.49f && PSIn.TexCoords.y < 0.51f)
{
float leftSpan = 0.51f - 0.49f;
float rightSpan = 0.51f - 0.49f;

float XvalueScaled = (PSIn.TexCoords.x - 0.49f) / leftSpan;
float YvalueScaled = (PSIn.TexCoords.y - 0.49f) / leftSpan;

float2 MoonCoords = float2(XvalueScaled, YvalueScaled);

Output.Color = tex2D(MoonSampler, MoonCoords);
}
}

### #2Tsus  Members

Posted 05 March 2012 - 03:01 PM

Hi!

What you like to achieve is easier done, if you render a viewport-aligned quad (aka billboard) at the position of the moon and put the moon texture on it. It will be faster, too, since you render less geometry (only a single quad) and you only invoke pixel shaders, where you need them.

But, to answer your question you could use the texcoord you already have got and just adapt the interval in which you display the texture [0.49, 0.51] --> [x-0.01, x+0.01]. x is a texture coordinate being passed in. You can compute x from a world position by mapping the (worldPos-viewerPos) from Cartesian to Spherical coordinates, see here (This article has the z-axis upward. You probably have the y-axis upward, so you’d have to substitute y and z. Also better you atan2 instead of atan.)

Hope that helps!
Cheers!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.