我正在使用“Pixel'”为谷歌做白日梦的游戏。电话。我正在寻找一种方法来使用失真着色器,将每只眼睛渲染到RenderTexture
以匹配镜头失真。
我在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
所暗示的那样,它仅在编辑器中运行时才有效。当应用程序在实际设备上运行时,我正在寻找一种方法来做同样的事情,但无法找到它。有人知道在哪里看吗?
答案 0 :(得分:0)
目前,Daydream和Unity无法实现这一目标。
我相信你仍然可以用Cardboard和Unity做到这一点。