Sign in to follow this  
circassia

texture lookup - 1 pixel

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?

[code]
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;
}
[/code]

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

Share this post


Link to post
Share on other sites
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:

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

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
[quote name='circassia' timestamp='1313749615' post='4851136']

[code]
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;
}
[/code]

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this