tex2Dlod giving different values in Linear and Gamma space?

I have a very simple shader that uses a texture that is written to from script to change the y value of vertices, simple displacement thing. All works great but when I change to Linear mode the whole mesh moves down a bit. The problem is the tex2dlod seems to give a different value in Linear mode than in Gamma mode. In the line below

v.vertex.y += (tex2Dlod(_HeightTex, float4(uv, 0, 0)).x - 0.5f) * _Length;

I have to change the -0.5f value to get the mesh to be at the right height, is there something I need to do so I can use the tex2Dlod value without any changes when I change between Linear and Gamma?

That actually goes for all tex functions. You should set the texture to bypass sRGB sampling in advanced mode. Or from the script using this constructor with the last value set to true:

public Texture2D(int width, int height, TextureFormat format, bool mipmap, bool linear);
1 Like

Brilliant, thanks for that, the sorted it out nicely.