Jump to content
  • Advertisement
Sign in to follow this  
circassia

texture lookup - 1 pixel

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

Hi guys,

i would like to make a texture-lookup (i have once posted this issue, but there it was very general)

Now, i want to save the pixel color value of a texture in a float variable.

how can i access it, when i have the texcoord and the texture?


float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 Color = 0;
float4 onePix;
onePix= tex2d(input, uv.xy); //there i get the whole texture, i just want to save one pixels value

Color += memory*0.5;

return Color;
}


Would be cool if someone could tell me how to do it, thank you!

Share this post


Link to post
Share on other sites
Advertisement
Tex2D returns a vector representing the filtered texel color values from the given texture at the given UV coordinate.

If your UV coordinate is a constant, then the function will always return the texel from the same coordinate. For example:


float4 colorInMiddle = tex2d(texture, float2(0.5f,0.5f)); // always returns the color in the middle of the texture


As of now, you get the "uv" parameter from the vertex attribute interpolator, and it is commonly not a constant value.

Share this post


Link to post
Share on other sites



float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 Color = 0;
float4 onePix;
onePix= tex2d(input, uv.xy); //there i get the whole texture, i just want to save one pixels value

Color += memory*0.5;

return Color;
}


Would be cool if someone could tell me how to do it, thank you!


In the shader you showed, you get only one pixel, not the whole texture.

If you want always get the same value from the texture you can specify constant value for the texture lookup : onePix= tex2d(input, float2(0.0f,0.0f)); // change the float2(x,y) to present the desired location, where both values are in the range of [0...1]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!