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);
}
}
Reposting, hopefully easier to understand....get texcoord of passed position
Started by danromeo, Mar 05 2012 01:20 PM
1 reply to this topic
#1 Members - Reputation: 150
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.
Sponsor:
#2 Members - Reputation: 789
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!
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!
Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)






