Color Interpolation [SOLVED]

Hi!

I’m creating a 3-D texture using an off-line tool and then saving it to disk. This texture represents an octree generated around a model, so I have to set the texture’s pixels’ content according to the information of the octree. So for example I might have a 4x4x4 texture, and only pixels (0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0) and (0, 0, 1), (1, 0, 1), (0, 1, 1), (1, 1, 1) might have color, while the rest of the texture will be empty.

The thing is that later on I pass this 3-D texture to a fragment shader, and scale the fragment position so that it falls within the 8 pixels mentioned above, and read the color at the given texture coordinates. I need to be able to use the alpha channel to determine what to do next in the shader. Something like this:

float3 texCoord = float3(l_fragmentPos.x, l_fragmentPos.y, l_fragmentPos.z);

float4 color = tex3D(k_3dTexture, texCoord);
	
if (color.a > 0.9f) {
	o_color = float4(1, 1, 1, 1);
}
else {
	o_color = float4(0, 0, 0, 0);
}

The problem is that the color gets interpolated, so with the above code my model will get partially painted white, althought the alpha I’ve set up in the 8 pixels above is 1.0.

What can I do to get the exact color of my pixel without it getting interpolated? Sorry if my question doesn’t make sense…

Thanks!

Turn off filtering. Use:

tex.setMagfilter(Texture.FTNearest)
tex.setMinfilter(Texture.FTNearest)

David

Thanks David! That worked perfectly!