tex2Dlod(_MainTex, float4((uv+.5) / 256.0, 0.0, 0.0));
Which will find the centre of the texel at the location specified by uv (in whole number pixel values).
It uses tex 2d LOD to make sure you’re getting the highest level mip map. It was added a few versions back, along with tex2Dgrad
tex2Dfetch is a Cg only thing… Unity actually does not use the Cg shader language anymore. It has ceased development and has been deprecated since 2012. It does not support SM4.0+ constructs, so for those it’s not even possible to use Cg. Instead, Unity compiles the shaders as HLSL - back in the days almost identical language to Cg. So, if you want a HLSL equivalent of tex2Dfetch, use this: Load (DirectX HLSL Texture Object) - Win32 apps | Microsoft Learn
Like so:
Shader error in ‘Custom/MyShader’: ‘’ : methods are not supported; ‘Load’ : no matching overloaded function found
It would be nice to have an answer to this, but for now, I’ve just switched texture filtering to Point and gone with this:
float4 data = tex2Dlod(_MainTex, float4(_MainTexPixelWidth * 0.5 + i * _MainTexPixelWidth, 0.5, 0.0, 0.0));
@DaveHoskins I had turned off mip-mapping for the texture I’m using since it’s basically being used as a large uniform buffer, but I suppose this is a good tip anyways, just to make sure nothing goes wrong.
What shader model are you targeting? Load works and compiles just fine on my platform, but I am targeting 5.0. You might try pushing up the profile to a higher target.