Unity supports single-pass stereo rendering for Android devices that support multiview. Multiview consists of the GL_OVR_multiview2 and GL_OVR_multiview_multisampled_render_to_texture OpenGL ES extensions. These extensions require shadersA program that runs on the GPU. More info
See in Glossary to use a 2D texture array that consists of two slices, one slice per eye.
To use single-pass stereo rendering with custom shaders, you may need to include additional shader code. You don’t need to include additional code if your custom shaders are:
Note: These shader changes are compatible with multi-pass stereo rendering.
If you want to use the unity_StereoEyeIndex
built-in shader variable to know which eye the GPU is rendering to, you must declare UNITY_VERTEX_OUTPUT_STEREO
in any shader stage output structs that you have. For example:
struct v2f {
float2 uv : TEXCOOR0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
To initialize the output data, use UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO()
in the vertex shaderA program that runs on each vertex of a 3D model when the model is being rendered. More info
See in Glossary function. For example:
v2f vert (appdata v)
{
v2f o;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
To initialize unity_StereoEyeIndex
in subsequent stages, add UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX()
at the beginning. For example:
fixed4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
If your shaders use other shader stages, use the UNITY_TRANSFER_VERTEX_OUTPUT_STEREO()
macro to transfer the eye index to the subsequent stages.
Tip: To calculate the final position of the object, it’s best practice to use UnityObjectToClipPos(IN.vertex)
instead of mul(UNITY_MATRIX_MVP, IN.vertex)
.
You must update post-processingA process that improves product visuals by applying filters and effects before the image appears on screen. You can use post-processing effects to simulate physical camera and film properties, for example Bloom and Depth of Field. More info post processing, postprocessing, postprocess
See in Glossary shaders to deal with the eye textures being a 2D texture array. To help with this, Unity includes the UNITY_DECLARE_SCREENSPACE_TEXTURE()
macro. To make textures work in both multi-pass and single-pass modes, wrap each textures in this macro. Also, when you sample the texture, use the UNITY_SAMPLE_SCREENSPACE_TEXTURE()
macro.
This macro requires that you call UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX()
beforehand when in single-pass mode. Unity also includes similar macros for depth textures and screen space shadow maps. You can see the full list at the bottom of HLSLSupport.cginc
.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.