I’m having trouble understanding the numbers that come back from tex2Dlod() in a vertex shader.
At first I was using textures that were allocated with ARGBHalf to store vertex positions. So for example, to fetch the second pixel in the first row I did something like this:
int x = 1;
int y = 0;
float4 values = tex2Dlod(_PosTex, float4((x + 0.5) * _PosTex.x, (y+ 0.5) * _PosTex.y, 0, 0)
Everything worked perfectly fine with ARGBHalf buffers. Then I decided to try it with ARGB32 instead, and suddenly the return values of tex2Dlod() are gibberish.
Let’s say I set the RGBA values of pixel location (1,0) in the texture to rgba(8, 51, 11, 0). When I set them, I divided each 8-bit component by 255 to convert them to a number between 0 and 1 so that the numbers I actually wrote to the texture were (0.0313725, 0.2, 0.04313725, 0). When I export the texture to png and then open it with Glimpse I see:
(The shader reads the pixels starting in the bottom left, so the pixel under consideration is in the bottom left of the png image).
So far so good. The values appear as I would have expected… (8, 51, 11, 0)… the exact numbers I stored at that location.
Just to double-check, I captured a frame in RenderDoc and examined the texture there:
Here the values don’t make sense. It’s showing an rgba value of (0.00244, 0.0332, 0.00336, 0). I expected to see (8 / 255, 51 / 255, 11 / 255, 0), which would be (0.0313725, 0.2, 0.04313725, 0). When I step through the shader, It also shows the same strange rgba values of (0.00244, 0.0332, 0.00336, 0.00):
(In the above code, xx is 1, yy is 0, and ts is _PosTex_TexelSize. So it should be reading the center of pixel location (0, 1). I can’t figure out what these numbers are! I knew the numbers returned by tex2Dlod would be floats between 0 and 1, and they are, but I thought that I could turn them back into bytes simply by multiplying by 255. When I calculated what the multiplier would have to be to convert the number in the range 0…1 back to the original byte value, I realized that it doesn’t seem to be linear because there isn’t a single multiplier that could get all the numbers back to the original value.
I made sure to turn off filters on the texture:

The texture was allocated like this:
RenderTexture positionRenderTex = new RenderTexture(w, h, 0, RenderTextureFormat.ARGB32); // ARGB version
I have a few theories:
- The first theory is that there’s a strange internal “byte-to-float-between-0-and-1” conversion equation that I don’t know about.
- The second is that perhaps when using tex2Dlod() on a RGBAHalf texture, a coordinate system is used that is different from the one used in RGB32 textures - thus I’m reading the wrong pixel and those strange values are actually for a different pixel?
- Maybe tex2Dlod is not meant for ARGB32 buffers and I should be using an alternative function?
- Could there be some sort of internal filtering that’s changing the bytes that I wrote into the file?
I dunno… What am I missing here?


