I was having some problems porting a shader from the HLSL/DirectX side of things to OpenGL ES. Since the effect was a full screen effect, I was focussed on problems with the inverted y coordinate in screen space. (UNITY_UV_STARTS_AT_TOP)
It seems however that the real issue was in the fact that the clip instruction can’t be vectorized on OpenGL ES. This might also be the case for OpenGL, but I’m not sure yet.
What I’m doing is essentially to display a scaled version of a RenderTexture in a full screen pass. Where the uv coordinates go below 0 or above 1 I clip the output. Which works fine like this on DirectX:
float2 uv = constructYourUV();
clip(uv);
clip(1.0 - uv);
return tex2D(map, uv);
On OpenGL ES this code only clips in the X direction, because clip is not vectorized. There are no compiler warnings about implicit reductions in vector width. This code works fine on OpenGL ES:
float2 uv = constructYourUV();
clip(uv.x);
clip(uv.y);
clip(1.0 - uv.x);
clip(1.0 - uv.y);
return tex2D(map, uv);
Is this a known limitation of the OpenGL variation of the clip instruction? I’m using #pragma glsl by the way.
Edit: It seems GLSL has a non-conditional discard instruction, so this HLSL code:
clip(x);
Is probably converted into this GLSL:
if (x < 0.0) discard;
Which indeed is not vectorized.