2017-01-16 92 views
0

我正在用Google的'Pixel'手机做白日梦游戏。我正在寻找一种方法来处理变形着色器,这种变形着色器将每个眼睛渲染到一个RenderTexture以匹配镜头失真。Unity Daydream变形着色器

我发现下面的代码StereoRenderEffect.cs

using UnityEngine; 

/// @cond 
[RequireComponent(typeof(Camera))] 
[AddComponentMenu("GoogleVR/StereoRenderEffect")] 
public class StereoRenderEffect : MonoBehaviour { 
#if !UNITY_HAS_GOOGLEVR || UNITY_EDITOR 
    private Material material; 

    private Camera cam; 

    private static readonly Rect fullRect = new Rect(0, 0, 1, 1); 

    void Awake() { 
    cam = GetComponent<Camera>(); 
    } 

    void Start() { 
    material = new Material(Shader.Find("GoogleVR/UnlitTexture")); 
    } 

    void OnRenderImage(RenderTexture source, RenderTexture dest) { 
    GL.PushMatrix(); 
    int width = dest ? dest.width : Screen.width; 
    int height = dest ? dest.height : Screen.height; 
    GL.LoadPixelMatrix(0, width, height, 0); 
    // Camera rects are in screen coordinates (bottom left is origin), but DrawTexture takes a 
    // rect in GUI coordinates (top left is origin). 
    Rect blitRect = cam.pixelRect; 
    blitRect.y = height - blitRect.height - blitRect.y; 
    RenderTexture oldActive = RenderTexture.active; 
    RenderTexture.active = dest; 
    Graphics.DrawTexture(blitRect, source, fullRect, 0, 0, 0, 0, Color.white, material); 
    RenderTexture.active = oldActive; 
    GL.PopMatrix(); 
    } 
#endif // !UNITY_HAS_GOOGLEVR || UNITY_EDITOR 
} 

它让我找到UnlitTexture.shader,这是负责的失真。 #if !UNITY_HAS_GOOGLEVR || UNITY_EDITOR 暗示的一样,只有在编辑器中运行时才有效。我正在寻找一种方法来在应用程序在实际设备上运行时执行相同操作,但无法找到它。有人知道在哪里看?

+1

这段代码是模拟编辑器中实际构建的显示。所以GVR SDK已经在为设备构建做这件事。您不需要手动执行此操作 –

+0

我知道,我只是想根据需要修改“StereoRenderEffect”着色器。添加第二个全屏着色器太昂贵了,所以我想调整它。 –

回答

0

这对于Daydream和Unity来说目前是不可能的。

但是,我相信你仍然可以用Cardboard和Unity做到这一点。