Render NV12 color format
This commit is contained in:
+22
-17
@@ -1,27 +1,32 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// CombinedUVMipsPS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D txInputU : register(t0);
|
||||
Texture2D txInputV : register(t1);
|
||||
Texture1D txInputShift : register(t2);
|
||||
Texture2D image : register(t0);
|
||||
|
||||
SamplerState GenericSampler : register(s0);
|
||||
SamplerState def_sampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
struct FragTexWide {
|
||||
float3 uuv : TEXCOORD0;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
float PS(PS_INPUT input) : SV_Target
|
||||
float2 PS(FragTexWide input) : SV_Target
|
||||
{
|
||||
float fShift = (float)txInputShift.Sample(GenericSampler, input.Tex.x);
|
||||
// float4 color_vec_y = { 0.301f, 0.586f, 0.113f, 0.0f };
|
||||
// float4 color_vec_u = { -0.168f, -0.328f, 0.496f, 128.0f / 256.0f };
|
||||
// float4 color_vec_v = { 0.496f, 0.414f, 0.082f, 128.0f / 256.0f };
|
||||
float4 color_vec_y = { 0.299, 0.587, 0.114, 0.0625 };
|
||||
float4 color_vec_u = { -0.168736, -0.331264, 0.5, 0.5 };
|
||||
float4 color_vec_v = { 0.5, -0.418688, -0.081312, 0.5 };
|
||||
|
||||
if(fShift == 0.0f)
|
||||
return (float)txInputU.SampleLevel(GenericSampler, input.Tex, 1.0f);
|
||||
else
|
||||
return (float)txInputV.SampleLevel(GenericSampler, input.Tex, 1.0f);
|
||||
// float4 color_vec_y = { 0.2578f, 0.5039f, 0.0977, 0.0625 };
|
||||
// float4 color_vec_u = { -0.1484, 0.2891, 0.4375, 128.0f / 256.0f };
|
||||
// float4 color_vec_v = { 0.4375, -0.3672, -0.0703, 128.0f / 256.0f };
|
||||
|
||||
float3 rgb_left = image.Sample(def_sampler, input.uuv.xz).rgb;
|
||||
float3 rgb_right = image.Sample(def_sampler, input.uuv.yz).rgb;
|
||||
float3 rgb = (rgb_left + rgb_right) * 0.5;
|
||||
|
||||
float u = dot(color_vec_u.xyz, rgb) + color_vec_u.w;
|
||||
float v = dot(color_vec_v.xyz, rgb) + color_vec_v.w;
|
||||
return float2(u, v);
|
||||
}
|
||||
+16
-13
@@ -1,23 +1,26 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// CombinedUVVS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
struct VertTexPosWide {
|
||||
float3 uuv : TEXCOORD;
|
||||
float4 pos : SV_POSITION;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_INPUT VS(uint vI : SV_VERTEXID)
|
||||
VertTexPosWide VS(uint vI : SV_VERTEXID)
|
||||
{
|
||||
PS_INPUT output = (PS_INPUT)0;
|
||||
float width_i = 1.0f / 1920.0f;
|
||||
float idHigh = float(vI >> 1);
|
||||
float idLow = float(vI & uint(1));
|
||||
|
||||
float2 texcoord = float2(vI & 1, vI >> 1);
|
||||
float x = idHigh * 4.0 - 1.0;
|
||||
float y = idLow * 4.0 - 1.0;
|
||||
|
||||
output.Pos = float4((texcoord.x - 0.5f) * 2.0f, -(texcoord.y + 0.0f) * 0.5f, 0.0f, 1.0f);
|
||||
output.Tex = texcoord;
|
||||
float u_right = idHigh * 2.0;
|
||||
float u_left = u_right - width_i;
|
||||
float v = 1.0 - idLow * 2.0;
|
||||
|
||||
return output;
|
||||
VertTexPosWide vert_out;
|
||||
vert_out.uuv = float3(u_left, u_right, v);
|
||||
vert_out.pos = float4(x, y, 0.0, 1.0);
|
||||
return vert_out;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// YCbCrPS2.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D image : register(t0);
|
||||
|
||||
SamplerState def_sampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
float PS(PS_INPUT frag_in) : SV_Target
|
||||
{
|
||||
float4 color_vec_y = { 0.299, 0.587, 0.114, 0.0625 };
|
||||
float4 color_vec_u = { -0.168736, -0.331264, 0.5, 0.5 };
|
||||
float4 color_vec_v = { 0.5, -0.418688, -0.081312, 0.5 };
|
||||
|
||||
float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
|
||||
float y = dot(color_vec_y.xyz, rgb) + color_vec_y.w;
|
||||
return y;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_INPUT VS(uint vI : SV_VERTEXID)
|
||||
{
|
||||
float idHigh = float(vI >> 1);
|
||||
float idLow = float(vI & uint(1));
|
||||
|
||||
float x = idHigh * 4.0 - 1.0;
|
||||
float y = idLow * 4.0 - 1.0;
|
||||
|
||||
PS_INPUT vert_out;
|
||||
vert_out.pos = float4(x, y, 0.0, 1.0);
|
||||
vert_out.tex = float2(idHigh, idLow);
|
||||
return vert_out;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// ScreenPS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D txInput : register(t0);
|
||||
|
||||
SamplerState GenericSampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
float4 PS(PS_INPUT input) : SV_Target
|
||||
{
|
||||
return txInput.Sample(GenericSampler, input.Tex);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// ScreenVS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_INPUT VS(uint vI : SV_VERTEXID)
|
||||
{
|
||||
PS_INPUT output = (PS_INPUT)0;
|
||||
|
||||
float2 texcoord = float2(vI & 1, vI >> 1);
|
||||
|
||||
output.Pos = float4((texcoord.x - 0.5f) * 2.0f, -(texcoord.y - 0.5f) * 2.0f, 0.0f, 1.0f);
|
||||
output.Tex = texcoord;
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// YCbCrPS2.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D txInput : register(t0);
|
||||
|
||||
SamplerState GenericSampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
struct PS_OUTPUT
|
||||
{
|
||||
float ColorY : SV_Target0;
|
||||
float2 ColorU: SV_Target1;
|
||||
float2 ColorV: SV_Target2;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_OUTPUT PS(PS_INPUT input) : SV_Target
|
||||
{
|
||||
PS_OUTPUT output;
|
||||
|
||||
float4 InputColor = txInput.Sample(GenericSampler, input.Tex);
|
||||
|
||||
// Range 0-255
|
||||
output.ColorY = (0.257f * InputColor.r + 0.504f * InputColor.g + 0.098f * InputColor.b) + (16 / 256.0f);
|
||||
output.ColorU = (-0.148f * InputColor.r - 0.291f * InputColor.g + 0.439f * InputColor.b) + (128.0f / 256.0f);
|
||||
output.ColorV = (0.439f * InputColor.r - 0.368f * InputColor.g - 0.071f * InputColor.b) + (128.0f / 256.0f);
|
||||
|
||||
output.ColorY = clamp(output.ColorY, 0.0f, 255.0f);
|
||||
output.ColorU = clamp(output.ColorU, 0.0f, 255.0f);
|
||||
output.ColorV = clamp(output.ColorV, 0.0f, 255.0f);
|
||||
|
||||
return output;
|
||||
}
|
||||
Reference in New Issue
Block a user