private void SwapStereoShader() { // check if stereo material is set Renderer renderer = GetComponent <Renderer>(); Material[] materialList = renderer.materials; int i = 0; for (i = 0; i < materialList.Length; i++) { Material mt = materialList[i]; if (mt.shader.name == "Custom/StereoRenderShader") { stereoMaterial = mt; if (StereoRenderDevice.IsNotUnityNativeSupport(StereoRenderManager.Instance.hmdType)) { if (isUnlit) { renderer.materials[i].shader = Shader.Find("Custom/StereoRenderShader-SingleTexture-Unlit"); } else { renderer.materials[i].shader = Shader.Find("Custom/StereoRenderShader-SingleTexture"); } } else { if (isUnlit) { renderer.materials[i].shader = Shader.Find("Custom/StereoRenderShader-Unlit"); } } break; } } // if couldn't find stereo material, replace first material if (i == materialList.Length) { renderer.sharedMaterial = (Material)Resources.Load("StereoRenderMaterial", typeof(Material)); if (StereoRenderDevice.IsNotUnityNativeSupport(StereoRenderManager.Instance.hmdType)) { if (isUnlit) { renderer.materials[i].shader = Shader.Find("Custom/StereoRenderShader-SingleTexture-Unlit"); } else { renderer.materials[i].shader = Shader.Find("Custom/StereoRenderShader-SingleTexture"); } } stereoMaterial = renderer.materials[0]; } }
public void Render(VRRenderEventDetector detector) { // move stereo camera around based on HMD pose MoveStereoCameraBasedOnHmdPose(detector); // invoke pre-render events if (preRenderListeners != null) { preRenderListeners.Invoke(); } if (canvasVisible) { // change layer of specified objects, // so that they become invisible to currect camera ignoreObjOriginalLayer.Clear(); for (int i = 0; i < ignoreWhenRender.Count; i++) { ignoreObjOriginalLayer.Add(ignoreWhenRender[i].layer); if (ignoreLayerNumber > 0) { ignoreWhenRender[i].layer = ignoreLayerNumber; } } // invert backface culling when rendering a mirror if (isMirror) { GL.invertCulling = true; } // render the canvas if (StereoRenderDevice.IsNotUnityNativeSupport(StereoRenderManager.Instance.hmdType)) { RenderToOneStereoTexture(detector); } else { RenderToTwoStereoTextures(detector); } // reset backface culling if (isMirror) { GL.invertCulling = false; } // resume object layers for (int i = 0; i < ignoreWhenRender.Count; i++) { ignoreWhenRender[i].layer = ignoreObjOriginalLayer[i]; } // finish this render pass, reset visibility canvasVisible = false; } // invoke post-render events if (postRenderListeners != null) { postRenderListeners.Invoke(); } }