我有一些(正确,平面)YUV纹理团结,我只是想看看他们的开发利用。
是否有实际工作YUV着色器统一(其着色器语言变量)踢身边?
这是很简单的概念,从YUV转换为RGB ..但有点繁琐。
YUV到RGB转换着色器:
Shader "Hidden/YUVtoRGB"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed3 YUVtoRGB(fixed3 c)
{
fixed3 rgb;
rgb.r = c.x + c.z * 1.13983;
rgb.g = c.x + dot(fixed2(-0.39465, -0.58060), c.yz);
rgb.b = c.x + c.y * 2.03211;
return rgb;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 yuv = tex2D(_MainTex, i.uv);
fixed4 rgb = fixed4(YUVtoRGB(yuv.rgb), yuv.a);
return rgb;
}
ENDCG
}
}
}
只是投入答案的缘故,
你可以很简单地只使用YUV的Y通道,
你会得到的,准确地说,图像的黑白版本。
因此,在抽象的伪代码而言,仅仅做这样的事情..
uint32_t grayscale_from_y(uint8_t y)
{
// when we want to show a YUV texture on screen
// for checking during development,
// you can be super lazy and just feed
// the "Y" to RGB upstream,
// set R G and B to the Y value, something like this:
uint32_t r = y;
uint32_t g = y;
uint32_t b = y;
return r + (g << 8) + (b << 16) + 0xff000000;
// (alpha is one there)
}
它可以帮助别人!