我正在使用 Unity 和 ARCore。问题是,当我使用伽玛色彩空间时,AR 相机工作正常。但是,使用线性色彩空间它会在 AR 相机的顶部创建一个白色叠加层。我必须使用线性色彩空间。我该怎么办 ?
问问题
331 次
1 回答
2
好的,解决了这个问题。我必须为 arcamera 背景制作一个自定义着色器。创建(或复制 arbackground 材质)材质并指定波纹管着色器并替换为 ar 材质。
Shader "ARCore/ARBackground(Linear)"
{
Properties {
_MainTex ("Texture", 2D) = "white" {}
_UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
_UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
}
// For GLES3
SubShader
{
Pass
{
ZWrite Off
GLSLPROGRAM
#pragma only_renderers gles3
#ifdef SHADER_API_GLES3
#extension GL_OES_EGL_image_external_essl3 : require
#endif
uniform vec4 _UvTopLeftRight;
uniform vec4 _UvBottomLeftRight;
#ifdef VERTEX
varying vec2 textureCoord;
void main()
{
#ifdef SHADER_API_GLES3
vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
#endif
}
#endif
#ifdef FRAGMENT
varying vec2 textureCoord;
uniform samplerExternalOES _MainTex;
void main()
{
#ifdef SHADER_API_GLES3
gl_FragColor = texture(_MainTex, textureCoord);
//gamma to linear conversion
gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
#endif
}
#endif
ENDGLSL
}
}
Subshader
{
Pass
{
ZWrite Off
CGPROGRAM
#pragma exclude_renderers gles3
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float4 _UvTopLeftRight;
uniform float4 _UvBottomLeftRight;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v)
{
float2 uvTop = lerp(_UvTopLeftRight.xy, _UvTopLeftRight.zw, v.uv.x);
float2 uvBottom = lerp(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, v.uv.x);
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = lerp(uvTop, uvBottom, v.uv.y);
// Instant preview's texture is transformed differently.
o.uv = o.uv.yx;
o.uv.x = 1.0 - o.uv.x;
return o;
}
sampler2D _MainTex;
fixed4 frag(v2f i) : SV_Target
{
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
FallBack Off
}
于 2018-11-20T06:15:41.513 回答