texture lookup - 1 pixel

Started by
1 comment, last by kauna 12 years, 8 months ago
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!
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.

Niko Suni




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!


This topic is closed to new replies.

Advertisement