Jump to content
  • Advertisement
Sign in to follow this  
danromeo

Shader question: Get Tex Coords of onscreen object

This topic is 2475 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

shader 3.0

In my vertex shader I pass a Vector3 position transformed by View*Projection:

Output.ObjectPosition=mul(ObjectPosition, camViewProjection);


In my pixel shader, how can I get the texture coordinates of the passed Vector3 ObjectPosition??

So that I can determine if the pixel being drawn is within a distance range of ObjectPosition.

Share this post


Link to post
Share on other sites
Advertisement
Your vector3 position is part of a vertex description, which I am going to assume you also include a UV coordinate to texture your objects(which you pass to your pixel shader as an "out" parameter of your vertex shader). Could you clarify a little bit exactly what you are having an issue with?

Share this post


Link to post
Share on other sites
Thanks for your reply. I'm trying to project a moon image onto a skydome at the proper location. So the shader is drawing the dome geometry with texcoords for the dome as part of the vertex declaration, and MoonPosition is being passed to the shader from the program, not in the vertex declaration.

In the pixel shader I want to do: If texcoord is within a range of MoonPosition, draw the moon.

I'm not a wiz at this stuff, still trying to wrap my head around it.

Share this post


Link to post
Share on other sites
It sounds like you may be confusing the term "texcoord", which is a UV coordinate, with a vertex position. If this is correct, and I am understanding correctly, all you need to do to achieve what you want, is pass the vector position from the vShader into the pShader using the TEXCOORDn semantic, then simply do a distance check(using your formula of choice). root(pow(x2-x1,2) + pow(y2-y1, 2) + pow(z2-z1, 2))

Share this post


Link to post
Share on other sites
I know the diff between a UV and a vertex position.

The problem (I THINK) is mapping the texcoords for the moon image. The distance equation will tell me if the pixel being drawn is near the moon position, but how do I map the texcoords for the moon image into that space?

What if I use this for starter code, somebody elses, not mine: This puts the moon image in the middle of my skydome. How do I align the output with my MoonPosition? If I could get the texcoord that the MoonPosition vector is falling at it would be easy. THANKS for your help.

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
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!