Does anyone know if moving a UV coord into a local variable causes a dependent texture read ?
float2 mainUV = i.uv;
fixed4 col = tex2D ( _MainTex, mainUV );
Does anyone know if moving a UV coord into a local variable causes a dependent texture read ?
float2 mainUV = i.uv;
fixed4 col = tex2D ( _MainTex, mainUV );
I’m not an expert in this stuff - far from it, but my understanding would be in that example no - not unless you change the values in mainUV in some way. In fact, in that example above, I’d imagine that the interim step would get optimised out at compile time.
Yeah thats what I am assuming also, but I would like to know for sure
Like is the driver smart enough to know the UV was moved to a local var ?
I am doing this because sometimes I do modify the UV like…
float2 mainUV = i.uv;
#ifdef ECHO_DISTORTION_ON
change mainUV here
#endif
fixed4 col = tex2D ( _MainTex, mainUV );
I’m hoping when the keyword ECHO_DISTORTION_ON is not active there are no dependent texture reads.
UPDATE: in a small test it seems unity optimizes out the mainUV variable if nothing changes it and uses the TEXCOORD directly
The shader compiler optimizes this away. Nothing to do with Unity itself FYI.