iPhoneSettings.screenOrientation and shaders

I’ve been having difficulty doing fragment shaders that deal with screen space on the iPad. Specifically, if iPhoneSettings.screenOrientation is set to anything except portrait, it seems like the screen coordinates calculated by ComputeScreenPos() are incorrect.

I’m doing something along the lines of:

v2f vert(appdata v)
{
    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    o.ref = ComputeScreenPos(o.pos);
}

half4 frag(v2f i) : COLOR
{
    half4 color = tex2Dproj( _ProjTex, UNITY_PROJ_COORD(o.ref) );
    return color;
}

Produces expected results in portrait mode, and it seems to sample from the wrong area of the texture in non-portrait orientations. If I multiply o.pos by a rotation matrix that rotates about the z-axis based on the desired screen orientation (90 degrees for landscape right, 180 degrees for upside-down portrait, etc), then the problem is fixed and the correct area of the texture is sampled from. The problem is that I can’t find an elegant way to account for screen orientation in a shader beyond attaching a script that continually checks for screen orientation and updates a Material variable for the shader to use. Is there a better way to handle different screen orientations in shaders that project into screen space?

Sorry, I thought I posted this in the ShaderLab forum…please ignore the above post.