Jump to content
  • Advertisement
Sign in to follow this  
danromeo

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

This topic is 2478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
}
}

Share this post


Link to post
Share on other sites
Advertisement
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! smile.png
Cheers!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!