Texture can not keep negative value?

i want to keep an negative value in the texture,but can not access that negative value in the Vertex Shader. But i found the negative value i kept turn out to be 0 in Vertex Shader. Why?
And how can i keep negative value in texture?

My texture definition is:

GLfloat edge[4][4]=

Cg code:

uniform float4x4 WorldViewProj : state.matrix.mvp;

void main_v(float4 pos:POSITION,
out float4 opos:POSITION,
out float4 color:COLOR,
uniform sampler2D tex
float a;



Why are you mismatching your image format with your pixel transfer parameters? If you want to actually store floating-point data, you have to store it. Use a floating-point image format.

What Alfonse wants to suggest is to replace GL_RGB with a floating point texture internal format. As I understand, you want a single channel floating point texture thus you should use GL_R32F or GL_R16F as an example.

Thanks a lot . The information you provided helps me a lot

It works using the way you suggest. Thanks a lot

Another question,if i use GL_LUMINANCE instead of GL_R32F,it does not work again.Why?


Because the driver may choose a different internal format in that case (e.g. GL_R8, which is again signed normalized texture format with values in range [0,1]).

Bare in mind that using constants like GL_RGB or GL_LUMINANCE when specifying the texture internal format is not a good practice in general as in such cases the driver can choose almost any kind of actual internal format (usually a limited one) that is compatible with the one you requested. You should always use a sized and typed internal format if you want to ensure that certain precision and/or value range will be available in your texture.

And you can introspect this with glGetTexLevelParameter(…GL_TEXTURE_INTERNAL_FORMAT…).

Another question,if i use GL_LUMINANCE instead of GL_R32F,it does not work again.Why?

Because you didn’t ask for a floating-point luminance format.

There’s a reason the Wiki article I linked you to did not talk about image formats that don’t have sizes. That’s because you should never use unsized formats. Ask for what you want, and you are far more likely to get it.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.