CUDA textur interpolation

Hello,

I need a float4 textur for RGB colors, with optioins normalize and interpolation. I have the following code:

texture<float4, 1, cudaReadModeElementType> color; 

__global__ void kernel(){

		...

		float4 farbe = tex1Dfetch(color, 0.5f);

		r = farbe.x;

		g = farbe.y;

		b = farbe.z;  

		//0.5f => result is blue (r=0.0,g=0.0,b=1.0)

		//2.0f => result is red  (r=1.0,g=0.0,b=0.0)

		//=>The textur is not normalized and not interpolated. But why?

		...

}

main(){

	float4 h_color[] = {

	{  0.0, 0.0, 1.0, 0.0, }, //blue

	{  0.0, 1.0, 0.0, 0.0, }, //green

	{  1.0, 0.0, 0.0, 0.0, }, //red

	};

	cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<float4>();

	cudaArray* d_transferFuncArray;

	cudaMallocArray( &d_transferFuncArray, &channelDesc, sizeof(h_color)/sizeof(float4), 1); 

	cudaMemcpyToArray( d_transferFuncArray, 0, 0, h_color, sizeof(h_color), cudaMemcpyHostToDevice);

	color.filterMode = cudaFilterModeLinear;

	color.normalized = true;   

	color.addressMode[0] = cudaAddressModeClamp;  

	cudaBindTextureToArray( color, d_transferFuncArray, channelDesc);

}

The texture is not normalized and the values are not interpolated. But why?

Use [font=“Courier New”]cudaReadModeNormalizedFloat[/font] for that.

Thank you!!!
I used tex1Dfetch and not tex1D and tex1Dfetch is only for integer. It work whit tex1D without problems…

Sorry, my bad. [font=“Courier New”]cudaReadModeElementType[/font] was of course correct as you are returning a float4.

I’ve tested your code and it actually works for me. I.e., 0.5f returns green (r=0.0,g=1.0,b=0.0), 1.0f returns red (r=1.0,g=0.0,b=0.0) and 0.333333f returns (r=0.0,g=0.5,b=0.5).

Thank you!!!
I used tex1Dfetch and not tex1D and tex1Dfetch is only for integer. It work whit tex1D without problems…