c# - Unity - 后处理导致VR中的分屏?
问题描述
好的,我正在为 Oculus rift 构建,我只是想让色差或任何后处理效果发挥作用。显示效果的唯一方法是将它们应用到 OVRCameraRig 中的 CenterEyeAnchor 相机。这在编辑器中有效,但是当我插入耳机时,屏幕会分成 2 x 我应用的效果脚本数量:
我一直在尝试旧的图像效果脚本(最新的什么都不做),以及这个下载的色差着色器:
Shader "Hidden/LensCAAndDistortion" {
Properties {
_MainTex ("RGB", 2D) = "" {}
_BorderTex ("Border", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
uniform float _RedCyan;
uniform float _GreenMagenta;
uniform float _BlueYellow;
uniform float _Zoom;
uniform float _BarrelDistortion;
uniform int _BorderOnOff;
sampler2D _BorderTex;
sampler2D _MainTex;
half4 _MainTex_TexelSize;
half4 _UV_Transform = half4(1, 0, 0, 1);
float2 barrelDistortion(float2 theUV)
{
float2 h = theUV.xy - 0.5;
float r2 = h.x * h.x + h.y * h.y;
float f = 1 + r2 * (_BarrelDistortion * sqrt(r2));
return f * (1.0+_Zoom) * h + 0.5;
}
half4 fragLens (v2f_img i) : SV_Target {
half2 zoomUV = i.uv;
float4 theScreen = tex2D(_MainTex, zoomUV);
if ((_RedCyan == 0) && (_GreenMagenta == 0) && (_BlueYellow == 0))
{
zoomUV = barrelDistortion(zoomUV);
if (_BorderOnOff == 1)
{
theScreen.r = tex2D(_MainTex, zoomUV).r * tex2D(_BorderTex, ((zoomUV * 0.9375) + 0.03125)).r;
theScreen.g = tex2D(_MainTex, zoomUV).g * tex2D(_BorderTex, ((zoomUV * 0.9375) + 0.03125)).g;
theScreen.b = tex2D(_MainTex, zoomUV).b * tex2D(_BorderTex, ((zoomUV * 0.9375) + 0.03125)).b;
}
if (_BorderOnOff == 0)
{
theScreen.r = tex2D(_MainTex, zoomUV).r;
theScreen.g = tex2D(_MainTex, zoomUV).g;
theScreen.b = tex2D(_MainTex, zoomUV).b;
}
}
if ((_RedCyan != 0) || (_GreenMagenta != 0) || (_BlueYellow != 0))
{
half2 redUV;
half2 greUV;
half2 bluUV;
float redcyan = _RedCyan*0.001;
float gremag = _GreenMagenta*0.001;
float bluyel = _BlueYellow*0.001;
zoomUV = barrelDistortion(zoomUV);
redUV = (zoomUV * (1.0+redcyan)) - (redcyan/2.0);
greUV = (zoomUV * (1.0+gremag)) - (gremag/2.0);
bluUV = (zoomUV * (1.0+bluyel)) - (bluyel/2.0);
if (_BorderOnOff == 1)
{
theScreen.r = tex2D(_MainTex, redUV).r * tex2D(_BorderTex, ((redUV * 0.9375) + 0.03125)).r;
theScreen.g = tex2D(_MainTex, greUV).g * tex2D(_BorderTex, ((greUV * 0.9375) + 0.03125)).g;
theScreen.b = tex2D(_MainTex, bluUV).b * tex2D(_BorderTex, ((bluUV * 0.9375) + 0.03125)).b;
}
if (_BorderOnOff == 0)
{
theScreen.r = tex2D(_MainTex, redUV).r;
theScreen.g = tex2D(_MainTex, greUV).g;
theScreen.b = tex2D(_MainTex, bluUV).b;
}
}
return theScreen;
}
ENDCG
Subshader {
ZTest Always Cull Off ZWrite Off
ColorMask RGB
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment fragLens
ENDCG
}
}
Fallback off
} // shader
这里发生了什么?可以修复吗?
脚本:
void Start ()
{
if(!SystemInfo.supportsImageEffects)
{
enabled = false;
return;
}
}
void OnRenderImage (RenderTexture sourceTexture, RenderTexture destTexture)
{
if(LensShader != null)
{
material.SetFloat("_RedCyan", RedCyan * 10.0f);
material.SetFloat("_GreenMagenta", GreenMagenta * 10.0f);
material.SetFloat("_BlueYellow", BlueYellow * 10.0f);
material.SetFloat("_Zoom", 0.0f - Zoom);
material.SetFloat("_BarrelDistortion", BarrelDistortion);
material.SetTexture ("_BorderTex", TrimTexture);
if (TrimExtents == true)
{
material.SetInt("_BorderOnOff", 1);
}
else
{
material.SetInt("_BorderOnOff", 0);
}
Graphics.Blit(sourceTexture, destTexture, material);
}
else
{
Graphics.Blit(sourceTexture, destTexture);
}
}
void Update ()
{
}
void OnDisable ()
{
if(curMaterial)
{
DestroyImmediate(curMaterial);
}
解决方案
推荐阅读
- ios - Xamarin Forms - iOS 输入字段不会自动调整位置,因为键盘出现在 ScrollView 中的内容
- python - Heroku:ModuleNotFoundError:没有名为“请求”的模块
- dart - 以编程方式返回由父小部件包装的小部件的最佳方法
- c - 如何使用c中的指针反转数组
- javascript - 页面加载时的多个异步调度会产生错误?
- django - 如何在 RedirectView 中自定义 url
- python - 为什么 Python 3 中这个简单的整数除法给我的答案比预期的少一个?
- android - 切换片段时reccyclerview消失
- sql-server - 指定 CollectionAggregate 使用的顺序
- python - 运行带有多个核心的snakemake