lowp vec4 tmpvar_4; tmpvar_4 = texture2D (

Hi,
The glsl compiled version of the shaders in unity always use a temporary in lowp precision to read a texture then is copied to the variable with the precision u defined in your shader. For example :
half4 c = tex2D( …
becomes something like this

mediump vec4 c_i0;
lowp vec4 tmpvar_4;
tmpvar_4 = texture2D (_MainTex2, …));
c_i0 = tmpvar_4;

What is the reason behind this? Is there any way to bypass this in “unitys shaderlab compiler” and read with a mediump directly from the texture fetch?
lowp is 8 bits but after filtering the hardware should be able to provide more than 8 bits precision? So if you are doing a texture lookup and not reading just a color, u might need more than 8 bits precision (like in my case reading uvs, which I know is makes to fail the texture prefetch).
Thanks

Yes, writing your shader in GLSL.

I’m not sure about that, the filtering unit might be limited to 8 bits precision if the texture has only 8 bits precision.

Thanks Martin for your answer.
I saw that even when your write the glsl version Unity creates defines to set lowp mediump highp to nothing.
powervr is internally working in floating point I dont see why they would mask the result to 8 bits as the filtering gives extra precision which could be useful to interpolate in lookups. I will do a test later in xcode to verify this. At least with other gpus I didnt have a problem with this independently of the texture format.

I see those defines only in the compiled shader code for OpenGL, not for OpenGL ES. Or am I missing something?

In the shaders; but the texture filtering is probably different hardware, I assume.

As I said: I actually don’t know. Please let us know your results. :slight_smile: